예제 #1
0
        public async Task AllRentPaymentsAsync_ShouldReturn_AllRentsThatAreNotPaid_IfSuchExist()
        {
            var db     = GetDatabase();
            var mapper = GetMapper();

            var firstPayment = new Payment
            {
                Id     = 1,
                PaidOn = new DateTime(2018, 12, 12),
                Amount = 10,
                MonthlyPaymentRentId = 1,
                CashPayment          = false
            };
            var secndPayment = new Payment
            {
                Id     = 2,
                PaidOn = new DateTime(2017, 11, 6),
                Amount = 20,
                MonthlyPaymentRentId = 2,
                CashPayment          = true
            };
            var thirdPayment = new Payment
            {
                Id     = 3,
                PaidOn = new DateTime(2016, 11, 12),
                Amount = 30,
                MonthlyPaymentRentId = 1,
                CashPayment          = false
            };
            var forthPayment = new Payment
            {
                Id     = 4,
                PaidOn = new DateTime(2015, 12, 15),
                Amount = 40,
                MonthlyPaymentRentId = 3,
                CashPayment          = false
            };
            var fifthPayment = new Payment
            {
                Id     = 5,
                PaidOn = new DateTime(2019, 12, 15),
                Amount = 50,
                MonthlyPaymentRentId = null,
                CashPayment          = false
            };
            await db.Payments.AddRangeAsync(firstPayment, secndPayment, thirdPayment, forthPayment, fifthPayment);

            await db.SaveChangesAsync();

            var paymentService = new PaymentsService(mapper, db, null);
            //Act
            var result = await paymentService.AllRentPaymentsAsync();

            //Assert
            result
            .Should()
            .BeOfType <List <PaymentRentListingModel> >()
            .And
            .HaveCount(4)
            .And
            .Match(x => x.ElementAt(0).Amount == 10 &&
                   x.ElementAt(1).Amount == 20 &&
                   x.ElementAt(2).CashPayment == false);
        }