コード例 #1
0
		public void edit_get_should_redirect_with_invalid_page_id()
		{
			// Arrange

			// Act
			ActionResult result = _pagesController.Edit(1);

			// Assert
			Assert.That(result, Is.TypeOf<RedirectToRouteResult>(), "RedirectToRouteResult");
			RedirectToRouteResult redirectResult = result as RedirectToRouteResult;
			Assert.NotNull(redirectResult, "Null RedirectToRouteResult");

			Assert.That(redirectResult.RouteValues["action"], Is.EqualTo("New"));
		}
コード例 #2
0
        public void TestEditPageIsCalled()
        {
            // Arrange - create the mock repo and manager
            Page suprise = new Page()
            {
                Id = 1, Page_Name = "TheSurpriseModified", Title = "Hallo123", Content = "Test321"
            };

            var repo = new Mock <IPageRepository>();

            repo.Setup(x => x.GetPage(1)).Returns(suprise);
            repo.Setup(x => x.EditPage(1, suprise));

            var manager = new PageManager(repo.Object);

            // Arrange - create a controller
            PagesController target = new PagesController(manager);

            // Modify page
            suprise.Title = "Testing";

            // Action
            var model = (target.Edit(1) as ViewResult).ViewData.Model as PageViewModel;

            // Assert
            Assert.NotNull(model);
            Assert.Equal("Testing", model.Title);
        }
コード例 #3
0
        public void ShouldKnowHowToUpdateAPage()
        {
            var repository   = new Mock <Repository>();
            var existingPage = new StaticPage {
                Id = 1, Title = "Derping for dummies."
            };

            repository.Setup(repo => repo.Edit(existingPage));
            var pagesController = new PagesController(repository.Object);
            var result          = pagesController.Edit(new StaticPageInformation {
                Model = existingPage
            });

            Assert.AreEqual(existingPage.Id, result.RouteValues["id"]);
            repository.Verify(repo => repo.Edit(existingPage), Times.Once());
        }
コード例 #4
0
        public void ShouldKnowHowToRenderAnEditPage()
        {
            var repositoryMock = new Mock <Repository>();
            var page           = new StaticPage {
                Id = 1, Title = "The Page"
            };

            repositoryMock.Setup(repo => repo.Get <StaticPage>(page.Id)).Returns(page);
            var pagesController = new PagesController(repositoryMock.Object);

            var result      = pagesController.Edit(page.Id);
            var actualModel = (StaticPageInformation)result.Model;

            Assert.AreEqual(page.Title, actualModel.Model.Title);
            repositoryMock.Verify(repo => repo.Get <StaticPage>(1), Times.Once());
        }