コード例 #1
0
        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);
            });
        }
コード例 #2
0
        public void ShouldDisplayFormForNewPage()
        {
            var repository = new Mock <Repository>();
            var controller = new PagesController(repository.Object);
            var result     = (ViewResult)controller.Create();

            Assert.AreEqual("Create", result.ViewName);
        }
コード例 #3
0
        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);
            });
        }
コード例 #4
0
        public void ShouldHandleDuplicatePageProblem()
        {
            var repository    = new Mock <Repository>();
            var duplicatePage = new StaticPage {
                Title = "test title", Content = "test content"
            };

            repository.Setup(repo => repo.Create(duplicatePage))
            .Throws(new Raven.Client.Exceptions.NonUniqueObjectException());

            var controller = new PagesController(repository.Object);

            controller.Create(new StaticPageInformation {
                Model = duplicatePage
            });

            Assert.AreEqual(string.Format("Sorry, page {0} already exists.", duplicatePage.Title), controller.TempData["flashError"]);
        }
コード例 #5
0
        public void ShouldStorePageWhenCreated()
        {
            var repository    = new Mock <Repository>();
            var submittedPage = new StaticPage {
                Title = "test title", Content = "some content"
            };

            repository.Setup(repo => repo.Create(submittedPage)).Returns(new StaticPage {
                Id = 1, Title = submittedPage.Title, Content = submittedPage.Content
            });
            var controller = new PagesController(repository.Object);
            var result     = (RedirectToRouteResult)controller.Create(new StaticPageInformation {
                Model = submittedPage
            });

            repository.Verify(it => it.Create(submittedPage), Times.Once());
            Assert.AreEqual(string.Format("Added {0}", submittedPage.Title), controller.TempData["flashSuccess"]);
            Assert.AreEqual(1, result.RouteValues["id"]);
        }