public async Task GetAllHavingCitiesWorksCorrectlyForCitiesWithService() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var addressesServiceMock = new Mock <IAddressesService>(); var citiesRepository = new EfDeletableEntityRepository <City>(dbContext); var repository = new EfDeletableEntityRepository <Country>(dbContext); var citiesServiceMock = new Mock <CitiesService>(citiesRepository, addressesServiceMock.Object); var service = new CountriesService(repository, citiesServiceMock.Object); var country1 = new Country() { Id = 1, }; var country2 = new Country() { Id = 2, Cities = new List <City>() { new City() { Teams = new List <Team>() { new Team() { Services = new List <TeamService>() { new TeamService(), }, }, }, }, }, }; var country3 = new Country() { Id = 3, }; dbContext.Add(country1); dbContext.Add(country2); dbContext.Add(country3); await dbContext.SaveChangesAsync(); var result = service.GetAllHavingCities(true); Assert.Single(result); }