// GET: Blogs/Details/5 public IActionResult Details(Guid?id) { if (id == null) { return(NotFound()); } var blog = blogsService.GetBlogById(id.ToString()); if (blog == null) { return(NotFound()); } return(View(blog)); }
public void GetBlogById_ShouldThrowKeyNotFoundException_IfInvalidIdIsGiven() { Mapper.Initialize(x => x.AddProfile <MapperConfiguration>()); var repo = new Mock <IRepository <Blog> >(); var categories = GetTestData().AsQueryable(); repo.Setup(x => x.All()).Returns(categories); var service = new BlogsService(repo.Object); //do var expected = typeof(KeyNotFoundException); Type actual = null; try { var result = service.GetBlogById <BlogViewModel>(3); } catch (KeyNotFoundException e) { actual = e.GetType(); } //assert Assert.Equal(expected, actual); }
//// GET: Blogs/Details/5 public IActionResult Details(int id) { var blog = _service.GetBlogById(id); if (blog == null) { return(NotFound()); } return(View(blog)); }
public void GetBlogById_ShouldReturnTheViewModel_ForTheGivenId() { Mapper.Initialize(x => x.AddProfile <MapperConfiguration>()); var repo = new Mock <IRepository <Blog> >(); var categories = GetTestData().AsQueryable(); repo.Setup(x => x.All()).Returns(categories); var service = new BlogsService(repo.Object); //do var result = service.GetBlogById <BlogViewModel>(1); //assert result.Should().NotBeNull().And.BeOfType <BlogViewModel>(); }