diff --git a/Vonage.Test/Common/Extensions/FluentAssertionExtensions.cs b/Vonage.Test/Common/Extensions/FluentAssertionExtensions.cs index fb8b872d6..56f54ddab 100644 --- a/Vonage.Test/Common/Extensions/FluentAssertionExtensions.cs +++ b/Vonage.Test/Common/Extensions/FluentAssertionExtensions.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Text.Json; +using System.Threading.Tasks; using Vonage.Common.Monads; namespace Vonage.Test.Common.Extensions; @@ -13,4 +14,7 @@ public static ResultAssertionExtensions Should(this Result instance) => public static ResultAsyncAssertionExtensions Should(this Task> instance) => new ResultAsyncAssertionExtensions(instance); + + public static JsonElementAssertionExtensions Should(this JsonElement instance) => + new JsonElementAssertionExtensions(instance); } \ No newline at end of file diff --git a/Vonage.Test/Common/Extensions/JsonElementAssertionExtensions.cs b/Vonage.Test/Common/Extensions/JsonElementAssertionExtensions.cs new file mode 100644 index 000000000..782756f21 --- /dev/null +++ b/Vonage.Test/Common/Extensions/JsonElementAssertionExtensions.cs @@ -0,0 +1,25 @@ +using System.Text.Json; +using FluentAssertions; +using FluentAssertions.Execution; +using FluentAssertions.Primitives; + +namespace Vonage.Test.Common.Extensions; + +public class JsonElementAssertionExtensions : ReferenceTypeAssertions +{ + public JsonElementAssertionExtensions(JsonElement subject) : base(subject) + { + } + + protected override string Identifier => "JsonElement"; + + public AndConstraint Be(JsonElement expected) + { + Execute.Assertion + .WithExpectation("Expected {context:option} to be {0}{reason}, ", expected) + .Given(() => this.Subject) + .ForCondition(subject => subject.GetRawText().Equals(expected.GetRawText())) + .FailWith("but found {0}.", this.Subject); + return new AndConstraint(this); + } +} \ No newline at end of file