diff --git a/TransactionProcessor.BusinessLogic.Tests/OperatorInterfaces/PataPawaPostPayProxyTests.cs b/TransactionProcessor.BusinessLogic.Tests/OperatorInterfaces/PataPawaPostPayProxyTests.cs index 79e3bdef..14010aff 100644 --- a/TransactionProcessor.BusinessLogic.Tests/OperatorInterfaces/PataPawaPostPayProxyTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/OperatorInterfaces/PataPawaPostPayProxyTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,11 +7,12 @@ namespace TransactionProcessor.BusinessLogic.Tests.OperatorInterfaces { using System.Threading; - using BusinessLogic.OperatorInterfaces; using Common; + using EstateManagement.DataTransferObjects.Responses.Operator; using Microsoft.Data.SqlClient; using Microsoft.Extensions.Caching.Memory; using Moq; + using NuGet.Protocol.Plugins; using PataPawaPostPay; using Shouldly; using Testing; @@ -49,7 +49,7 @@ public async Task PataPawaPostPayProxy_ProcessLogonMessage_SuccessfulResponse_Me PataPawaPostPayService.Setup(s => s.getLoginRequestAsync(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.PataPawaPostPaidSuccessfulLoginResponse); - OperatorResponse logonResponse = await PataPawaPostPayProxy.ProcessLogonMessage("", CancellationToken.None); + BusinessLogic.OperatorInterfaces.OperatorResponse logonResponse = await PataPawaPostPayProxy.ProcessLogonMessage("", CancellationToken.None); logonResponse.ShouldNotBeNull(); logonResponse.IsSuccessful.ShouldBeTrue(); @@ -62,7 +62,19 @@ public async Task PataPawaPostPayProxy_ProcessLogonMessage_SuccessfulResponse_Me balance.ShouldBe(TestData.PataPawaPostPaidSuccessfulLoginResponse.balance); } - + [Fact] + public async Task PataPawaPostPayProxy_ProcessLogonMessage_LogonCached_SuccessfulResponse_MessageIsProcessed() + { + BusinessLogic.OperatorInterfaces.OperatorResponse operatorResponse = new() { TransactionId = Guid.Parse("2D9D6BBA-BDF4-4248-9B27-6B68374AC037").ToString() }; + + this.MemoryCache.Set("PataPawaPostPayLogon", operatorResponse, new MemoryCacheEntryOptions()); + + var result = await PataPawaPostPayProxy.ProcessLogonMessage("", CancellationToken.None); + + result.IsSuccess.ShouldBeTrue(); + result.Data.TransactionId.ShouldBe(operatorResponse.TransactionId); + } + [Fact] public async Task PataPawaPostPayProxy_ProcessLogonMessage_FailedResponse_MessageIsProcessed() { @@ -81,7 +93,7 @@ public async Task PataPawaPostPayProxy_ProcessSaleMessage_VerifyAccount_Successf .ReturnsAsync(TestData.PataPawaPostPaidSuccessfulVerifyAccountResponse); MemoryCache.Set("PataPawaPostPayLogon", TestData.PataPawaPostPaidSuccessfulLoginOperatorResponse); - OperatorResponse saleResponse = await this.PataPawaPostPayProxy.ProcessSaleMessage(TestData.TokenResponse().AccessToken, + BusinessLogic.OperatorInterfaces.OperatorResponse saleResponse = await this.PataPawaPostPayProxy.ProcessSaleMessage(TestData.TokenResponse().AccessToken, TestData.TransactionId, TestData.OperatorId, TestData.Merchant, @@ -205,7 +217,7 @@ public async Task PataPawaPostPayProxy_ProcessSaleMessage_ProcessBill_Successful .ReturnsAsync(TestData.PataPawaPostPaidSuccessfulProcessBillResponse); this.MemoryCache.Set("PataPawaPostPayLogon", TestData.PataPawaPostPaidSuccessfulLoginOperatorResponse); - OperatorResponse saleResponse = await this.PataPawaPostPayProxy.ProcessSaleMessage(TestData.TokenResponse().AccessToken, + BusinessLogic.OperatorInterfaces.OperatorResponse saleResponse = await this.PataPawaPostPayProxy.ProcessSaleMessage(TestData.TokenResponse().AccessToken, TestData.TransactionId, TestData.OperatorId, TestData.Merchant, diff --git a/TransactionProcessor.BusinessLogic.Tests/OperatorInterfaces/PataPawaPrePayProxyTests.cs b/TransactionProcessor.BusinessLogic.Tests/OperatorInterfaces/PataPawaPrePayProxyTests.cs new file mode 100644 index 00000000..a8c89e32 --- /dev/null +++ b/TransactionProcessor.BusinessLogic.Tests/OperatorInterfaces/PataPawaPrePayProxyTests.cs @@ -0,0 +1,458 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Caching.Memory; +using Newtonsoft.Json; +using RichardSzalay.MockHttp; +using Shared.Logger; +using Shouldly; +using SimpleResults; +using TransactionProcessor.BusinessLogic.OperatorInterfaces; +using TransactionProcessor.BusinessLogic.OperatorInterfaces.PataPawaPrePay; +using TransactionProcessor.Testing; +using Xunit; + +namespace TransactionProcessor.BusinessLogic.Tests.OperatorInterfaces; + +public class PataPawaPrePayProxyTests { + private readonly IOperatorProxy PataPawaPrePayProxy; + private readonly MockHttpMessageHandler MockHttpMessageHandler; + private readonly IMemoryCache MemoryCache = new MemoryCache(new MemoryCacheOptions()); + + public PataPawaPrePayProxyTests() { + PataPawaPrePaidConfiguration configuration = new PataPawaPrePaidConfiguration(); + configuration.Url = "http://localhost"; + configuration.Password = "password"; + configuration.Username = "username"; + + this.MockHttpMessageHandler = new MockHttpMessageHandler(); + HttpClient httpClient = new HttpClient(this.MockHttpMessageHandler); + + this.PataPawaPrePayProxy = new PataPawaPrePayProxy(configuration, httpClient, this.MemoryCache); + + Logger.Initialise(NullLogger.Instance); + } + + [Fact] + public async Task PataPawaPrePayProxy_ProcessLogonMessage_MessageProcessed() { + + LogonResponse logonResponse = new LogonResponse { Balance = "0", Key = "Key", Msg = "Success", Status = 0 }; + + this.MockHttpMessageHandler.When("http://localhost").Respond("application/json", JsonConvert.SerializeObject(logonResponse)); + + var result = await this.PataPawaPrePayProxy.ProcessLogonMessage("token", CancellationToken.None); + result.IsSuccess.ShouldBeTrue(); + result.Data.ResponseCode.ShouldBe("0000"); + result.Data.IsSuccessful.ShouldBeTrue(); + } + + [Fact] + public async Task PataPawaPrePayProxy_ProcessLogonMessage_CachedResponse_MessageProcessed() { + BusinessLogic.OperatorInterfaces.OperatorResponse operatorResponse = new() { TransactionId = Guid.Parse("2D9D6BBA-BDF4-4248-9B27-6B68374AC037").ToString() }; + + this.MemoryCache.Set("PataPawaPrePayLogon", operatorResponse, new MemoryCacheEntryOptions()); + LogonResponse logonResponse = new LogonResponse { Balance = "0", Key = "Key", Msg = "Success", Status = 0 }; + + var result = await this.PataPawaPrePayProxy.ProcessLogonMessage("token", CancellationToken.None); + result.IsSuccess.ShouldBeTrue(); + result.Data.TransactionId.ShouldBe(operatorResponse.TransactionId); + } + + [Fact] + public async Task PataPawaPrePayProxy_ProcessLogonMessage_FailedLogon_MessageProcessed() + { + LogonResponse logonResponse = new LogonResponse { Balance = "0", Key = "Key", Msg = "Success", Status = -1 }; + + this.MockHttpMessageHandler.When("http://localhost").Respond("application/json", JsonConvert.SerializeObject(logonResponse)); + + var result = await this.PataPawaPrePayProxy.ProcessLogonMessage("token", CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task PataPawaPrePayProxy_ProcessLogonMessage_HttpCallFailed_MessageProcessed() + { + LogonResponse logonResponse = new LogonResponse { Balance = "0", Key = "Key", Msg = "Success", Status = -1 }; + + this.MockHttpMessageHandler.When("http://localhost").Respond(req => new HttpResponseMessage(HttpStatusCode.BadRequest)); + + var result = await this.PataPawaPrePayProxy.ProcessLogonMessage("token", CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task PataPawaPrePayProxy_ProcessSaleMessage_MeterTransaction_MessageProcessed() + { + BusinessLogic.OperatorInterfaces.OperatorResponse operatorResponse = new() + { + TransactionId = Guid.Parse("2D9D6BBA-BDF4-4248-9B27-6B68374AC037").ToString(), + AdditionalTransactionResponseMetadata = new Dictionary{ + {"PataPawaPrePaidAPIKey", "APIKey"} + } + }; + + this.MemoryCache.Set("PataPawaPrePayLogon", operatorResponse, new MemoryCacheEntryOptions()); + + Dictionary metaDataDictionary = new Dictionary(); + metaDataDictionary.Add("PataPawaPrePayMessageType", "meter"); + metaDataDictionary.Add("MeterNumber", "123456"); + + MeterResponse meterResponse = new MeterResponse { Status = 0, Code = "1", CustomerName = "Customer", Msg = "msg" }; + + this.MockHttpMessageHandler.When("http://localhost").Respond("application/json", JsonConvert.SerializeObject(meterResponse)); + + var result = await this.PataPawaPrePayProxy.ProcessSaleMessage("token", TestData.TransactionId, + TestData.OperatorId, TestData.Merchant, TestData.TransactionDateTime, TestData.TransactionReference, + metaDataDictionary, CancellationToken.None); + + result.IsSuccess.ShouldBeTrue(); + result.Data.ResponseCode.ShouldBe("0000"); + result.Data.IsSuccessful.ShouldBeTrue(); + } + + [Fact] + public async Task PataPawaPrePayProxy_ProcessSaleMessage_MeterTransaction_FailedAtOperator_MessageProcessed() + { + BusinessLogic.OperatorInterfaces.OperatorResponse operatorResponse = new() + { + TransactionId = Guid.Parse("2D9D6BBA-BDF4-4248-9B27-6B68374AC037").ToString(), + AdditionalTransactionResponseMetadata = new Dictionary{ + {"PataPawaPrePaidAPIKey", "APIKey"} + } + }; + + this.MemoryCache.Set("PataPawaPrePayLogon", operatorResponse, new MemoryCacheEntryOptions()); + + Dictionary metaDataDictionary = new Dictionary(); + metaDataDictionary.Add("PataPawaPrePayMessageType", "meter"); + metaDataDictionary.Add("MeterNumber", "123456"); + + MeterResponse meterResponse = new MeterResponse { Status = -1, Code = "1", CustomerName = "Customer", Msg = "msg" }; + + this.MockHttpMessageHandler.When("http://localhost").Respond("application/json", JsonConvert.SerializeObject(meterResponse)); + + var result = await this.PataPawaPrePayProxy.ProcessSaleMessage("token", TestData.TransactionId, + TestData.OperatorId, TestData.Merchant, TestData.TransactionDateTime, TestData.TransactionReference, + metaDataDictionary, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task PataPawaPrePayProxy_ProcessSaleMessage_VendTransaction_MessageProcessed() + { + BusinessLogic.OperatorInterfaces.OperatorResponse operatorResponse = new() + { + TransactionId = Guid.Parse("2D9D6BBA-BDF4-4248-9B27-6B68374AC037").ToString(), + AdditionalTransactionResponseMetadata = new Dictionary{ + {"PataPawaPrePaidAPIKey", "APIKey"} + } + }; + + this.MemoryCache.Set("PataPawaPrePayLogon", operatorResponse, new MemoryCacheEntryOptions()); + + Dictionary metaDataDictionary = new Dictionary(); + metaDataDictionary.Add("PataPawaPrePayMessageType", "vend"); + metaDataDictionary.Add("MeterNumber", "123456"); + metaDataDictionary.Add("CustomerName", "Mr Customer"); + metaDataDictionary.Add("Amount", "100"); + + VendResponse vendResponse = new VendResponse { Status = 0, Msg = "msg", + Transaction = new BusinessLogic.OperatorInterfaces.PataPawaPrePay.Transaction { + CustomerName = "Mr Customer" + }}; + + this.MockHttpMessageHandler.When("http://localhost").Respond("application/json", JsonConvert.SerializeObject(vendResponse)); + + var result = await this.PataPawaPrePayProxy.ProcessSaleMessage("token", TestData.TransactionId, + TestData.OperatorId, TestData.Merchant, TestData.TransactionDateTime, TestData.TransactionReference, + metaDataDictionary, CancellationToken.None); + + result.IsSuccess.ShouldBeTrue(); + result.Data.ResponseCode.ShouldBe("0000"); + result.Data.IsSuccessful.ShouldBeTrue(); + } + + [Fact] + public async Task PataPawaPrePayProxy_ProcessSaleMessage_VendTransaction_FailedAtOperator_MessageProcessed() + { + BusinessLogic.OperatorInterfaces.OperatorResponse operatorResponse = new() + { + TransactionId = Guid.Parse("2D9D6BBA-BDF4-4248-9B27-6B68374AC037").ToString(), + AdditionalTransactionResponseMetadata = new Dictionary{ + {"PataPawaPrePaidAPIKey", "APIKey"} + } + }; + + this.MemoryCache.Set("PataPawaPrePayLogon", operatorResponse, new MemoryCacheEntryOptions()); + + Dictionary metaDataDictionary = new Dictionary(); + metaDataDictionary.Add("PataPawaPrePayMessageType", "vend"); + metaDataDictionary.Add("MeterNumber", "123456"); + metaDataDictionary.Add("CustomerName", "Mr Customer"); + metaDataDictionary.Add("Amount", "100"); + + VendResponse vendResponse = new VendResponse + { + Status = -1, + Msg = "msg", + Transaction = new BusinessLogic.OperatorInterfaces.PataPawaPrePay.Transaction + { + CustomerName = "Mr Customer" + } + }; + + this.MockHttpMessageHandler.When("http://localhost").Respond("application/json", JsonConvert.SerializeObject(vendResponse)); + + var result = await this.PataPawaPrePayProxy.ProcessSaleMessage("token", TestData.TransactionId, + TestData.OperatorId, TestData.Merchant, TestData.TransactionDateTime, TestData.TransactionReference, + metaDataDictionary, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + public async Task PataPawaPrePayProxy_ProcessSaleMessage_VendTransaction_CustomerNameIsNullOrEmpty_MessageProcessed(String customerName) + { + BusinessLogic.OperatorInterfaces.OperatorResponse operatorResponse = new() + { + TransactionId = Guid.Parse("2D9D6BBA-BDF4-4248-9B27-6B68374AC037").ToString(), + AdditionalTransactionResponseMetadata = new Dictionary{ + {"PataPawaPrePaidAPIKey", "APIKey"} + } + }; + + this.MemoryCache.Set("PataPawaPrePayLogon", operatorResponse, new MemoryCacheEntryOptions()); + + Dictionary metaDataDictionary = new Dictionary(); + metaDataDictionary.Add("PataPawaPrePayMessageType", "vend"); + metaDataDictionary.Add("MeterNumber", "123456"); + metaDataDictionary.Add("CustomerName", customerName); + metaDataDictionary.Add("Amount", "100"); + + VendResponse vendResponse = new VendResponse + { + Status = -1, + Msg = "msg", + Transaction = new BusinessLogic.OperatorInterfaces.PataPawaPrePay.Transaction + { + CustomerName = "Mr Customer" + } + }; + + this.MockHttpMessageHandler.When("http://localhost").Respond("application/json", JsonConvert.SerializeObject(vendResponse)); + + var result = await this.PataPawaPrePayProxy.ProcessSaleMessage("token", TestData.TransactionId, + TestData.OperatorId, TestData.Merchant, TestData.TransactionDateTime, TestData.TransactionReference, + metaDataDictionary, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + public async Task PataPawaPrePayProxy_ProcessSaleMessage_VendTransaction_AmountIsNullOrEmpty_MessageProcessed(String amount) + { + BusinessLogic.OperatorInterfaces.OperatorResponse operatorResponse = new() + { + TransactionId = Guid.Parse("2D9D6BBA-BDF4-4248-9B27-6B68374AC037").ToString(), + AdditionalTransactionResponseMetadata = new Dictionary{ + {"PataPawaPrePaidAPIKey", "APIKey"} + } + }; + + this.MemoryCache.Set("PataPawaPrePayLogon", operatorResponse, new MemoryCacheEntryOptions()); + + Dictionary metaDataDictionary = new Dictionary(); + metaDataDictionary.Add("PataPawaPrePayMessageType", "vend"); + metaDataDictionary.Add("MeterNumber", "123456"); + metaDataDictionary.Add("CustomerName", "Mr Customer"); + metaDataDictionary.Add("Amount", amount); + + VendResponse vendResponse = new VendResponse + { + Status = -1, + Msg = "msg", + Transaction = new BusinessLogic.OperatorInterfaces.PataPawaPrePay.Transaction + { + CustomerName = "Mr Customer" + } + }; + + this.MockHttpMessageHandler.When("http://localhost").Respond("application/json", JsonConvert.SerializeObject(vendResponse)); + + var result = await this.PataPawaPrePayProxy.ProcessSaleMessage("token", TestData.TransactionId, + TestData.OperatorId, TestData.Merchant, TestData.TransactionDateTime, TestData.TransactionReference, + metaDataDictionary, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task PataPawaPrePayProxy_ProcessSaleMessage_UnknownMessageType_MessageProcessed() + { + BusinessLogic.OperatorInterfaces.OperatorResponse operatorResponse = new() + { + TransactionId = Guid.Parse("2D9D6BBA-BDF4-4248-9B27-6B68374AC037").ToString(), + AdditionalTransactionResponseMetadata = new Dictionary{ + {"PataPawaPrePaidAPIKey", "APIKey"} + } + }; + + this.MemoryCache.Set("PataPawaPrePayLogon", operatorResponse, new MemoryCacheEntryOptions()); + + Dictionary metaDataDictionary = new Dictionary(); + metaDataDictionary.Add("PataPawaPrePayMessageType", "unknown"); + metaDataDictionary.Add("MeterNumber", "123456"); + metaDataDictionary.Add("CustomerName", "Mr Customer"); + metaDataDictionary.Add("Amount", "100"); + + VendResponse vendResponse = new VendResponse + { + Status = 0, + Msg = "msg", + Transaction = new BusinessLogic.OperatorInterfaces.PataPawaPrePay.Transaction + { + CustomerName = "Mr Customer" + } + }; + + this.MockHttpMessageHandler.When("http://localhost").Respond("application/json", JsonConvert.SerializeObject(vendResponse)); + + var result = await this.PataPawaPrePayProxy.ProcessSaleMessage("token", TestData.TransactionId, + TestData.OperatorId, TestData.Merchant, TestData.TransactionDateTime, TestData.TransactionReference, + metaDataDictionary, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + result.Status.ShouldBe(ResultStatus.Invalid); + } + + [Fact] + public async Task PataPawaPrePayProxy_ProcessSaleMessage_NoLogonResponse_MessageProcessed() + { + //BusinessLogic.OperatorInterfaces.OperatorResponse operatorResponse = new() + //{ + // TransactionId = Guid.Parse("2D9D6BBA-BDF4-4248-9B27-6B68374AC037").ToString(), + // AdditionalTransactionResponseMetadata = new Dictionary{ + // {"PataPawaPrePaidAPIKey", "APIKey"} + // } + //}; + + //this.MemoryCache.Set("PataPawaPrePayLogon", operatorResponse, new MemoryCacheEntryOptions()); + + Dictionary metaDataDictionary = new Dictionary(); + metaDataDictionary.Add("PataPawaPrePayMessageType", "meter"); + metaDataDictionary.Add("MeterNumber", "123456"); + + //MeterResponse meterResponse = new MeterResponse { Status = 0, Code = "1", CustomerName = "Customer", Msg = "msg" }; + + //this.MockHttpMessageHandler.When("http://localhost").Respond("application/json", JsonConvert.SerializeObject(meterResponse)); + + var result = await this.PataPawaPrePayProxy.ProcessSaleMessage("token", TestData.TransactionId, + TestData.OperatorId, TestData.Merchant, TestData.TransactionDateTime, TestData.TransactionReference, + metaDataDictionary, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + result.Status.ShouldBe(ResultStatus.Invalid); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + public async Task PataPawaPrePayProxy_ProcessSaleMessage_APIKeyNullOrEmpty_MessageProcessed(String apiKey) + { + BusinessLogic.OperatorInterfaces.OperatorResponse operatorResponse = new() + { + TransactionId = Guid.Parse("2D9D6BBA-BDF4-4248-9B27-6B68374AC037").ToString(), + AdditionalTransactionResponseMetadata = new Dictionary{ + {"PataPawaPrePaidAPIKey",apiKey} + } + }; + + this.MemoryCache.Set("PataPawaPrePayLogon", operatorResponse, new MemoryCacheEntryOptions()); + + Dictionary metaDataDictionary = new Dictionary(); + metaDataDictionary.Add("PataPawaPrePayMessageType", "meter"); + metaDataDictionary.Add("MeterNumber", "123456"); + + //MeterResponse meterResponse = new MeterResponse { Status = 0, Code = "1", CustomerName = "Customer", Msg = "msg" }; + + //this.MockHttpMessageHandler.When("http://localhost").Respond("application/json", JsonConvert.SerializeObject(meterResponse)); + + var result = await this.PataPawaPrePayProxy.ProcessSaleMessage("token", TestData.TransactionId, + TestData.OperatorId, TestData.Merchant, TestData.TransactionDateTime, TestData.TransactionReference, + metaDataDictionary, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + result.Status.ShouldBe(ResultStatus.Invalid); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + public async Task PataPawaPrePayProxy_ProcessSaleMessage_MessageTypeNullOrEmpty_MessageProcessed(String messageType) + { + BusinessLogic.OperatorInterfaces.OperatorResponse operatorResponse = new() + { + TransactionId = Guid.Parse("2D9D6BBA-BDF4-4248-9B27-6B68374AC037").ToString(), + AdditionalTransactionResponseMetadata = new Dictionary{ + {"PataPawaPrePaidAPIKey","APIKey"} + } + }; + + this.MemoryCache.Set("PataPawaPrePayLogon", operatorResponse, new MemoryCacheEntryOptions()); + + Dictionary metaDataDictionary = new Dictionary(); + metaDataDictionary.Add("PataPawaPrePayMessageType", messageType); + metaDataDictionary.Add("MeterNumber", "123456"); + + //MeterResponse meterResponse = new MeterResponse { Status = 0, Code = "1", CustomerName = "Customer", Msg = "msg" }; + + //this.MockHttpMessageHandler.When("http://localhost").Respond("application/json", JsonConvert.SerializeObject(meterResponse)); + + var result = await this.PataPawaPrePayProxy.ProcessSaleMessage("token", TestData.TransactionId, + TestData.OperatorId, TestData.Merchant, TestData.TransactionDateTime, TestData.TransactionReference, + metaDataDictionary, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + result.Status.ShouldBe(ResultStatus.Invalid); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + public async Task PataPawaPrePayProxy_ProcessSaleMessage_MeterNumberNullOrEmpty_MessageProcessed(String meterNumber) + { + BusinessLogic.OperatorInterfaces.OperatorResponse operatorResponse = new() + { + TransactionId = Guid.Parse("2D9D6BBA-BDF4-4248-9B27-6B68374AC037").ToString(), + AdditionalTransactionResponseMetadata = new Dictionary{ + {"PataPawaPrePaidAPIKey","APIKey"} + } + }; + + this.MemoryCache.Set("PataPawaPrePayLogon", operatorResponse, new MemoryCacheEntryOptions()); + + Dictionary metaDataDictionary = new Dictionary(); + metaDataDictionary.Add("PataPawaPrePayMessageType", "meter"); + metaDataDictionary.Add("MeterNumber", meterNumber); + + //MeterResponse meterResponse = new MeterResponse { Status = 0, Code = "1", CustomerName = "Customer", Msg = "msg" }; + + //this.MockHttpMessageHandler.When("http://localhost").Respond("application/json", JsonConvert.SerializeObject(meterResponse)); + + var result = await this.PataPawaPrePayProxy.ProcessSaleMessage("token", TestData.TransactionId, + TestData.OperatorId, TestData.Merchant, TestData.TransactionDateTime, TestData.TransactionReference, + metaDataDictionary, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + result.Status.ShouldBe(ResultStatus.Invalid); + } + +} \ No newline at end of file diff --git a/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj b/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj index 6e144a25..0e8710e2 100644 --- a/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj +++ b/TransactionProcessor.BusinessLogic.Tests/TransactionProcessor.BusinessLogic.Tests.csproj @@ -12,6 +12,7 @@ + diff --git a/TransactionProcessor.BusinessLogic/OperatorInterfaces/PataPawaPrePay/PataPawaPrePayProxy.cs b/TransactionProcessor.BusinessLogic/OperatorInterfaces/PataPawaPrePay/PataPawaPrePayProxy.cs index d98d6107..e4b5c347 100644 --- a/TransactionProcessor.BusinessLogic/OperatorInterfaces/PataPawaPrePay/PataPawaPrePayProxy.cs +++ b/TransactionProcessor.BusinessLogic/OperatorInterfaces/PataPawaPrePay/PataPawaPrePayProxy.cs @@ -1,4 +1,5 @@ -using System.Reflection.Metadata.Ecma335; +using System.Diagnostics.CodeAnalysis; +using System.Reflection.Metadata.Ecma335; using SimpleResults; namespace TransactionProcessor.BusinessLogic.OperatorInterfaces.PataPawaPrePay; @@ -126,7 +127,7 @@ private async Task> PerformVendTransaction(String meter String amount = additionalTransactionMetadata.ExtractFieldFromMetadata("Amount"); - if (String.IsNullOrEmpty(meterNumber)) + if (String.IsNullOrEmpty(amount)) { return Result.Invalid("Amount - Amount is a required field for this transaction type"); } @@ -232,6 +233,7 @@ private Result CreateFromVend(String responseContent) new MemoryCacheEntryOptions().SetPriority(CacheItemPriority.NeverRemove).SetSlidingExpiration(TimeSpan.FromHours(1)) .RegisterPostEvictionCallback(this.PostEvictionCallback); + [ExcludeFromCodeCoverage] private void PostEvictionCallback(Object key, Object value, EvictionReason reason,