public async Task WhenUpdatePaymentAsync_ThenPaymentUpdated() { // Arrange var payment = new Payment() { ID = Guid.NewGuid(), CustomerID = Guid.NewGuid(), Amount = 100, ApproverID = Guid.NewGuid(), Comment = "test", PaymentStatus = PaymentStatus.Pending, PaymentDateUtc = DateTime.UtcNow, RequestedDateUtc = DateTime.UtcNow.AddDays(2) }; using (var ctx = _dbContextCreator.CreateDbContext()) { ctx.Add(payment); await ctx.SaveChangesAsync(); } var updatedPayment = payment.Adapt <Payment>(); updatedPayment.PaymentStatus = PaymentStatus.Closed; updatedPayment.ProcessedDateUtc = DateTime.UtcNow.AddDays(1); // Act var result = await _repo.UpdatePaymentAsync(updatedPayment); //Assert result.Should().BeEquivalentTo(updatedPayment); using (var ctx = _dbContextCreator.CreateDbContext()) { var paymentInDb = await ctx.Payment.FirstOrDefaultAsync(); paymentInDb.Should().BeEquivalentTo(updatedPayment); } }
public async Task GivenCustomerAndStaffExist_WhenProcessPayment_ThenPaymentProcessed() { // Arrange var customer = new Customer() { ID = Guid.NewGuid(), CurrentBalance = 200 }; var approver = new Staff() { ID = Guid.NewGuid() }; var payment = new Payment() { ID = Guid.NewGuid(), Amount = 100, PaymentDateUtc = DateTime.UtcNow.AddDays(-5), RequestedDateUtc = DateTime.UtcNow.AddDays(-5), CustomerID = customer.ID, PaymentStatus = PaymentStatus.Pending }; using (var ctx = _dbContextCreator.CreateDbContext()) { ctx.Add(customer); ctx.Add(approver); ctx.Add(payment); await ctx.SaveChangesAsync(); } // Shallow copy payment var updatedPayment = payment.Adapt <Payment>(); updatedPayment.Customer = null; updatedPayment.ApproverID = approver.ID; updatedPayment.PaymentStatus = PaymentStatus.Processed; // Act HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Patch, Url + payment.ID.ToString()); message.Content = new ObjectContent <Payment>(updatedPayment, new JsonMediaTypeFormatter()); var response = await _client.SendAsync(message); var result = await response.Content.ReadAsAsync <Payment>(); // Assert response.EnsureSuccessStatusCode(); result.Should().BeEquivalentTo(updatedPayment, options => options.Excluding(p => p.ProcessedDateUtc) .Excluding(p => p.Comment) .Excluding(p => p.Customer) .Excluding(p => p.Approver)); Assert.Equal(_utcNow, result.ProcessedDateUtc); Assert.Equal(Payment.ProcessedComment, result.Comment); using (var ctx = _dbContextCreator.CreateDbContext()) { var paymentInDb = await ctx.Payment.FirstOrDefaultAsync(); result.Should().BeEquivalentTo(paymentInDb, options => options.Excluding(p => p.Customer).Excluding(p => p.Approver)); var customerInDb = await ctx.Customer.FirstOrDefaultAsync(); Assert.Equal(customer.CurrentBalance, customerInDb.CurrentBalance); } }