public void ShouldDisplayOnlyDraftPagesCreatedByCurrentUserWhenListingDraftPages()
        {
            string userName = "******";

            UsingSession((session) =>
            {
                var repository = new Repository(session);
                var controller = new PagesController(repository);
                controller.Create(new StaticPageInformation()
                {
                    Model = new StaticPage { Id = 1, Title = "Draft Page", Content = "Hello\n=====\nWorld", IsDraft = true, Creator = userName}
                });
                controller.Create(new StaticPageInformation()
                {
                    Model = new StaticPage { Id = 2, Title = "Draft Page 2", Content = "Hello\n=====\nAnother World", IsDraft = true, Creator = userName}
                });
                controller.Create(new StaticPageInformation()
                {
                    Model = new StaticPage { Id = 3, Title = "Draft Page 3", Content = "Hello\n=====\nI'm a draft", IsDraft = true, Creator = "anotherUser" }
                });
            });

            UsingSession((session) =>
            {
                WaitForTheLastWrite<StaticPage>(session);

                var httpContextStub = new Mock<HttpContextBase>
                {
                    DefaultValue = DefaultValue.Mock
                };
                var user = Mock.Get(httpContextStub.Object.User);
                user.Setup(u => u.Identity.Name).Returns(userName);

                var controller = new PagesController(new Repository(session));
                controller.ControllerContext = new ControllerContext(httpContextStub.Object, new RouteData(), controller);
                var result = controller.List(excludeDraft:false);
                var pages = (PagedList.IPagedList<StaticPageInformation>)result.Model;

                Assert.AreEqual(2, pages.Count);
            });
        }
        public void ShouldExcludeDraftPagesWhenListingAllPages()
        {
            UsingSession((session) =>
            {
                var repository = new Repository(session);
                var controller = new PagesController(repository);
                controller.Create(new StaticPageInformation()
                    {
                        Model = new StaticPage { Id = 1, Title = "test title", Content = "Hello\n=====\nWorld" }
                    });
                controller.Create(new StaticPageInformation()
                    {
                        Model = new StaticPage { Id = 2, Title = "test title2", Content = "Hello\n=====\nAnother World" }
                    });
                controller.Create(new StaticPageInformation()
                    {
                        Model = new StaticPage { Id = 3, Title = "Draft Page", Content = "Hello\n=====\nI'm a draft", IsDraft = true }
                    });
            });

            UsingSession((session) =>
            {
                WaitForTheLastWrite<StaticPage>(session);
                var controller = new PagesController(new Repository(session));
                var result = controller.List();
                var pages = (PagedList.IPagedList<StaticPageInformation>)result.Model;

                Assert.AreEqual(2, pages.Count);
            });
        }
 public void ShouldKnowHowToListAllPages()
 {
     var repository = new Mock<Repository>();
     var savedPages = new List<StaticPage>
     {
         new StaticPage { Id = 1, Title = "test title", Content = "Hello\n=====\nWorld" },
         new StaticPage { Id = 2, Title = "test title2", Content = "Hello\n=====\nAnother World" }
     };
     var savedPageInformations = new List<StaticPageInformation>
     {
         new StaticPageInformation {Model = savedPages[0]},
         new StaticPageInformation {Model = savedPages[1]}
     };
     repository.Setup(repo => repo.Search<StaticPage>(It.IsAny<Expression<Func<StaticPage, bool>>>(), It.IsAny<int>(), It.IsAny<int>())).Returns(savedPages);
     repository.Setup(repo => repo.Search<StaticPage>(It.IsAny<Expression<Func<StaticPage, bool>>>())).Returns(savedPages);
     var controller = new PagesController(repository.Object);
     var result = controller.List();
     repository.Verify(it => it.Search<StaticPage>(It.IsAny<Expression<Func<StaticPage, bool>>>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once());
     Assert.AreEqual(savedPageInformations[0].Model, ((PagedList.IPagedList<StaticPageInformation>)result.Model)[0].Model);
     Assert.AreEqual(savedPageInformations[1].Model, ((PagedList.IPagedList<StaticPageInformation>)result.Model)[1].Model);
 }