public void ReturnFilteredSetOfBreweries(int expectedTotalCount) { // Arrange var pattern = this.Fixture.Create <string>(); var expectedFoundCount = expectedTotalCount / 5; var countryCount = expectedFoundCount / 2; var nameCount = countryCount; var breweries = new List <Brewery>(); for (var i = 0; i < expectedTotalCount - expectedFoundCount; i++) { breweries.Add(new Brewery() { Name = this.Fixture.Create <string>(), Country = this.Fixture.Create <string>() }); } for (int i = 0; i < countryCount; i++) { breweries.Add(new Brewery() { Name = this.Fixture.Create <string>(), Country = this.Fixture.Create <string>() + pattern + this.Fixture.Create <string>() }); } for (int i = 0; i < nameCount; i++) { breweries.Add(new Brewery() { Country = this.Fixture.Create <string>(), Name = this.Fixture.Create <string>() + pattern + this.Fixture.Create <string>() }); } var queryableBreweries = breweries.AsQueryable(); var repository = new Mock <IEfRepository <Brewery> >(); repository.Setup(r => r.All) .Returns(queryableBreweries); var beerRepo = new Mock <IEfRepository <Beer> >(); var service = new BreweryService(repository.Object, beerRepo.Object); // Act var result = service.Search(pattern); // Assert var actualBreweries = result as IBrewery[] ?? result.ToArray(); var actualCount = actualBreweries.Count(); Assert.GreaterOrEqual(expectedFoundCount, actualCount); foreach (var actualBrewery in actualBreweries) { Assert.IsTrue(actualBrewery.Name.Contains(pattern) || actualBrewery.Country.Contains(pattern)); } }