public async Task FilterRentsAsync_ShouldReturn_CorrectQueryResult_DependingOnInput() { var db = GetDatabase(); var mapper = GetMapper(); var firstMonthConsumable = new MonthlyPaymentRent { Id = 1, RentAgreement = new RentAgreement { Id = 1, ClientId = 1 } }; var secondMonthConsumable = new MonthlyPaymentRent { Id = 2, RentAgreement = new RentAgreement { Id = 1, ClientId = 1 } }; var thirdMonthConsumable = new MonthlyPaymentRent { Id = 3, RentAgreement = new RentAgreement { Id = 2, ClientId = 2 } }; var forthMonthConsumable = new MonthlyPaymentRent { Id = 4, RentAgreement = new RentAgreement { Id = 1, ClientId = 1 } }; await db.MonthlyPaymentRents.AddRangeAsync(firstMonthConsumable, secondMonthConsumable, thirdMonthConsumable, forthMonthConsumable); var firstPayment = new Payment { Id = 1, PaidOn = new DateTime(2018, 12, 12), Amount = 10, CashPayment = false, MonthlyPaymentRentId = 1, }; var secndPayment = new Payment { Id = 2, PaidOn = new DateTime(2017, 11, 6), Amount = 20, CashPayment = true, MonthlyPaymentRentId = 2, }; var thirdPayment = new Payment { Id = 3, PaidOn = new DateTime(2015, 11, 12), Amount = 30, CashPayment = false, MonthlyPaymentRentId = 3 }; var forthPayment = new Payment { Id = 4, PaidOn = new DateTime(2015, 12, 15), Amount = 40, CashPayment = false, MonthlyPaymentRentId = 4 }; var fifthPayment = new Payment { Id = 5, PaidOn = new DateTime(2017, 12, 15), Amount = 50, MonthlyPaymentRentId = null, CashPayment = false }; await db.Payments.AddRangeAsync(firstPayment, secndPayment, thirdPayment, forthPayment, fifthPayment); await db.SaveChangesAsync(); var filterModel = new FilterRentBindingModel { 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.FilterRentsAsync(filterModel); //Assert result .Should() .BeOfType <FilterRentsViewModel>() .And .Match <FilterRentsViewModel>(x => x.TotalIncome == 20 && x.Payments.Any(y => y.PaidOn == new DateTime(2017, 11, 6))); }