public void ForumAnonControllerGetMethod_GetAllCategories_ShouldReturnAllCategories() { //arrange Mock <IForumService> mockService = new Mock <IForumService>(); mockService.Setup(m => m.GetCategories()).Returns(new CategoryDTO[] { new CategoryDTO { ID = 1, Title = "First" }, new CategoryDTO { ID = 2, Title = "Second" }, new CategoryDTO { ID = 3, Title = "Third" }, new CategoryDTO { ID = 4, Title = "Fourth" }, }); var controller = new ForumAnonController(mockService.Object); //act var response = controller.Get() as OkNegotiatedContentResult <List <Categories> >; //assert Assert.AreEqual(4, response.Content.Count); Assert.AreEqual("First", response.Content[0].title); }
public void ForumAnonControllerGetPostWithCommentsMethod_GetNullPost_ShouldGiveNotFoundResult() { Mock <IForumService> mockService = new Mock <IForumService>(); mockService.Setup(m => m.GetPostById(1)).Equals(null); var controller = new ForumAnonController(mockService.Object); var response = controller.GetPostWithComments(1, 1); Assert.IsInstanceOfType(response, typeof(NotFoundResult)); }
public void ForumAnonControllerGetPostsMethod_GetAllNullPosts_ShouldGiveNotFoundResult() { Mock <IForumService> mockService = new Mock <IForumService>(); mockService.Setup(m => m.GetPosts(1)).Returns(new PostDTO[] { null, null }); var controller = new ForumAnonController(mockService.Object); var response = controller.GetPosts(1); Assert.IsInstanceOfType(response, typeof(NotFoundResult)); }
public void ForumAnonControllerGetPostsMethod_GetAllPosts_ShouldReturnAllPosts() { Mock <IForumService> mockService = new Mock <IForumService>(); mockService.Setup(m => m.GetPosts(1)).Returns(new PostDTO[] { new PostDTO { ID = 1, Title = "First" }, new PostDTO { ID = 2, Title = "Second" }, new PostDTO { ID = 3, Title = "Third" }, }); var controller = new ForumAnonController(mockService.Object); var response = controller.GetPosts(1) as OkNegotiatedContentResult <List <Posts> >; Assert.AreEqual(3, response.Content.Count); Assert.AreEqual("Second", response.Content[1].title); }
public void ForumAnonControllerGetPostWithCommentsMethod_GetPostWithComments_ShouldReturnPost() { Mock <IForumService> mockService = new Mock <IForumService>(); mockService.Setup(m => m.GetPostById(1)).Returns(new PostDTO { ID = 1, Title = "First" }); mockService.Setup(m => m.GetComments(1)).Returns(new CommentDTO[] { new CommentDTO { ID = 2, Body = "Hello1" }, new CommentDTO { ID = 3, Body = "Hello2" } }); var controller = new ForumAnonController(mockService.Object); var response = controller.GetPostWithComments(1, 1) as OkNegotiatedContentResult <WEB.Models.Post>; Assert.AreEqual(1, response.Content.id); Assert.AreEqual(2, response.Content.comments.ToList().Count); }