public void Can_Get_Posts_First_Page_By_Author_Name()
        {
            var mockServiceLocator = new Mock<IServiceLocator>();

            mockServiceLocator
                .Setup(c => c.GetInstance<IPagedPostSearch>())
                .Returns(new PagedPostSearch(SessionFactory))
                .Verifiable();

            IServiceLocator serviceLocator = mockServiceLocator.Object;

            var repository = new NHibernateRepository<Post>(SessionFactory, new QueryFactory(serviceLocator));

            LoadPosts(repository);

            var query = repository.CreateQuery<IPagedPostSearch>();
            query.ItemsPerPage = 5;
            query.PageNumber = 1;
            query.AuthorName = "Renata Fan";

            PagedResult<Post> posts = query.Execute();

            Assert.AreEqual(5, posts.TotalItems);
            Assert.AreEqual(5, posts.PageOfResults.Count());

            mockServiceLocator.VerifyAll();
        }
        public void Can_Search_By_Post_Title()
        {
            var mockServiceLocator = new Mock<IServiceLocator>();

            mockServiceLocator
                .Setup(c => c.GetInstance<IAdvancedPostSearch>())
                .Returns(new AdvancedPostSearch(SessionFactory))
                .Verifiable();

            IServiceLocator serviceLocator = mockServiceLocator.Object;

            var repository = new NHibernateRepository<Post>(SessionFactory, new QueryFactory(serviceLocator));

            LoadPosts(repository);

            var query = repository.CreateQuery<IAdvancedPostSearch>();
            query.Title = "Title1";

            IEnumerable<Post> posts = query.Execute();

            Assert.AreEqual(1, posts.Count());

            mockServiceLocator.VerifyAll();
        }
        public void Can_Search_Posts_By_All_Filters()
        {
            var mockServiceLocator = new Mock<IServiceLocator>();

            mockServiceLocator
                .Setup(c => c.GetInstance<IAdvancedPostSearch>())
                .Returns(new AdvancedPostSearch(SessionFactory))
                .Verifiable();

            IServiceLocator serviceLocator = mockServiceLocator.Object;

            var repository = new NHibernateRepository<Post>(SessionFactory, new QueryFactory(serviceLocator));

            LoadPosts(repository);

            var query = repository.CreateQuery<IAdvancedPostSearch>();
            query.AuthorName = "Flavia Alessandra";
            query.Title = "Title9";
            query.CreatedBetween = new Period(DateTime.Today.AddDays(-1), DateTime.Today.AddDays(1));

            IEnumerable<Post> posts = query.Execute();

            Assert.AreEqual(1, posts.Count());

            mockServiceLocator.VerifyAll();
        }
        public void Can_Search_Posts_Create_Between_Yesterday_And_Tomorrow()
        {
            var mockServiceLocator = new Mock<IServiceLocator>();

            mockServiceLocator
                .Setup(c => c.GetInstance<IAdvancedPostSearch>())
                .Returns(new AdvancedPostSearch(SessionFactory))
                .Verifiable();

            IServiceLocator serviceLocator = mockServiceLocator.Object;

            var repository = new NHibernateRepository<Post>(SessionFactory, new QueryFactory(serviceLocator));

            LoadPosts(repository);

            var query = repository.CreateQuery<IAdvancedPostSearch>();
            query.CreatedBetween = new Period(DateTime.Today.AddDays(-1), DateTime.Today.AddDays(1));

            IEnumerable<Post> posts = query.Execute();

            Assert.AreEqual(10, posts.Count());

            mockServiceLocator.VerifyAll();
        }