public void GetByQuery_WhenTitleIsSupplied_FiltersByTitle() { //arrange var options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: "GetByQueryTitleSupplied") .Options; using (var context = new ApplicationContext(options)) { var service = new CarAdvertService(context); var items = GetTestCarAdverts().ToList(); items.ForEach(carAdvert => service.Add(carAdvert)); context.SaveChanges(); } var query = new CarAdvertQueryModel { Title = "Used Toyota Matrix" }; //act & Assert using (var context = new ApplicationContext(options)) { var service = new CarAdvertService(context); var allCarAdverts = service.GetByQuery(query).ToList(); Assert.Single(allCarAdverts); } }
public void GetByQuery_WhenQueryIsEmpty_ReturnsAllItems() { //arrange var options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: "GetByQuery") .Options; using (var context = new ApplicationContext(options)) { var service = new CarAdvertService(context); var items = GetTestCarAdverts().ToList(); items.ForEach(carAdvert => service.Add(carAdvert)); context.SaveChanges(); } //act & Assert using (var context = new ApplicationContext(options)) { var service = new CarAdvertService(context); var allCarAdverts = service.GetByQuery(new CarAdvertQueryModel()).ToList(); Assert.Equal(5, allCarAdverts.Count); } }