Beispiel #1
0
        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.");
        }
Beispiel #2
0
        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.");
        }
Beispiel #3
0
            public Payment SetupFromTestData(PaymentServiceTestData testData, bool nullGroup = false)
            {
                SetupByIdUser(testData.Payer.Id, testData.Payer);
                SetupByIdUser(testData.Receiver.Id, testData.Receiver);
                SetupByGroupUser(testData.Group, nullGroup);

                SetupLoans(
                    testData.PayerLoansToReceiver,
                    loanerId: testData.Payer.Id,
                    loaneeId: testData.Receiver.Id,
                    nullGroup ? null : testData.Group.Id
                    );

                SetupLoans(
                    testData.ReceiverLoansToPayer,
                    loanerId: testData.Receiver.Id,
                    loaneeId: testData.Payer.Id,
                    nullGroup ? null : testData.Group.Id
                    );

                SetupPayments(
                    testData.PayerPaymentsToReceiver,
                    payerId: testData.Payer.Id,
                    receiverId: testData.Receiver.Id,
                    nullGroup ? null : testData.Group.Id
                    );

                SetupPayments(
                    testData.ReceiverPaymentsToPayer,
                    payerId: testData.Receiver.Id,
                    receiverId: testData.Payer.Id,
                    nullGroup ? null : testData.Group.Id
                    );

                return(SetupAddPayment(testData.NewPaymentData));
            }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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.");
        }
Beispiel #7
0
        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.");
        }