public void FantasticBookSpec_ReturnsFantastic() { //Arrange //const int numOfBooks = 5; using (var uow = CreateMemoryUoW(new Type[] { typeof(Book), typeof(Author), typeof(Genre) })) { Genre genre = new Genre("жанр"); Genre genreFant = new Genre("фантастика"); Book book; book = new Book(1, "Book1"); book.Raiting = 1; book.AddGenre(genre); uow.Add(book); book = new Book(2, "Book2"); book.Raiting = 9; book.AddGenre(genreFant); uow.Add(book); book = new Book(3, "Book3"); book.Raiting = 1; book.AddGenre(genre); book.AddGenre(genreFant); uow.Add(book); book = new Book(4, "Book4"); book.Raiting = 6; book.AddGenre(genre); book.AddGenre(genreFant); uow.Add(book); book = new Book(5, "Book5"); book.Raiting = 1; book.AddGenre(genre); uow.Add(book); var qrit = new FantasticQrit { Popular = true }; var spec = new FantasticSpec(); ILinqSpec <FantasticQrit, Book> linqSpec = new ExpressionLinqSpec <Book, FantasticQrit>(spec); //IFilterSpec<FantasticQrit, Book> spec = new FantasticSpec(); //Act var actual = uow.Linq.Query <Book>().Apply(linqSpec, qrit); //Assert Assert.IsTrue(actual.Count() > 0); Assert.IsTrue(actual.All(b => Book.Rules.PopularBook.IsSatisfiedBy(b))); } }
public void FantasticSpec_Returns_Fantastic() { //Arrange var qrit = new FantasticQrit { Popular = true }; var spec = new FantasticSpec(); //Act //System.Diagnostics.Debug.WriteLine($"FantasticSpec:{spec.Expression(qrit)}"); var actual = books.AsQueryable().Where(spec.Expression(qrit)); //Assert Assert.IsTrue(actual.Count() > 0); Assert.IsTrue(actual.All(b => b.BookGenres.Any(g => Genre.FantasticGenresList.Any(fg => fg == g.Genre.Name))) ); Assert.IsTrue(actual.All(b => b.Raiting > 5)); }