Exemplo n.º 1
0
        public async Task EFQueryAsyncTest()
        {
            int cntBook = 0;

            using (ILinqProvider linq = serviceLocator.GetInstance <ILinqProviderFactory>().Create())
            {
                var books = linq.Query <Book>().ToList();
                Assert.IsNotNull(books);
                cntBook = books.Count();
                Assert.IsTrue(cntBook > 0);
            }

            var allBooks = await handlerLocator
                           .For <IEnumerable <BookDto> >()
                           .AskAsync(new BookOrAuthorQriteria());

            var idQrit = new IdQriteria {
                Id = 2
            };
            var book = await handlerLocator
                       .For <BookDto>()
                       .AskAsync(idQrit);

            Assert.IsNotNull(allBooks);
            Assert.IsInstanceOfType(allBooks, typeof(IEnumerable <BookDto>));
            Assert.IsTrue(allBooks.Count() > 0);
            Assert.IsTrue(allBooks.Count() == cntBook);

            Assert.IsNotNull(book);
            Assert.IsInstanceOfType(book, typeof(BookDto));
            Assert.AreEqual(idQrit.Id, book.Id);
        }
Exemplo n.º 2
0
        public void ConventionsTest()
        {
            var idQrit = new IdQriteria {
                Id = 1
            };
            var authorConv     = Conventions <AuthorDto> .IdSpec;
            var authorPageConv = Conventions <AuthorDto> .PageSpec();

            Assert.ThrowsException <InvalidOperationException>(() => Conventions <PublisherDto> .IdSpec);
        }
Exemplo n.º 3
0
        public void Query_ByStringId_Returns_EntityWithId()
        {
            //Arrange
            var qrit = new IdQriteria <String> {
                Id = "PITER"
            };

            //Act
            var actual = handlerLocator
                         .For <PublisherDto>()
                         .Find(qrit);

            //Assert
            Assert.AreEqual(qrit.Id, actual.Id);
        }
Exemplo n.º 4
0
        public void Query_ById_Returns_EntityWithId()
        {
            //Arrange
            var qrit = new IdQriteria {
                Id = 2
            };

            //Act
            var actual = handlerLocator
                         .For <AuthorDto>()
                         .Find(qrit);

            //Assert
            Assert.AreEqual(qrit.Id, actual.Id);
        }
Exemplo n.º 5
0
        public void IdConvention_Returns_EntityWithId()
        {
            using (var uowStub = Stub.CreateMemoryUoW(typeof(Author)).AddAuthors(5))
            {
                var qrit = new IdQriteria <Int32> {
                    Id = 3
                };

                var e = new ConventionIdLinqSpec <Author>();
                //var e = ConventionFactory<AuthorDto>.IdSpec();
                var actual = e.Query(uowStub.Linq, qrit)
                             .Cast <Author>()
                             .Single();

                Assert.AreEqual(qrit.Id, actual.Id);
            }
        }
Exemplo n.º 6
0
        public void IdConventionExpression_Returns_EntityWithId()
        {
            using (var uowStub = Stub.CreateMemoryUoW(typeof(Author)))
            {
                uowStub.AddAuthors(5);
                var qrit = new IdQriteria <Int32> {
                    Id = 3
                };
                var expr = ConventionBuilder <Author>
                           .IdFilterExpression(qrit);

                var actual = uowStub.Linq.Query <Author>()
                             .Where(expr)
                             .Cast <Author>()
                             .Single();

                Assert.AreEqual(qrit.Id, actual.Id);
            }
        }
Exemplo n.º 7
0
        public void IdStringConventionExpression_Returns_EntityWithId()
        {
            using (var uow = Stub.CreateMemoryUoW(typeof(BookAuthor)))
            {
                uow.Add(new BookAuthor(new Book(1, "Book 1"), new Author(1, "Author 1")));
                uow.Add(new BookAuthor(new Book(2, "Book 2"), new Author(1, "Author 1")));
                uow.Add(new BookAuthor(new Book(3, "Book 2"), new Author(2, "Author 2")));

                var qrit = new IdQriteria <String> {
                    Id = "2-1"
                };
                var expr = ConventionBuilder <BookAuthor>
                           .IdFilterExpression(qrit);

                var actual = uow.Linq.Query <BookAuthor>().Where(expr)
                             .Cast <BookAuthor>()
                             .Single();

                Assert.AreEqual(qrit.Id, actual.Id);
            }
        }
Exemplo n.º 8
0
        public void ConventionIdLinqSpec_Returns_EntityWithId()
        {
            //Arrange
            const int numOfAuthors = 10;

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

                var spec = new ConventionIdLinqSpec <Author>();

                var qrit = new IdQriteria {
                    Id = 2
                };

                //Act
                var actual = spec.Query(uow.Linq, qrit);

                //Assert
                Assert.AreEqual(qrit.Id, actual.Cast <Author>().Single().Id);
            }
        }