using InterfaceForward.Application.Contracts.ForwardCore; using InterfaceForward.Application.ForwardCore; using InterfaceForward.Domain.Shared; using InterfaceForward.Domain.Shared.Dtos; using InterfaceForward.Domain.Shared.Enum; using Newtonsoft.Json.Linq; namespace InterfaceForward.Application.Tests; public class DefaultForwardFlowTests { [Fact] public void SerializationBody_ShouldUseMappedInputForJson() { var flow = new TestForwardFlow(); var context = new ForwardCoreContext { TargetInterface = new InterfaceDto { ContentType = ContentType.Json }, OriginalInterfaceMappedInput = new JObject { ["orderId"] = "A001" } }; var body = flow.SerializationBody(context); Assert.Equal("{\"orderId\":\"A001\"}", body); } [Fact] public async Task SetContentType_ShouldReplaceFromMappingBodyForFormUrlEncoded() { var flow = new TestForwardFlow(); var context = new ForwardCoreContext { TargetInterface = new InterfaceDto { ContentType = ContentType.FormUrlEncoded }, TargetInterfaceInput = "{\"orderId\":\"A001\"}", OriginalInterfaceMappedInput = new JObject { ["orderId"] = "A001" }, FormFieldList = [ new InterfaceFormFieldDto { Name = "notifyBizEventDTO", Value = GlobalConst.FromMappingBody } ] }; using var message = new HttpRequestMessage(); flow.SetContentTypeForTest(context, message); var content = await message.Content!.ReadAsStringAsync(); Assert.Equal("notifyBizEventDTO=%7B%22orderId%22%3A%22A001%22%7D", content); } [Fact] public void NoneContentType_ShouldNotCreateRequestContent() { var flow = new TestForwardFlow(); var context = new ForwardCoreContext { TargetInterface = new InterfaceDto { ContentType = ContentType.None }, OriginalInterfaceMappedInput = new JObject(), TargetInterfaceInput = string.Empty }; using var message = new HttpRequestMessage(); flow.SetContentTypeForTest(context, message); Assert.Equal(string.Empty, flow.SerializationBody(context)); Assert.Null(message.Content); } class TestForwardFlow : DefaultForwardFlow { public void SetContentTypeForTest(ForwardCoreContext context, HttpRequestMessage message) { SetContentType(context, message); } } }