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); }
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>()); }
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)); }