public async Task GetById_SuccessResponse_ForValidId() { // Arrange var id = Guid.NewGuid().ToString(); var _testPayment = GetTestPaymentWithId(id); _paymentServiceMock.Setup(ps => ps.GetPaymentDetailsById(It.Is <string>(x => x.Equals(id, StringComparison.InvariantCultureIgnoreCase)))) .ReturnsAsync(_testPayment) .Verifiable(); // Act var response = await _paymentController.Get(id); // Assert Assert.IsNotNull(response, "Expected response from the API"); var result = response as OkObjectResult; Assert.IsNotNull(result, "OK Response expected from API"); Assert.AreEqual(200, result.StatusCode); var paymentSummary = result.Value as PaymentSummaryVm; Assert.IsNotNull(paymentSummary, "Payment Summary expected"); Assert.AreEqual(_testPayment.Id, paymentSummary.Id, "Id should match"); Assert.AreEqual($"XXXX-XXXX-XXXX-{_testPayment.CardNumber.Substring(15, 4)}", paymentSummary.MaskedCardNumber, "Masked CardNumber should match"); _paymentServiceMock.Verify(); }
public async Task GivenValidPaymentId_ShouldGetOkResult() { //act var response = await _sut.Get(_successfulPayment.Id); //assert response.Should().BeAssignableTo <OkObjectResult>(); }
public async Task Returns_404_status_code_when_payment_is_not_found() { _repositoryMock.Setup(x => x.GetAsync(It.IsAny <GetPaymentRequest>())).Returns(Task.FromResult <Payment>(null)); var response = (NotFoundResult)await _paymentController.Get("", ""); Assert.That(response.StatusCode, Is.EqualTo((int)HttpStatusCode.NotFound)); _repositoryMock.VerifyAll(); }
public async Task return_payment_details_for_a_given_payment_identifier() { var paymentId = Guid.NewGuid(); var paymentDetails = TestHelpers.CreatePaymentDetails(paymentId); retrievePaymentService.Setup(a => a.Get(paymentId)).ReturnsAsync(paymentDetails); var result = await paymentController.Get(paymentId) as OkObjectResult; result.Value.Should().BeOfType <PaymentDetails>(); result.Value.Should().Be(paymentDetails); }
public async Task GetPayment_ReturnsOkObjectResult() { // Arrange Guid id = Guid.NewGuid(); PaymentStatus paymentStatus = PaymentStatus.Paid; PaymentRespModel paymentRespModel = MockPaymentRespModel.Get(id, paymentStatus); ModelStateDictionary modelStateDictionary = new ModelStateDictionary(); mockPaymentManager.Setup(s => s.GetAsync(It.IsAny <Guid>(), It.IsAny <ModelStateDictionary>())) .Returns(Task.FromResult <(PaymentRespModel, ModelStateDictionary)>((paymentRespModel, modelStateDictionary))) .Verifiable(); // Act ActionResult actionResult = await paymentController.Get(id) as ActionResult; // Assert Assert.IsNotNull(actionResult); Assert.IsInstanceOf <OkObjectResult>(actionResult); OkObjectResult okObjectResult = actionResult as OkObjectResult; Assert.IsNotNull(okObjectResult); Assert.AreEqual(StatusCodes.Status200OK, okObjectResult.StatusCode); Assert.IsNotNull(okObjectResult.Value); Assert.IsInstanceOf <PaymentRespVM>(okObjectResult.Value); PaymentRespVM paymentRespVM = okObjectResult.Value as PaymentRespVM; Assert.IsNotNull(paymentRespVM); Assert.AreEqual(id, paymentRespVM.Id); Assert.AreEqual(paymentStatus.ToString(), paymentRespVM.Status); Assert.AreEqual(CurrencyCode.GBP.ToString(), paymentRespVM.Currency); Assert.AreEqual(1, paymentRespVM.Amount); Assert.IsNotNull(paymentRespVM.CardDetails); Assert.AreEqual("J Doe", paymentRespVM.CardDetails.NameOnCard); Assert.AreEqual(CardType.Credit.ToString(), paymentRespVM.CardDetails.CardType); Assert.AreEqual(Issuer.Visa.ToString(), paymentRespVM.CardDetails.Issuer); Assert.AreEqual("6331", paymentRespVM.CardDetails.CardnumberLast4); Assert.AreEqual("***", paymentRespVM.CardDetails.Cvv); Assert.AreEqual(1, paymentRespVM.CardDetails.ExpiryMonth); Assert.AreEqual(2020, paymentRespVM.CardDetails.ExpiryYear); mockPaymentManager.Verify(v => v.GetAsync(It.IsAny <Guid>(), It.IsAny <ModelStateDictionary>())); }
public async Task Given_payment_exists_when_get_payment_called_with_payment_id_then_returns_payment() { var paymentsRepo = new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance); var existingPayment = new Payment( Id: Guid.NewGuid(), Amount: new(1.23m, "GBP"), Description: "Test Payment", Card: new( MaskedPan: "1234", ExpiryMonth: new(2021, 01) ), Result: PaymentResult.Succeeded, Timestamp: SystemClock.Instance.GetCurrentInstant(), CreatedAt: SystemClock.Instance.GetCurrentInstant()); await paymentsRepo.Create(existingPayment, PaymentController.DefaultMerchant.Id); var sut = new PaymentController(paymentsRepo, new AlwaysThrowsPaymentAuthoriser(), SystemClock.Instance, NullLogger <PaymentController> .Instance); var result = await sut.Get(existingPayment.Id); var actionResult = Assert.IsType <ActionResult <PaymentResponse> >(result); var okResult = Assert.IsType <OkObjectResult>(actionResult.Result); var returnedPayment = Assert.IsType <PaymentResponse>(okResult.Value); Assert.Equal(existingPayment.Amount, returnedPayment.Amount); Assert.Equal(existingPayment.Description, returnedPayment.Description); Assert.Equal(existingPayment.Result, returnedPayment.Result); }
public void Get() { _repo.Setup(m => m.GetAllPayments()).Returns(GetPayments()); var result = _controller.Get() as List <Payment>; Assert.Equal(4, result.Count); }
public void Merchant_GetTransactionById_NotFoundResult() { var controller = new PaymentController(_userService.Object, _cardService.Object, _transactService.Object, _logger.Object); var data = controller.Get(0); Assert.IsType <OkObjectResult>(data); }
public async Task AndTheIdIsIncorrect_ThenReturnBadRequest() { var nonGuidId = "testtesttest"; var sut = new PaymentController(null, _loggerMock.Object); var result = await sut.Get(nonGuidId); result.Should().BeOfType <BadRequestObjectResult>(); }
public async Task Given_InvalidId_When_GetIsInvoked_Then_NotFoundIsReturned() { // arrange var id = default(Guid); var paymentResponseFailed = new PaymentResponseFailedDto(); this.paymentService .Setup(p => p.GetAsync(It.IsAny <Guid>())) .ReturnsAsync(paymentResponseFailed); // act var actionResult = await paymentController.Get(id); // assert Assert.True(actionResult.Result is NotFoundObjectResult); Assert.Equal((actionResult.Result as NotFoundObjectResult).StatusCode, (int)HttpStatusCode.NotFound); }
public async Task AndThereIsNoPayment_ThenReturn404() { var nonExistingPaymentId = Guid.NewGuid(); var paymentServiceMock = new Mock <IPaymentService>(); var sut = new PaymentController(paymentServiceMock.Object, _loggerMock.Object); var result = await sut.Get(nonExistingPaymentId.ToString()); result.Should().BeOfType <NotFoundResult>(); }
public void Get_NotFound() { //Arrange PaymentController controller = new PaymentController(logger); //Act var result = controller.Get("04402d75-bea0-459a-9c6b-123456789"); //Assert Assert.IsTrue(result is NotFoundResult); }
public async Task ShouldPassGet() { var sut = new PaymentController(new Mock <ILogger <PaymentController> >().Object, _bankProcessor, _merchantRepository, _paymentRepository); var response = await sut.Get("bd2347d5-98b3-4d4e-8773-4eb4b33ca0d6", "TestReference"); var responseType = response.GetType(); Assert.IsTrue(responseType.Name == "OkObjectResult"); }
public async Task ShouldFailGet() { var sut = new PaymentController(new Mock <ILogger <PaymentController> >().Object, _bankProcessor, _merchantRepository, _paymentRepository); var response = await sut.Get(string.Empty, string.Empty); var responseType = response.GetType(); Assert.IsTrue(responseType.Name == "BadRequestObjectResult"); }
public async Task Given_non_existent_payment_when_get_payment_called_then_returns_not_found() { var sut = new PaymentController(new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance), new AlwaysThrowsPaymentAuthoriser(), SystemClock.Instance, NullLogger <PaymentController> .Instance); var result = await sut.Get(Guid.NewGuid()); var actionResult = Assert.IsType <ActionResult <PaymentResponse> >(result); _ = Assert.IsType <NotFoundResult>(actionResult.Result); }
public async Task Should_return_404_when_payment_not_found() { var paymentId = Guid.NewGuid(); _dynamoDbContextMock.Setup(self => self.LoadAsync <Payment>(paymentId, It.IsAny <CancellationToken>())) .ReturnsAsync(() => null); var response = await _paymentController.Get(paymentId); var result = (ObjectResult)response.Result; result.StatusCode.ShouldBe(404); var gatewayResponse = (PaymentGatewayResponse <PaymentDetail>)result.Value; gatewayResponse.Success.ShouldBe(false); gatewayResponse.ResponseCode.ShouldBe(ResponseCodes.PaymentNotFound); gatewayResponse.Entity.ShouldBeNull(); }
public void Get_Success() { //Arrange Post(); PaymentController controller = new PaymentController(logger); //Act var result = controller.Get(PaymentController._payments[0].Id); //Assert Assert.IsTrue(result is OkObjectResult); }
public void Get_should_return_not_found_if_the_payment_is_not_found() { var payments = new Mock <IPaymentRepository>(); payments.Setup(p => p.Get(It.IsAny <int>())).Returns((PaymentEntity)null); var controller = new PaymentController(Mock.Of <IBank>(), payments.Object); IActionResult result = controller.Get(1); Assert.True(result is NotFoundResult); }
public async Task AndThereIsAPayment_ThenReturn200_and_thePayment() { var existingPaymentId = Guid.NewGuid(); var paymentServiceMock = new Mock <IPaymentService>(); paymentServiceMock.Setup(x => x.GetPayment(existingPaymentId)).ReturnsAsync(new Payment { Id = existingPaymentId }); var sut = new PaymentController(paymentServiceMock.Object, _loggerMock.Object); var result = await sut.Get(existingPaymentId.ToString()); result.Should().BeOfType <OkObjectResult>(); }
public async Task AndThereIsExeption_ThenReturn500() { var paymentServiceMock = new Mock <IPaymentService>(); paymentServiceMock.Setup(x => x.GetPayment(It.IsAny <Guid>())).ThrowsAsync(new Exception()); var sut = new PaymentController(paymentServiceMock.Object, _loggerMock.Object); var result = await sut.Get(Guid.NewGuid().ToString()); result.Should().BeOfType <StatusCodeResult>(); var castedResult = (StatusCodeResult)result; castedResult.StatusCode.Should().Be(500); }
public void ShouldReturnBadRequestWhenPaymentDoesntExist() { var fixture = new Fixture(); var paymentServiceMock = new Mock <PaymentService>(); var paymentController = new PaymentController(paymentServiceMock.Object, new Mock <ILogger <PaymentController> >().Object, _fixture.Mapper); paymentController.ControllerContext = _fixture.ControllerContext; var response = paymentController.Get(Guid.NewGuid()).Result; var badRequestResult = response as BadRequestObjectResult; paymentServiceMock.Verify(p => p.GetPaymentDetailsAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); Assert.NotNull(badRequestResult); Assert.Equal(400, badRequestResult.StatusCode); }
public void ShouldReturnOkStatusWhenPaymentExists() { var fixture = new Fixture(); var paymentDetailsMock = fixture.Build <PaymentDetailsDto>().Create(); var paymentServiceMock = new Mock <PaymentService>(); paymentServiceMock.Setup(p => p.GetPaymentDetailsAsync(It.IsAny <Guid>(), It.IsAny <Guid>())).ReturnsAsync(paymentDetailsMock); var paymentController = new PaymentController(paymentServiceMock.Object, new Mock <ILogger <PaymentController> >().Object, _fixture.Mapper); paymentController.ControllerContext = _fixture.ControllerContext; var response = paymentController.Get(Guid.NewGuid()).Result; var okResult = response as OkObjectResult; paymentServiceMock.Verify(p => p.GetPaymentDetailsAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); Assert.NotNull(okResult); Assert.Equal(200, okResult.StatusCode); }
public void TestGetPayment() { // Arrange var dbContext = _paymentDbContext; var repository = new PaymentRepository(dbContext); var controller = new PaymentController(repository); var guid = new Guid(); var payment = new Payment { Id = guid, CardNumber = "4111 1111 1111 1111", CardHolderName = "John Doe", ExpiryYear = 2020, ExpiryMonth = 11, Amount = 2000, Currency = "USD", Cvv = "123", BankSuccess = true, BankTransactionId = new Guid().ToString() }; _paymentDbContext.Payments.Add(payment); // Act var response = controller.Get(guid.ToString()); var value = response.Value; _paymentDbContext.Payments.RemoveRange(_paymentDbContext.Payments); // Assert Assert.False(value == null); Assert.False(value.Id == null); Assert.False(value.BankSuccess == false); }
public static void ControlCredits(string userId) { Credit credit = new Credit(); Payment payment = new Payment(); PaymentController paymentController = new PaymentController(); CreditController creditController = new CreditController(); IHttpActionResult resp; var continuar = true; while (continuar) { Console.WriteLine("***************************"); Console.WriteLine("--------- CREDITOS --------"); Console.WriteLine("***************************"); credit.UserId = userId; resp = creditController.Get(credit); var listRespContent = resp as OkNegotiatedContentResult <List <Credit> >; if (listRespContent != null) { foreach (var c in listRespContent.Content) { Console.WriteLine(" ==> CREDITO: " + c.GetEntityInformation()); } } else { Console.WriteLine("No existen creditos registradas para este usuario"); } Console.WriteLine("--------------------"); Console.WriteLine("Que desea realizar?"); Console.WriteLine("1. Registrar un nuevo credito"); Console.WriteLine("2. Modificar credito"); Console.WriteLine("3. Eliminar credito"); Console.WriteLine("4. Ver pagos realizados"); Console.WriteLine("5. Realizar pago"); Console.WriteLine("6. Volver al menu principal"); Console.Write("Digite la opcion que desea: "); var option = Console.ReadLine(); switch (option) { case "1": Console.WriteLine("\n ***** Registrar nueva credito *******" + '\n'); Console.WriteLine("Ingrese la siguiente informacion en el mismo orden y separado por comas"); Console.WriteLine("Monto, Tasa de interes, Nombre de la linea de credito, Cuota, Fecha de inicio (aaaa-mm-dd), Estado del credito"); var info = Console.ReadLine(); var infoArray = info.Split(','); trimString(infoArray); credit = new Credit(infoArray, credit.UserId); resp = creditController.Post(credit); var creRespCont = resp as OkNegotiatedContentResult <Credit>; if (creRespCont != null) { Console.WriteLine(creRespCont.Content); } else { var errorMsg = resp as NegotiatedContentResult <string>; Console.WriteLine(errorMsg.Content); } break; case "2": Console.WriteLine("\n ***** Actualizar credito ***** \n"); Console.WriteLine("Ingrese la informacion actualizada"); Console.Write("Digite el id del credito a actualizar: "); credit.CreditId = Convert.ToInt32(Console.ReadLine()); Console.Write("Tasa de interes: "); credit.InterestRate = Convert.ToDouble(Console.ReadLine()); Console.Write("Nombre de linea del credito: "); credit.CreditLine = Console.ReadLine(); Console.Write("Cuota: "); credit.Fee = Convert.ToDouble(Console.ReadLine()); Console.Write("Fecha de inicio (aaaa-mm-dd): "); credit.StartDate = Convert.ToDateTime(Console.ReadLine()); Console.Write("Estado del credito (A= Aprobado/ D= Denegado/ P= Pendiente): "); credit.Status = Convert.ToChar(Console.ReadLine()); resp = creditController.Put(credit); var updRespCont = resp as OkNegotiatedContentResult <string>; if (updRespCont != null) { Console.WriteLine(updRespCont.Content); } else { var errorMsg = resp as NegotiatedContentResult <string>; Console.WriteLine(errorMsg.Content); } break; case "3": Console.WriteLine("\n ***** Eliminar credito ***** \n"); Console.Write("Digite el numero de cuenta a eliminar: "); credit.CreditId = Convert.ToInt32(Console.ReadLine()); resp = creditController.Delete(credit); var delRespCont = resp as OkNegotiatedContentResult <string>; if (delRespCont != null) { Console.WriteLine(delRespCont.Content); } else { var errorMsg = resp as NegotiatedContentResult <string>; Console.WriteLine(errorMsg.Content); } break; case "4": Console.WriteLine("\n ***** Pagos realizados ***** \n"); Console.Write("Ingrese el id del credito a consultar: "); payment.CreditId = Convert.ToInt32(Console.ReadLine()); resp = paymentController.Get(payment); var paymRespContent = resp as OkNegotiatedContentResult <List <Payment> >; if (paymRespContent != null) { foreach (var c in paymRespContent.Content) { Console.WriteLine(" ==> PAGO: " + c.GetEntityInformation()); } } else { var errorMsg = resp as NegotiatedContentResult <string>; Console.WriteLine(errorMsg.Content); } break; case "5": Console.WriteLine("\n ***** Hacer pago *******" + '\n'); Console.WriteLine("Digite el id del credito al cual va a realizar el pago"); credit.CreditId = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Ingrese la siguiente informacion en el mismo orden y separado por comas"); Console.WriteLine("Fecha de pago (aaaa-mm-dd), Monto"); info = Console.ReadLine(); infoArray = info.Split(','); trimString(infoArray); payment = new Payment(infoArray, credit.CreditId, credit.UserId); resp = paymentController.Post(payment); var payRespCont = resp as OkNegotiatedContentResult <string>; if (payRespCont != null) { Console.WriteLine(payRespCont.Content); } else { var errorMsg = resp as NegotiatedContentResult <string>; Console.WriteLine(errorMsg.Content); } break; case "6": continuar = false; break; } } }
public async Task WhenIGetThePaymentWithTheId(string paymentId) { returnedActionResult = await paymentController.Get(paymentId); }
public void Get_test() { PaymentController controller = GetController(); controller.Get(); }