Exemplo n.º 1
0
        public async void Get_Blog_Mock_By_Id_Async()
        {
            var repositoryMock = new Mock <IBloggingRepository>();

            var blogMock = new Blog()
            {
                BlogId = 1,
                Name   = "Corbs Blog",
                Posts  = new List <Post>()
                {
                    new Post()
                    {
                        BlogId  = 1,
                        Content = "ipso facto",
                        PostId  = 1,
                        Title   = "Post for this blog"
                    }
                },
                Url = "test.com"
            };

            repositoryMock.Setup(x => x.GetBlogAsync(1)).ReturnsAsync(blogMock);

            var bloggingController = new BloggingController(repositoryMock.Object);
            var actualResponse     = await bloggingController.GetAsync(1);

            var expectedResponse = new ActionResult <Blog>(new OkObjectResult(blogMock));

            Assert.Equal(expectedResponse.Value, actualResponse.Value);
        }
Exemplo n.º 2
0
        public async void Delete_Blog_Mock_By_Id_Async()
        {
            var repositoryMock = new Mock <IBloggingRepository>();

            dynamic jsonResponseMock = new JObject();

            jsonResponseMock.message = "Blog with id 2 successfully deleted.";

            repositoryMock.Setup(x => x.DeleteBlogAsync(2)).ReturnsAsync(true);

            var bloggingController = new BloggingController(repositoryMock.Object);
            var response           = await bloggingController.DeleteAsync(2);

            var expectedResponse = new ActionResult <string>(new OkObjectResult(jsonResponseMock));

            Assert.Equal(expectedResponse.Value, response.Value);
        }