예제 #1
0
        public void FuncSpec_WithCustomFunc()
        {
            using (var uow = CreateMemoryUoW(typeof(Author)))
            {
                const int numOfAuthorsA = 10, numOfAuthorsB = 12;
                var       authorAQrit = new EF.NameQriteria {
                    Name = "A."
                };
                var authorBQrit = new EF.NameQriteria {
                    Name = "B."
                };
                AddAuthors(uow, numOfAuthorsA, authorAQrit.Name);
                AddAuthors(uow, numOfAuthorsB, authorBQrit.Name);

                //Arrange
                var spec = LinqSpec <Author> .FilterFunc <EF.NameQriteria>(
                    (qrit) => author => author.Name.StartsWith(qrit.Name)
                    );

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

                //Assert
                Assert.AreEqual(numOfAuthorsB, actual.Count());
                Assert.IsTrue(actual.Any(a => a.Name.StartsWith(authorBQrit.Name)));
            }
        }