Esempio n. 1
0
        public async Task FilterConsumablesAsync_ShouldReturn_CorrectQueryResult_DependingOnInput()
        {
            var db     = GetDatabase();
            var mapper = GetMapper();

            var firstMonthConsumable = new MonthlyPaymentConsumable
            {
                Id            = 1,
                RentAgreement = new RentAgreement
                {
                    Id       = 1,
                    ClientId = 1
                }
            };
            var secondMonthConsumable = new MonthlyPaymentConsumable
            {
                Id            = 2,
                RentAgreement = new RentAgreement
                {
                    Id       = 1,
                    ClientId = 1
                }
            };
            var thirdMonthConsumable = new MonthlyPaymentConsumable
            {
                Id            = 3,
                RentAgreement = new RentAgreement
                {
                    Id       = 2,
                    ClientId = 2
                }
            };
            var forthMonthConsumable = new MonthlyPaymentConsumable
            {
                Id            = 4,
                RentAgreement = new RentAgreement
                {
                    Id       = 1,
                    ClientId = 1
                }
            };
            await db.MonthlyPaymentConsumables.AddRangeAsync(firstMonthConsumable, secondMonthConsumable, thirdMonthConsumable, forthMonthConsumable);

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

            await db.SaveChangesAsync();

            var filterModel = new FilterConsumablesBindingModel
            {
                Client    = 1,
                OnlyCash  = true,
                StartDate = new DateTime(2017, 1, 1),
                EndDate   = new DateTime(2018, 12, 30)
            };
            var paymentService = new PaymentsService(mapper, db, null);
            //Act
            var result = await paymentService.FilterConsumablesAsync(filterModel);

            //Assert
            result
            .Should()
            .BeOfType <FilterConsumablesViewModel>()
            .And
            .Match <FilterConsumablesViewModel>(x => x.TotalIncome == 20 &&
                                                x.Payments.Any(y => y.PaidOn == new DateTime(2017, 11, 6)));
        }