private void AssertResult(string url, HttpMethod method, PaymentResponse response) { _httpMessageHandler.AssertUrl($"{_settings.BaseUrl}/{url}") .Should() .BeTrue(); _httpMessageHandler.AssertHttpMethod(method) .Should() .BeTrue(); response.Should() .NotBeNull(); response.Should().BeEquivalentTo(_apiResponse); }
public async Task HandlePayment_ReturnSuccessfulPaymentResponse_WhenPaymentPassedAllChecks() { // Arrange var request = CreateMakePaymentCommand(); var(payment, paymentResponse) = CreateSuccessfulPaymentAndPaymentResponse(); A.CallTo(() => _validatorsEnumerator.Current).Returns(new CardNumberLengthValidator()); A.CallTo(() => _validators.GetEnumerator()).Returns(_validatorsEnumerator); A.CallTo(() => _validatorService.Validate(_validators, request)).Returns((true, new List <ValidationError>())); A.CallTo(() => _bankService.ProcessPayment(request)).Returns(paymentResponse); A.CallTo(() => _paymentsService.CreateAsync(payment)); A.CallTo(() => _paymentMapper.Map(payment)).Returns(paymentResponse); // Act var response = await _sut.Handle(request, new CancellationToken()); // Assert var expectedPaymentResponse = new PaymentResponse { Id = paymentResponse.Id, BankPaymentId = paymentResponse.BankPaymentId, MerchantPaymentId = paymentResponse.MerchantPaymentId, BillingDetails = paymentResponse.BillingDetails, Currency = paymentResponse.Currency, Amount = paymentResponse.Amount, Status = paymentResponse.Status, ValidationErrors = paymentResponse.ValidationErrors, Reason = paymentResponse.Reason, TimeStamp = DateTime.UtcNow }; expectedPaymentResponse.Should().BeEquivalentTo(expectedPaymentResponse, x => x.Excluding(a => a.TimeStamp)); }
public void Process_Payment(PaymentRequest paymentRequest, HttpResponseMessage httpResponse, PaymentResponse paymentResponse) { "Given i have a payment request" .x(() => paymentRequest = GivenPaymentRequest()); "When i make a payment request" .x(async() => { httpResponse = await MakePaymentRequest(paymentRequest); }); "Then a 201 created response is returned" .x(() => httpResponse.StatusCode.Should().Be(HttpStatusCode.Created)); "Then the payment identifier should be returned" .x(async() => { var stringResult = await httpResponse.Content.ReadAsStringAsync(); paymentResponse = JsonSerializer.Deserialize <PaymentResponse>(stringResult, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); paymentResponse.Should().NotBeNull(); paymentResponse.PaymentId.Should().NotBeNull(); }); "And the saved card details should be encripted" .x(async() => await AssertPaymentIsPersistAndCardDetailsAreEncripted(paymentResponse, paymentRequest)); }
public void Process_Payment(PaymentRequest paymentRequest, PaymentResponse paymentResponse) { "Given i have a payment request" .x(() => paymentRequest = GivenPaymentRequest()); "When i make a payment request" .x(async() => { paymentResponse = await MakePaymentRequest(paymentRequest); paymentResponse.Should().NotBeNull(); paymentResponse.PaymentId.Should().NotBeNull(); }); "And the saved card details should be encripted" .x(async() => await AssertPaymentIsPersistAndCardDetailsAreEncripted(paymentResponse, paymentRequest)); }