diff --git a/CDK.Framework.sln b/CDK.Framework.sln index 32fd379..94bb075 100644 --- a/CDK.Framework.sln +++ b/CDK.Framework.sln @@ -45,6 +45,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sagittaras.CDK.Testing", "S EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sagittaras.CDK.Testing.Route53", "Sagittaras.CDK.Testing.Route53\Sagittaras.CDK.Testing.Route53.csproj", "{2C4B4454-A145-405E-85BC-F54B56EAC39B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sagittaras.CDK.Testing.KMS", "Sagittaras.CDK.Testing.KMS\Sagittaras.CDK.Testing.KMS.csproj", "{FF8FB1E8-9071-470E-A4F3-6C0CD27716F4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -66,6 +68,7 @@ Global {3A01C380-5151-4039-A00C-A33687E00861} = {AEF441A3-E5F9-46D2-82B9-8EE105CC3274} {D753C559-6F75-4493-A5A3-00CD0727A2DC} = {3A01C380-5151-4039-A00C-A33687E00861} {2C4B4454-A145-405E-85BC-F54B56EAC39B} = {3A01C380-5151-4039-A00C-A33687E00861} + {FF8FB1E8-9071-470E-A4F3-6C0CD27716F4} = {3A01C380-5151-4039-A00C-A33687E00861} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {940EEEA3-A068-4793-A44A-D2FCE1143E49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -112,5 +115,9 @@ Global {2C4B4454-A145-405E-85BC-F54B56EAC39B}.Debug|Any CPU.Build.0 = Debug|Any CPU {2C4B4454-A145-405E-85BC-F54B56EAC39B}.Release|Any CPU.ActiveCfg = Release|Any CPU {2C4B4454-A145-405E-85BC-F54B56EAC39B}.Release|Any CPU.Build.0 = Release|Any CPU + {FF8FB1E8-9071-470E-A4F3-6C0CD27716F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF8FB1E8-9071-470E-A4F3-6C0CD27716F4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF8FB1E8-9071-470E-A4F3-6C0CD27716F4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF8FB1E8-9071-470E-A4F3-6C0CD27716F4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Sagittaras.CDK.Testing.KMS/AliasAssertion.cs b/Sagittaras.CDK.Testing.KMS/AliasAssertion.cs new file mode 100644 index 0000000..f72810c --- /dev/null +++ b/Sagittaras.CDK.Testing.KMS/AliasAssertion.cs @@ -0,0 +1,11 @@ +using Sagittaras.CDK.Testing.Resources; + +namespace Sagittaras.CDK.Testing.KMS; + +/// +/// Assertion for AWS::KMS::Alias. +/// +public class AliasAssertion : ResourceAssertion +{ + public override string Type => "AWS::KMS::Alias"; +} \ No newline at end of file diff --git a/Sagittaras.CDK.Testing.KMS/AliasProperties.cs b/Sagittaras.CDK.Testing.KMS/AliasProperties.cs new file mode 100644 index 0000000..89a3825 --- /dev/null +++ b/Sagittaras.CDK.Testing.KMS/AliasProperties.cs @@ -0,0 +1,14 @@ +using Sagittaras.CDK.Testing.Resources; + +namespace Sagittaras.CDK.Testing.KMS; + +/// +/// Properties for AWS::KMS::Alias. +/// +public class AliasProperties : ResourceProperties +{ + /// + /// Name of the key alias. + /// + public string? AliasName { get; set; } +} \ No newline at end of file diff --git a/Sagittaras.CDK.Testing.KMS/KeyAssertion.cs b/Sagittaras.CDK.Testing.KMS/KeyAssertion.cs new file mode 100644 index 0000000..0022139 --- /dev/null +++ b/Sagittaras.CDK.Testing.KMS/KeyAssertion.cs @@ -0,0 +1,11 @@ +using Sagittaras.CDK.Testing.Resources; + +namespace Sagittaras.CDK.Testing.KMS; + +/// +/// Assertion for AWS::KMS::Key. +/// +public class KeyAssertion : ResourceAssertion +{ + public override string Type => "AWS::KMS::Key"; +} \ No newline at end of file diff --git a/Sagittaras.CDK.Testing.KMS/KeyProperties.cs b/Sagittaras.CDK.Testing.KMS/KeyProperties.cs new file mode 100644 index 0000000..20c509a --- /dev/null +++ b/Sagittaras.CDK.Testing.KMS/KeyProperties.cs @@ -0,0 +1,11 @@ +using Sagittaras.CDK.Testing.Resources; + +namespace Sagittaras.CDK.Testing.KMS; + +/// +/// Properties for AWS::KMS::Key. +/// +public class KeyProperties : ResourceProperties +{ + +} \ No newline at end of file diff --git a/Sagittaras.CDK.Testing.KMS/Sagittaras.CDK.Testing.KMS.csproj b/Sagittaras.CDK.Testing.KMS/Sagittaras.CDK.Testing.KMS.csproj new file mode 100644 index 0000000..79d9447 --- /dev/null +++ b/Sagittaras.CDK.Testing.KMS/Sagittaras.CDK.Testing.KMS.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Sagittaras.CDK.Testing.Route53/KeySigningKeyAssertion.cs b/Sagittaras.CDK.Testing.Route53/KeySigningKeyAssertion.cs new file mode 100644 index 0000000..e025e25 --- /dev/null +++ b/Sagittaras.CDK.Testing.Route53/KeySigningKeyAssertion.cs @@ -0,0 +1,12 @@ +using Sagittaras.CDK.Testing.Resources; + +namespace Sagittaras.CDK.Testing.Route53; + +/// +/// Assertion for AWS::Route53::KeySigningKey. +/// +public class KeySigningKeyAssertion : ResourceAssertion +{ + /// + public override string Type => "AWS::Route53::KeySigningKey"; +} \ No newline at end of file diff --git a/Sagittaras.CDK.Testing.Route53/KeySigningKeyProperties.cs b/Sagittaras.CDK.Testing.Route53/KeySigningKeyProperties.cs new file mode 100644 index 0000000..85848fa --- /dev/null +++ b/Sagittaras.CDK.Testing.Route53/KeySigningKeyProperties.cs @@ -0,0 +1,14 @@ +using Sagittaras.CDK.Testing.Resources; + +namespace Sagittaras.CDK.Testing.Route53; + +/// +/// Properties for AWS::Route53::KeySigningKey. +/// +public class KeySigningKeyProperties : ResourceProperties +{ + /// + /// Current status of the KSK. + /// + public string? Status { get; set; } +} \ No newline at end of file diff --git a/Sagittaras.CDK.Testing.Route53/RecordSetAssertion.cs b/Sagittaras.CDK.Testing.Route53/RecordSetAssertion.cs new file mode 100644 index 0000000..d44d3f2 --- /dev/null +++ b/Sagittaras.CDK.Testing.Route53/RecordSetAssertion.cs @@ -0,0 +1,12 @@ +using Sagittaras.CDK.Testing.Resources; + +namespace Sagittaras.CDK.Testing.Route53; + +/// +/// Assertion for AWS::Route53::RecordSet. +/// +public class RecordSetAssertion : ResourceAssertion +{ + /// + public override string Type => "AWS::Route53::RecordSet"; +} \ No newline at end of file diff --git a/Sagittaras.CDK.Testing.Route53/RecordSetProperties.cs b/Sagittaras.CDK.Testing.Route53/RecordSetProperties.cs new file mode 100644 index 0000000..09818a2 --- /dev/null +++ b/Sagittaras.CDK.Testing.Route53/RecordSetProperties.cs @@ -0,0 +1,11 @@ +using Sagittaras.CDK.Testing.Resources; + +namespace Sagittaras.CDK.Testing.Route53; + +/// +/// Properties for AWS::Route53::RecordSet. +/// +public class RecordSetProperties : ResourceProperties +{ + +} \ No newline at end of file diff --git a/Sagittaras.CDK.Testing/Extensions/TemplateAssertionExtension.cs b/Sagittaras.CDK.Testing/Extensions/TemplateAssertionExtension.cs index 05a95f3..b238999 100644 --- a/Sagittaras.CDK.Testing/Extensions/TemplateAssertionExtension.cs +++ b/Sagittaras.CDK.Testing/Extensions/TemplateAssertionExtension.cs @@ -19,4 +19,16 @@ public static void Assert(this Template template, TResourceA { template.HasResource(assertion.Type, assertion.GetResourceDescription()); } + + /// + /// Asserts that the template has a given number of resources of the given type. + /// + /// + /// + /// + public static void AssertCount(this Template template, int count) + where TResourceAssertion : IResourceAssertion, new() + { + template.ResourceCountIs(new TResourceAssertion().Type, count); + } } \ No newline at end of file diff --git a/Sagittaras.CDK.Tests.Route53/PublicHostedZoneTest.cs b/Sagittaras.CDK.Tests.Route53/PublicHostedZoneTest.cs index 104c68b..5c85965 100644 --- a/Sagittaras.CDK.Tests.Route53/PublicHostedZoneTest.cs +++ b/Sagittaras.CDK.Tests.Route53/PublicHostedZoneTest.cs @@ -2,6 +2,7 @@ using Amazon.CDK.Assertions; using Sagittaras.CDK.Framework.Route53; using Sagittaras.CDK.Testing.Extensions; +using Sagittaras.CDK.Testing.KMS; using Sagittaras.CDK.Testing.Route53; using Xunit; @@ -32,8 +33,8 @@ public void Test_BaseFactoryUsage() Name = Domain } }); - template.ResourceCountIs("AWS::Route53::HostedZone", 1); - template.ResourceCountIs("AWS::Route53::RecordSet", 0); + template.AssertCount(1); + template.AssertCount(0); } /// @@ -47,15 +48,20 @@ public void Test_DNSSEC() .Construct(); Template template = StackTemplate; - template.ResourceCountIs("AWS::KMS::Key", 1); - template.HasResourceProperties("AWS::KMS::Alias", new Dictionary + template.AssertCount(1); + template.Assert(new AliasAssertion { - { "AliasName", "alias/examplecom-key" } + Properties = new AliasProperties + { + AliasName = "alias/examplecom-key" + } }); - - template.HasResourceProperties("AWS::Route53::KeySigningKey", new Dictionary + template.Assert(new KeySigningKeyAssertion { - { "Status", "ACTIVE" } + Properties = new KeySigningKeyProperties + { + Status = "ACTIVE" + } }); template.HasResource("AWS::Route53::DNSSEC", new Dictionary diff --git a/Sagittaras.CDK.Tests.Route53/Sagittaras.CDK.Tests.Route53.csproj b/Sagittaras.CDK.Tests.Route53/Sagittaras.CDK.Tests.Route53.csproj index 0850230..37f999a 100644 --- a/Sagittaras.CDK.Tests.Route53/Sagittaras.CDK.Tests.Route53.csproj +++ b/Sagittaras.CDK.Tests.Route53/Sagittaras.CDK.Tests.Route53.csproj @@ -24,6 +24,7 @@ +