From d33933f948ad935bdc55c2be481d04bf893488f7 Mon Sep 17 00:00:00 2001 From: Brandon Bernard Date: Thu, 29 Feb 2024 16:22:03 -0600 Subject: [PATCH] Add Unit test to illustrate simply way to build a Payload body with complex model using PayloadBuilder directly... --- .../PayloadBuilderTests.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/SqlTransactionalOutbox.IntegrationTests/PayloadBuilderTests/PayloadBuilderTests.cs b/SqlTransactionalOutbox.IntegrationTests/PayloadBuilderTests/PayloadBuilderTests.cs index 8e74b57..57e57ee 100644 --- a/SqlTransactionalOutbox.IntegrationTests/PayloadBuilderTests/PayloadBuilderTests.cs +++ b/SqlTransactionalOutbox.IntegrationTests/PayloadBuilderTests/PayloadBuilderTests.cs @@ -111,5 +111,37 @@ public void TestPayloadBuilderFromObjectWithComplexBody() Assert.IsTrue(originalBody.Guids.SequenceEqual(payloadBody.Guids)); Assert.AreEqual(originalBody.IsThisABoolean, payloadBody.IsThisABoolean); } + + + [TestMethod] + public void TestPayloadBuilderDirectlyToCreatingPayloads() + { + var complexBodyModel = new ComplexBody( + Message: "This is a complex Body Payload...", + Ids: new[] { 1, 2, 3 }, + Guids: new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }, + IsThisABoolean: true + ); + + var payloadBuilder = new PayloadBuilder() + { + PublishTarget = TestConfiguration.AzureServiceBusTopic, // aka Topic for Azure Service Bus! + FifoGroupingId = "HttpProxy-IntegrationTest", + To = "CajunCoding", + Body = JsonConvert.SerializeObject(complexBodyModel) + }; + + Assert.AreEqual(TestConfiguration.AzureServiceBusTopic, payloadBuilder.PublishTarget); + Assert.AreEqual("HttpProxy-IntegrationTest", payloadBuilder.FifoGroupingId); + Assert.AreEqual("CajunCoding", payloadBuilder.To); + + //Compare and Validate the Complex Body values... + var originalBody = complexBodyModel; + var payloadBody = JsonConvert.DeserializeObject(payloadBuilder.Body); + Assert.AreEqual(originalBody.Message, payloadBody.Message); + Assert.IsTrue(originalBody.Ids.SequenceEqual(payloadBody.Ids)); + Assert.IsTrue(originalBody.Guids.SequenceEqual(payloadBody.Guids)); + Assert.AreEqual(originalBody.IsThisABoolean, payloadBody.IsThisABoolean); + } } }