Class Capture
Capture values while matching templates.
Inherited Members
Namespace: Amazon.CDK.Assertions
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Capture : Matcher
Syntax (vb)
Public Class Capture Inherits Matcher
Remarks
Using an instance of this class within a Matcher will capture the matching value.
The as*()
APIs on the instance can be used to get the captured value.
ExampleMetadata: infused
Examples
// Given a template -
// {
// "Resources": {
// "MyBar": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": "Flob",
// }
// },
// "MyBaz": {
// "Type": "Foo::Bar",
// "Properties": {
// "Fred": "Quib",
// }
// }
// }
// }
var fredCapture = new Capture();
template.HasResourceProperties("Foo::Bar", new Dictionary<string, Capture> {
{ "Fred", fredCapture }
});
fredCapture.AsString(); // returns "Flob"
fredCapture.Next(); // returns true
fredCapture.AsString();
Synopsis
Constructors
Capture(object?) | Initialize a new capture. |
Properties
Name | A name for the matcher. |
Methods
AsArray() | Retrieve the captured value as an array. |
AsBoolean() | Retrieve the captured value as a boolean. |
AsNumber() | Retrieve the captured value as a number. |
AsObject() | Retrieve the captured value as a JSON object. |
AsString() | Retrieve the captured value as a string. |
Next() | When multiple results are captured, move the iterator to the next result. |
Test(object) | Test whether a target matches the provided pattern. |
Constructors
Capture(object?)
Initialize a new capture.
public Capture(object? pattern = null)
Parameters
- pattern object
a nested pattern or Matcher.
Remarks
Using an instance of this class within a Matcher will capture the matching value.
The as*()
APIs on the instance can be used to get the captured value.
ExampleMetadata: infused
Properties
Name
A name for the matcher.
public override string Name { get; }
Property Value
Overrides
Remarks
This is collected as part of the result and may be presented to the user.
Methods
AsArray()
Retrieve the captured value as an array.
public virtual object[] AsArray()
Returns
object[]
Remarks
An error is generated if no value is captured or if the value is not an array.
AsBoolean()
Retrieve the captured value as a boolean.
public virtual bool AsBoolean()
Returns
Remarks
An error is generated if no value is captured or if the value is not a boolean.
AsNumber()
Retrieve the captured value as a number.
public virtual double AsNumber()
Returns
Remarks
An error is generated if no value is captured or if the value is not a number.
AsObject()
Retrieve the captured value as a JSON object.
public virtual IDictionary<string, object> AsObject()
Returns
Remarks
An error is generated if no value is captured or if the value is not an object.
AsString()
Retrieve the captured value as a string.
public virtual string AsString()
Returns
Remarks
An error is generated if no value is captured or if the value is not a string.
Next()
When multiple results are captured, move the iterator to the next result.
public virtual bool Next()
Returns
true if another capture is present, false otherwise
Remarks
Using an instance of this class within a Matcher will capture the matching value.
The as*()
APIs on the instance can be used to get the captured value.
ExampleMetadata: infused
Test(object)
Test whether a target matches the provided pattern.
public override MatchResult Test(object actual)
Parameters
- actual object
Returns
Overrides
Remarks
Every Matcher must implement this method. This method will be invoked by the assertions framework. Do not call this method directly.