コード例 #1
0
        public void ShouldDisplayOnlyDraftNewsCreatedByCurrentUserWhenListingDraftNews()
        {
            string userName = "******";

            UsingSession((session) =>
            {
                var repository = new Repository(session);
                var post = new Post { Id = 1, Title = "Post 1", Content = "A Post", UpdatedAt = DateTime.Now.AddMinutes(-1), IsDraft = true, Creator = userName };
                repository.Create(post);
                post = new Post { Id = 2, Title = "Post 2", Content = "A Post", UpdatedAt = DateTime.Now.AddMinutes(-1), IsDraft = true, Creator = userName };
                repository.Create(post);
                post = new Post { Id = 3, Title = "Post 3", Content = "A Post", UpdatedAt = DateTime.Now.AddMinutes(-1), IsDraft = true, Creator = "anotherUser" };
                repository.Create(post);
                var controller = new PostsController(repository);
            });

            UsingSession((session) =>
            {
                WaitForTheLastWrite<Post>(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 PostsController(new Repository(session));
                controller.ControllerContext = new ControllerContext(httpContextStub.Object, new RouteData(), controller);
                var result = (ViewResult)controller.News(excludeDraft: false);
                var pages = (PagedList.IPagedList<IBasePostInformation>)result.Model;

                Assert.AreEqual(2, pages.Count);
            });
        }
コード例 #2
0
        public void ShouldExcludeDraftPostsWhenListingAllPosts()
        {
            UsingSession((session) =>
            {
                var repository = new Repository(session);
                var post = new Post { Id = 1, Title = "Post 1", Content = "A Post", UpdatedAt = DateTime.Now.AddMinutes(-1) } ;
                repository.Create(post);
                post = new Post { Id = 2, Title = "Post 2", Content = "A Post", UpdatedAt = DateTime.Now.AddMinutes(-1) } ;
                repository.Create(post);
                post = new Post { Id = 3, Title = "Post 3", Content = "A Post", UpdatedAt = DateTime.Now.AddMinutes(-1), IsDraft = true} ;
                repository.Create(post);
                var controller = new PostsController(repository);
            });

            UsingSession((session) =>
            {
                WaitForTheLastWrite<Post>(session);
                var controller = new PostsController(new Repository(session));
                var result = (ViewResult)controller.News();
                var pages = (PagedList.IPagedList<IBasePostInformation>)result.Model;

                Assert.AreEqual(2, pages.Count);
            });
        }