public async void Details_IdIsNull_ReturnRedirectToIndexAction() { var result = await _controller.Details(null); var redirect = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Create", redirect.ActionName); }
public void Get_Blog_By_Id() { var data = new Initialize(); BlogsController controller = new BlogsController(data); ViewResult blog = controller.Details(data.Get().First().BlogId) as ViewResult; Assert.IsNotNull(blog); }
public void Product_NotFound_By_BlogId() { using (var context = new ApplicationDbContext(options)) { var dataProtectionProvider = new EphemeralDataProtectionProvider(); blogsController = new BlogsController(context, dataProtectionProvider, mockHttpContextAccessor.Object, mockEnvironment.Object); var resultTask = blogsController.Details(3); resultTask.Wait(); var response = resultTask.Result as NotFoundResult; Assert.AreEqual((int)HttpStatusCode.NotFound, response.StatusCode); } }
public void Details_By_BlogId() { using (var context = new ApplicationDbContext(options)) { var dataProtectionProvider = new EphemeralDataProtectionProvider(); blogsController = new BlogsController(context, dataProtectionProvider, mockHttpContextAccessor.Object, mockEnvironment.Object); var resultTask = blogsController.Details(1); resultTask.Wait(); Assert.IsNotNull(resultTask.Result); var model = (Blogs)((ViewResult)resultTask.Result).Model; Assert.AreEqual(1, model.BlogId); } }
public void Details() { // Arrange var controller = new BlogsController(_blogService); // Act var result = controller.Details(1).Result as ViewResult; var model = result.Model as Blog; // Assert Assert.IsNotNull(result); Assert.AreEqual("Blog 1", model.Name); }
public async Task DetailsBlogsController() { var context = GetInMemoryDbMetData(); var controller = new BlogsController(context, _hostingEnvironment); var result = await controller.Details(Blogs[1].Id); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <Blog>(viewResult.ViewData.Model); Assert.Equal("Summer 2018", model.Title); Assert.Equal("Summer is the hottest of the four temperate seasons, falling after spring and before autumn.", model.Content); Assert.Equal("In the summer the sun shines sometimes, but sometimes it doesn't", model.Subtitle); Assert.NotNull(viewResult); }