public async Task SubmitPaymentToBank_ValidPaymentRequest_ReturnsCorrectDetails() { // Arrange var expectedBankId = new Guid("7b6bf96c-0231-41e3-9014-393ff87ed4e1"); PaymentRequest paymentRequest = new PaymentRequest { Amount = 100, CardholderName = "Testy McTester", CardNumber = "1111 2222 3333 4444", CurrencyIsoAlpha3 = "GBP", Cvv = "123", MerchantId = new Guid("aa9f4ef9-35ab-4a10-8cf5-f5535582fd01") }; var submissionDateTimeMock = new DateTimeOffset(2020, 01, 01, 0, 0, 0, new TimeSpan(0, 0, 0)); AcquiringBankResponse responseMock = new AcquiringBankResponse { BankId = expectedBankId, PaymentStatus = "Submitted", StatusDateTime = submissionDateTimeMock }; var data = JsonSerializer.Serialize(responseMock); var contentMock = new StringContent(data.ToString(), Encoding.UTF8, "application/json"); _httpMessageHandlerMock.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = contentMock }); var client = new HttpClient(_httpMessageHandlerMock.Object); var sut = new AcquiringBankClient(_acquiringBankSettingsMock.Object, client, _loggerMock.Object); // Act var result = await sut.SubmitPaymentToBank(paymentRequest); // Assert Assert.AreEqual(expectedBankId, result.BankId); Assert.AreEqual(PaymentStatuses.Submitted, result.PaymentStatus); Assert.AreEqual(submissionDateTimeMock, result.StatusDateTime); }
public async Task SubmitPaymentToBank_NullPaymentRequest_Throws() { // Arrange PaymentRequest paymentRequest = null; _httpMessageHandlerMock.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK }); var client = new HttpClient(_httpMessageHandlerMock.Object); var sut = new AcquiringBankClient(_acquiringBankSettingsMock.Object, client, _loggerMock.Object); // Act and Assert Assert.ThrowsAsync <ArgumentNullException>(() => sut.SubmitPaymentToBank(paymentRequest)); }