public void GetAllPosts() { ActionResult <ListResponse <Post> > result = blogController.GetPosts(null); Assert.IsInstanceOf <OkObjectResult>(result.Result); Assert.IsNotNull((result.Result as OkObjectResult).Value); }
public void GetPosts() { var home = new BlogController(); User user = new User("bob"); var startDate = new DateTime(2013, 1, 1); var endDate = new DateTime(2014, 1, 1); IEnumerable <Post> posts = home.GetPosts(user, startDate, endDate); Assert.AreEqual(2, posts.Count()); }
public void TestGetPosts() { // Arrange var dbContext = DbContextMocker.GetDbContext(nameof(TestGetPosts)); var controller = new BlogController(dbContext); // Act if (controller.GetPosts() is ObjectResult response) { // Assert that blog posts are exactly 1 Assert.True(response.Value is IList <PostModel> value && value.Count == 1); } dbContext.Dispose(); }