Example #1
0
        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));
        }
Example #2
0
        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);
        }