Skip to content

Commit

Permalink
Add Unit test to illustrate the use of PayloadBuilder with complex bo…
Browse files Browse the repository at this point in the history
…dy payload...
  • Loading branch information
cajuncoding committed Feb 29, 2024
1 parent 98e5720 commit aa976da
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
using System;
using System.Linq;
using Azure.Identity;
using Microsoft.IdentityModel.Tokens;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SqlTransactionalOutbox.JsonExtensions;
using SqlTransactionalOutbox.Tests;
using SqlTransactionalOutbox.Utilities;
Expand Down Expand Up @@ -72,5 +77,39 @@ public void TestPayloadBuilderFromObject()
Assert.AreEqual("CajunCoding", payloadBuilder.To);
Assert.AreEqual("Testing Json Payload from HttpProxy", payloadBuilder.Body);
}

private record ComplexBody(string Message, int[] Ids, Guid[] Guids, bool IsThisABoolean);

[TestMethod]
public void TestPayloadBuilderFromObjectWithComplexBody()
{
var tempObject = new
{
Topic = TestConfiguration.AzureServiceBusTopic,
FifoGroupingId = "HttpProxy-IntegrationTest",
To = "CajunCoding",
Body = 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 = PayloadBuilder.FromObject(tempObject);

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 = tempObject.Body;
var payloadBody = JsonConvert.DeserializeObject<ComplexBody>(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);
}
}
}

0 comments on commit aa976da

Please sign in to comment.