Class Template
Suite of assertions that can be run on a CDK stack.
Inheritance
Namespace: Amazon.CDK.Assertions
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Template : DeputyBase
Syntax (vb)
Public Class Template
Inherits DeputyBase
Remarks
Typically used, as part of unit tests, to validate that the rendered CloudFormation template has expected resources and properties.
ExampleMetadata: nofixture infused
Examples
using Amazon.CDK;
using Amazon.CDK.Assertions;
var stack = new Stack();
// ...
var template = Template.FromStack(stack);
Synopsis
Constructors
Template(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
Template(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
Methods
AllResources(String, Object) | Assert that all resources of the given type contain the given definition in the CloudFormation template. |
AllResourcesProperties(String, Object) | Assert that all resources of the given type contain the given properties CloudFormation template. |
FindConditions(String, Object) | Get the set of matching Conditions that match the given properties in the CloudFormation template. |
FindMappings(String, Object) | Get the set of matching Mappings that match the given properties in the CloudFormation template. |
FindOutputs(String, Object) | Get the set of matching Outputs that match the given properties in the CloudFormation template. |
FindParameters(String, Object) | Get the set of matching Parameters that match the given properties in the CloudFormation template. |
FindResources(String, Object) | Get the set of matching resources of a given type and properties in the CloudFormation template. |
FromJSON(IDictionary<String, Object>, ITemplateParsingOptions) | Base your assertions from an existing CloudFormation template formatted as an in-memory JSON object. |
FromStack(Stack, ITemplateParsingOptions) | Base your assertions on the CloudFormation template synthesized by a CDK |
FromString(String, ITemplateParsingOptions) | Base your assertions from an existing CloudFormation template formatted as a JSON string. |
HasCondition(String, Object) | Assert that a Condition with the given properties exists in the CloudFormation template. |
HasMapping(String, Object) | Assert that a Mapping with the given properties exists in the CloudFormation template. |
HasOutput(String, Object) | Assert that an Output with the given properties exists in the CloudFormation template. |
HasParameter(String, Object) | Assert that a Parameter with the given properties exists in the CloudFormation template. |
HasResource(String, Object) | Assert that a resource of the given type and given definition exists in the CloudFormation template. |
HasResourceProperties(String, Object) | Assert that a resource of the given type and properties exists in the CloudFormation template. |
ResourceCountIs(String, Double) | Assert that the given number of resources of the given type exist in the template. |
ResourcePropertiesCountIs(String, Object, Double) | Assert that the given number of resources of the given type and properties exists in the CloudFormation template. |
TemplateMatches(Object) | Assert that the CloudFormation template matches the given value. |
ToJSON() | The CloudFormation template deserialized into an object. |
Constructors
Template(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected Template(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
Template(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected Template(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Methods
AllResources(String, Object)
Assert that all resources of the given type contain the given definition in the CloudFormation template.
public virtual void AllResources(string type, object props)
Parameters
- type System.String
the resource type;
- props System.Object
the entire definition of the resources as they should be expected in the template.
Remarks
By default, performs partial matching on the resource, via the Match.objectLike()
.
To configure different behavior, use other matchers in the Match
class.
AllResourcesProperties(String, Object)
Assert that all resources of the given type contain the given properties CloudFormation template.
public virtual void AllResourcesProperties(string type, object props)
Parameters
- type System.String
the resource type;
- props System.Object
the 'Properties' section of the resource as should be expected in the template.
Remarks
By default, performs partial matching on the Properties
key of the resource, via the
Match.objectLike()
. To configure different behavior, use other matchers in the Match
class.
FindConditions(String, Object)
Get the set of matching Conditions that match the given properties in the CloudFormation template.
public virtual IDictionary<string, IDictionary<string, object>> FindConditions(string logicalId, object props = null)
Parameters
- logicalId System.String
the name of the condition.
- props System.Object
by default, matches all Conditions in the template.
Returns
System.Collections.Generic.IDictionary<System.String, System.Collections.Generic.IDictionary<System.String, System.Object>>
FindMappings(String, Object)
Get the set of matching Mappings that match the given properties in the CloudFormation template.
public virtual IDictionary<string, IDictionary<string, object>> FindMappings(string logicalId, object props = null)
Parameters
- logicalId System.String
the name of the mapping.
- props System.Object
by default, matches all Mappings in the template.
Returns
System.Collections.Generic.IDictionary<System.String, System.Collections.Generic.IDictionary<System.String, System.Object>>
FindOutputs(String, Object)
Get the set of matching Outputs that match the given properties in the CloudFormation template.
public virtual IDictionary<string, IDictionary<string, object>> FindOutputs(string logicalId, object props = null)
Parameters
- logicalId System.String
the name of the output.
- props System.Object
by default, matches all Outputs in the template.
Returns
System.Collections.Generic.IDictionary<System.String, System.Collections.Generic.IDictionary<System.String, System.Object>>
FindParameters(String, Object)
Get the set of matching Parameters that match the given properties in the CloudFormation template.
public virtual IDictionary<string, IDictionary<string, object>> FindParameters(string logicalId, object props = null)
Parameters
- logicalId System.String
the name of the parameter.
- props System.Object
by default, matches all Parameters in the template.
Returns
System.Collections.Generic.IDictionary<System.String, System.Collections.Generic.IDictionary<System.String, System.Object>>
FindResources(String, Object)
Get the set of matching resources of a given type and properties in the CloudFormation template.
public virtual IDictionary<string, IDictionary<string, object>> FindResources(string type, object props = null)
Parameters
- type System.String
the type to match in the CloudFormation template.
- props System.Object
by default, matches all resources with the given type.
Returns
System.Collections.Generic.IDictionary<System.String, System.Collections.Generic.IDictionary<System.String, System.Object>>
FromJSON(IDictionary<String, Object>, ITemplateParsingOptions)
Base your assertions from an existing CloudFormation template formatted as an in-memory JSON object.
public static Template FromJSON(IDictionary<string, object> template, ITemplateParsingOptions templateParsingOptions = null)
Parameters
- template System.Collections.Generic.IDictionary<System.String, System.Object>
the CloudFormation template formatted as a nested set of records.
- templateParsingOptions ITemplateParsingOptions
Optional param to configure template parsing behavior, such as disregarding circular dependencies.
Returns
FromStack(Stack, ITemplateParsingOptions)
Base your assertions on the CloudFormation template synthesized by a CDK Stack
.
public static Template FromStack(Stack stack, ITemplateParsingOptions templateParsingOptions = null)
Parameters
- stack Stack
the CDK Stack to run assertions on.
- templateParsingOptions ITemplateParsingOptions
Optional param to configure template parsing behavior, such as disregarding circular dependencies.
Returns
FromString(String, ITemplateParsingOptions)
Base your assertions from an existing CloudFormation template formatted as a JSON string.
public static Template FromString(string template, ITemplateParsingOptions templateParsingOptions = null)
Parameters
- template System.String
the CloudFormation template in.
- templateParsingOptions ITemplateParsingOptions
Optional param to configure template parsing behavior, such as disregarding circular dependencies.
Returns
HasCondition(String, Object)
Assert that a Condition with the given properties exists in the CloudFormation template.
public virtual void HasCondition(string logicalId, object props)
Parameters
- logicalId System.String
the name of the mapping.
- props System.Object
the output as should be expected in the template.
Remarks
By default, performs partial matching on the resource, via the Match.objectLike()
.
To configure different behavior, use other matchers in the Match
class.
HasMapping(String, Object)
Assert that a Mapping with the given properties exists in the CloudFormation template.
public virtual void HasMapping(string logicalId, object props)
Parameters
- logicalId System.String
the name of the mapping.
- props System.Object
the output as should be expected in the template.
Remarks
By default, performs partial matching on the resource, via the Match.objectLike()
.
To configure different behavior, use other matchers in the Match
class.
HasOutput(String, Object)
Assert that an Output with the given properties exists in the CloudFormation template.
public virtual void HasOutput(string logicalId, object props)
Parameters
- logicalId System.String
the name of the output.
- props System.Object
the output as should be expected in the template.
Remarks
By default, performs partial matching on the resource, via the Match.objectLike()
.
To configure different behavior, use other matchers in the Match
class.
HasParameter(String, Object)
Assert that a Parameter with the given properties exists in the CloudFormation template.
public virtual void HasParameter(string logicalId, object props)
Parameters
- logicalId System.String
the name of the parameter.
- props System.Object
the parameter as should be expected in the template.
Remarks
By default, performs partial matching on the parameter, via the Match.objectLike()
.
To configure different behavior, use other matchers in the Match
class.
HasResource(String, Object)
Assert that a resource of the given type and given definition exists in the CloudFormation template.
public virtual void HasResource(string type, object props)
Parameters
- type System.String
the resource type;
- props System.Object
the entire definition of the resource as should be expected in the template.
Remarks
By default, performs partial matching on the resource, via the Match.objectLike()
.
To configure different behavior, use other matchers in the Match
class.
HasResourceProperties(String, Object)
Assert that a resource of the given type and properties exists in the CloudFormation template.
public virtual void HasResourceProperties(string type, object props)
Parameters
- type System.String
the resource type;
- props System.Object
the 'Properties' section of the resource as should be expected in the template.
Remarks
By default, performs partial matching on the Properties
key of the resource, via the
Match.objectLike()
. To configure different behavior, use other matchers in the Match
class.
ResourceCountIs(String, Double)
Assert that the given number of resources of the given type exist in the template.
public virtual void ResourceCountIs(string type, double count)
Parameters
- type System.String
the resource type;
- count System.Double
number of expected instances.
ResourcePropertiesCountIs(String, Object, Double)
Assert that the given number of resources of the given type and properties exists in the CloudFormation template.
public virtual void ResourcePropertiesCountIs(string type, object props, double count)
Parameters
- type System.String
the resource type;
- props System.Object
the 'Properties' section of the resource as should be expected in the template.
- count System.Double
number of expected instances.
TemplateMatches(Object)
Assert that the CloudFormation template matches the given value.
public virtual void TemplateMatches(object expected)
Parameters
- expected System.Object
the expected CloudFormation template as key-value pairs.
ToJSON()
The CloudFormation template deserialized into an object.
public virtual IDictionary<string, object> ToJSON()
Returns
System.Collections.Generic.IDictionary<System.String, System.Object>