예제 #1
0
        public ActionResult Single(PageUrlViewModel urlModel)
        {
            var page = repository.SinglePage(urlModel.UrlTitle);

            if (page == null) return HttpNotFound();

            var model = mapper.Map<PageViewModel>(page);

            return View(model);
        }
예제 #2
0
        public void NonExistentPageUrlReturns404()
        {
            var badUrl = new PageUrlViewModel { UrlTitle = "doesnt-exist" };

            Mock.Get(repository)
                .Setup(r => r.SinglePage(It.IsAny<string>()))
                .Returns((Page)null);

            var result = controller.Single(badUrl);

            Mock.Get(repository).Verify(r => r.SinglePage(badUrl.UrlTitle));
            Assert.That(result, Is.InstanceOf<HttpNotFoundResult>());
        }
예제 #3
0
        public void GetReturnsCorrectPageFromRepository()
        {
            var urlModel = new PageUrlViewModel();
            var page = new Page();
            var expectedModel = new PageViewModel();

            Mock.Get(repository).Setup(r => r.SinglePage(It.IsAny<string>())).Returns(page);
            Mock.Get(mapper).Setup(m => m.Map<PageViewModel>(page)).Returns(expectedModel);

            var result = controller.Single(urlModel) as ViewResult;

            Assert.IsNotNull(result);
            Assert.That(result.Model, Is.EqualTo(expectedModel));
            Mock.Get(repository).Verify(r => r.SinglePage(urlModel.UrlTitle));
        }