Esempio n. 1
0
        public async Task GetFilteredPaymentsAsync_WhenFilterInfoPassed_ShouldCreateFilterAndReturnExpectedResult()
        {
            //Arrange
            var sutBuilder = new PaymentServiceSutBuilder();

            var filterInfo = new PaymentFilterInfo();

            var filter = A.Fake <PaymentDbFilter>();

            A.CallTo(() => sutBuilder.PaymentDbFilterFactory.Create(filterInfo))
            .Returns(filter);

            var expectedList = new List <Payment>();

            A.CallTo(() => sutBuilder.PaymentRepository.GetAllAsync(filter))
            .Returns(expectedList);

            var paymentService = sutBuilder.CreateSut();

            //Act
            var results = await paymentService.GetFilteredPaymentsAsync(filterInfo);

            //Assert
            results.ShouldBe(expectedList);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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.");
        }
Esempio n. 5
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.");
        }
Esempio n. 6
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.");
        }
Esempio n. 7
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.");
        }