Beispiel #1
0
        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)));
            }
        }
Beispiel #2
0
        public void ExpressionSpec_Default_ReturnsAll()
        {
            //Arrange
            const int numOfAuthors = 5;

            using (var uow = CreateMemoryUoW(typeof(Author)))
            {
                AddAuthors(uow, numOfAuthors);

                ILinqSpec <NameQriteria, Author> spec = new ExpressionLinqSpec <Author, NameQriteria>();

                //Act
                var actual = spec.Query(uow.Linq.Query <Author>(), null);

                //Assert
                Assert.AreEqual(numOfAuthors, actual.Count());
            }
        }