public async Task GetExpectedPaymentsForUserAsync_WhenCalledWithGroup_ShouldReturnExpectedPayments(PaymentServiceTestData testData) { //Arrange var sutBuilder = new PaymentServiceSutBuilder(); sutBuilder.SetupFromTestData(testData); var paymentService = sutBuilder.CreateSut(); //Act var payerPayments = await paymentService.GetExpectedPaymentsForUserAsync(testData.Payer.Id, testData.Group.Id); var receiverPayments = await paymentService.GetExpectedPaymentsForUserAsync(testData.Receiver.Id, testData.Group.Id); //Assert payerPayments.Count.ShouldBe(1); var payerPayment = payerPayments.Single(); payerPayment.Amount.ShouldBe(testData.PayerOwesReceiver); payerPayment.Payer.ShouldBe(testData.Payer); payerPayment.Receiver.ShouldBe(testData.Receiver); receiverPayments.Count.ShouldBe(1); var receiverPayment = payerPayments.Single(); receiverPayment.Amount.ShouldBe(testData.PayerOwesReceiver); receiverPayment.Payer.ShouldBe(testData.Payer); receiverPayment.Receiver.ShouldBe(testData.Receiver); }
public async Task AddPaymentAsync_WhenPaymentCorrect_ShouldReturnExpectedPayment(PaymentServiceTestData testData) { //Arrange var sutBuilder = new PaymentServiceSutBuilder(); var expectedPayment = sutBuilder.SetupFromTestData(testData); var paymentService = sutBuilder.CreateSut(); //Act var resultPayment = await paymentService.AddPaymentAsync(testData.NewPaymentData); //Assert resultPayment.ShouldBe(expectedPayment); }
public void AddPaymentAsync_WhenTryingToOverpay_ShouldThrowOverpay(PaymentServiceTestData testData) { //Arrange var sutBuilder = new PaymentServiceSutBuilder(); sutBuilder.SetupFromTestData(testData); var paymentService = sutBuilder.CreateSut(); //Act & Assert var exception = Assert.ThrowsAsync <BadRequestException>(async() => await paymentService.AddPaymentAsync(testData.NewPaymentData)); exception.Message.ShouldBe("Trying to pay back more than owned."); }
public void AddPaymentAsync_WhenReceiverOwesPayer_ShouldThrowAlreadyOwedMoney(PaymentServiceTestData testData) { //Arrange var sutBuilder = new PaymentServiceSutBuilder(); sutBuilder.SetupFromTestData(testData); var paymentService = sutBuilder.CreateSut(); //Act & Assert var exception = Assert.ThrowsAsync <BadRequestException>(async() => await paymentService.AddPaymentAsync(testData.NewPaymentData)); exception.Message.ShouldBe($"User {testData.Receiver.Email} already owes you money."); }
public void AddPaymentAsync_WhenNoPaymentsAreExpected_ShouldThrowNoPaymentsExpected(PaymentServiceTestData testData) { //Arrange var sutBuilder = new PaymentServiceSutBuilder(); sutBuilder.SetupFromTestData(testData); var paymentService = sutBuilder.CreateSut(); //Act & Assert var exception = Assert.ThrowsAsync <BadRequestException>(async() => await paymentService.AddPaymentAsync(testData.NewPaymentData)); exception.Message.ShouldBe("No payment expected."); }
public void GetExpectedPaymentsForUserAsync_WhenUserDoesNotExist_ShouldThrow() { //Arrange var sutBuilder = new PaymentServiceSutBuilder(); var testData = new PaymentServiceTestData(40) .AddReceiverLoanToPayer(50); sutBuilder.SetupFromTestData(testData, nullGroup: true); sutBuilder.SetupByIdUser(testData.Payer.Id, null); var paymentService = sutBuilder.CreateSut(); //Act & Assert var exception = Assert.ThrowsAsync <NotFoundException>(async() => await paymentService.GetExpectedPaymentsForUserAsync(testData.Payer.Id, null)); exception.Message.ShouldBe("User with given id does not exist."); }