public void View_WhenCalled_ReturnsOKResult() { //Given //Arrange /* * var postList = new List<Post> { * new Post {Id = 1, Title = "Post 1", Body = "Cuerpo del post 1", Autor = "Luis" }, * new Post {Id = 2, Title = "Post 2", Body = "Cuerpo del post 2", Autor = "Eduardo" }, * new Post {Id = 3, Title = "Post 3", Body = "Cuerpo del post 3", Autor = "Marcelo" } * }; */ var mockService = new Mock <IPostService>(); var fakePost = new Post { Id = 1, Title = "Post 1", Body = "Cuerpo del post 1", Autor = "Luis" }; mockService.Setup(serv => serv.GetById(1)).Returns(fakePost); BlogPosts post = new BlogPosts(mockService.Object); Post data = new Post { Id = 1 }; // When // Act var result = post.View(data.Id); // Then // Assert Assert.IsType <OkObjectResult>(result); }
public void View_WhenCalled_ReturnsOKResult_WhitFluentAssertions() { //Given //Arrange var mockService = new Mock <IPostService>(); var fakePost = new Post { Id = 1, Title = "Post 1", Body = "Cuerpo del post 1", Autor = "Luis" }; mockService.Setup(serv => serv.GetById(1)).Returns(fakePost); BlogPosts post = new BlogPosts(mockService.Object); // When // Act var result = (OkObjectResult)post.View(1); // Then // Assert result.Value.Should().BeEquivalentTo(fakePost); }