public void UpdatePayment() { var context = serviceProvider.GetRequiredService <DataContext>(); var controller = new PaymentsController(context); context.Payment.Add(payment1); context.SaveChanges(); //The entity is not being tracked by the context context.Entry(payment1).State = EntityState.Detached; Payment payment3 = new Payment { Id = 1, Amount = 9000, Currency = "$", Source = "Balanica Gabriel", Date = new DateTime(2020, 12, 30), Destination = "Spantu Theodor Ioan", Status = "complete", latitude = 93.231f, longitude = 44.2f }; var updateResult = controller.PutPayment(1, payment3).Result; Assert.IsType <OkResult>(updateResult); }
public async Task TestPutPaymentAmount(decimal amountPaid) { // Arrange var mockPaymentRepo = new Mock <IPaymentRepository>(); var mockCustomerRepo = new Mock <ICustomerRepository>(); var paymentDTO = CreatePaymentData(); paymentDTO.AmountPaid = amountPaid; mockPaymentRepo.Setup(repo => repo.GetPaymentFromCustomer(paymentDTO.CustomerId)) .ReturnsAsync(paymentDTO); mockCustomerRepo.Setup(repo => repo.GetCustomer(paymentDTO.CustomerId)) .ReturnsAsync(paymentDTO.Customer); // Act var controller = new PaymentsController(mockPaymentRepo.Object, mockCustomerRepo.Object); SimulateModelValidation.Validate(mockPaymentRepo, controller); var result = await controller.PutPayment(paymentDTO.PaymentId, paymentDTO); // Assert var okResult = Assert.IsType <OkObjectResult>(result); var res = Assert.IsType <Payment>(okResult.Value); var idea = res as Payment; Assert.Equal(1, idea.PaymentId); Assert.NotNull(idea.Customer); Assert.NotNull(idea.Domain); if (paymentDTO.Amount == 0) { Assert.Equal(PaymentStatus.COMPLETE, idea.Status); Assert.Null(idea.DueDate); } else { Assert.NotNull(idea.DueDate); Assert.Equal(PaymentStatus.PROCESSING, idea.Status); } }