public void GetFreeTeamsWorksCorrectly(ServiceFrequency appointmentServiceFrequency, DateTime appointmentStartDate, DateTime appointmentEndDate, ServiceFrequency serviceFrequency, DateTime startDate, DateTime endDate, int expectedCount) { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var week = appointmentStartDate.GetWeekOfMonth(); var repositoryMock = new Mock <IDeletableEntityRepository <Team> >(); repositoryMock.Setup(x => x.All()) .Returns(new List <Team>() { new Team() { Id = "1", CityId = 1, Services = new List <TeamService>() { new TeamService() { TeamId = "1", ServiceId = 1, }, }, Orders = new List <Order>() { new Order() { Id = "1", ServiceFrequency = appointmentServiceFrequency, Status = OrderStatus.Pending, AppointmetnId = "1", TeamId = "1", Appointment = new Appointment() { Id = "1", OrderId = "1", DayOfWeek = (int)appointmentStartDate.DayOfWeek, StartDate = appointmentStartDate, EndDate = appointmentEndDate, WeekOfMonth = appointmentStartDate.GetWeekOfMonth(), }, }, }, TeamMembers = new List <ApplicationUser>() { new ApplicationUser() { Id = "1", TeamId = "1", }, }, }, }.AsQueryable()); var service = new TeamsService(repositoryMock.Object); var result = service.GetFreeTeams <TeamServiceModel>(startDate, endDate, 1, 1, serviceFrequency); Assert.Equal(expectedCount, result.Count()); }