Show / Hide Table of Contents

Class Capture

Capture values while matching templates.

Inheritance
object
Matcher
Capture
Inherited Members
Matcher.IsMatcher(object)
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

string

Overrides
Matcher.Name
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

bool

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

double

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

IDictionary<string, object>

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

string

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

bool

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

MatchResult

Overrides
Matcher.Test(object)
Remarks

Every Matcher must implement this method. This method will be invoked by the assertions framework. Do not call this method directly.

Back to top Generated by DocFX