public async Task CheckCreatePostNull_Test()
        {
            var fileMock = new Mock <IFormFile>();
            var mock     = new Mock <IPostService>();
            var ms       = new MemoryStream();
            var writer   = new StreamWriter(ms);
            var fileName = "i.jpg";

            writer.Write(fileName);
            writer.Flush();
            ms.Position = 0;
            fileMock.Setup(_ => _.OpenReadStream()).Returns(ms);
            fileMock.Setup(_ => _.Length).Returns(ms.Length);

            var createPostModel = new CreatePostModel
            {
                Title            = "Luxury interior in the design of apartments and houses",
                ShortDescription = "Designing premium interiors is a rejection of typical planning.",
                Image            = fileMock.Object
            };

            Post post = null;

            byte[] imageData = new byte[255];

            mock.Setup(repo => repo.CreatePost(createPostModel.Title, createPostModel.ShortDescription,
                                               createPostModel.Image.FileName, imageData)).Returns(async() => { return(post); });

            var createNewPostController = new CreatePostController(mock.Object);

            Exception ex = await Assert.ThrowsAsync <Exception>(() => createNewPostController.CreatePost(createPostModel));

            Assert.Equal("Post not created!", ex.Message);
        }
        public void CreatePostCheckReturnPost_Test()
        {
            var fileMock = new Mock <IFormFile>();

            var mock     = new Mock <IPostService>();
            var ms       = new MemoryStream();
            var writer   = new StreamWriter(ms);
            var fileName = "i.jpg";

            writer.Write(fileName);
            writer.Flush();
            ms.Position = 0;

            var createPostModel = new CreatePostModel
            {
                Title            = "Luxury interior in the design of apartments and houses",
                ShortDescription = "Designing premium interiors is a rejection of typical planning.",
                Image            = fileMock.Object
            };

            var postModel = new Post
            {
                Title            = "Luxury interior in the design of apartments and houses",
                ShortDescription = "Designing premium interiors is a rejection of typical planning.",
                ImageUrl         = "i.jpg"
            };

            fileMock.Setup(_ => _.FileName).Returns(fileName);
            fileMock.Setup(_ => _.OpenReadStream()).Returns(ms);
            fileMock.Setup(_ => _.Length).Returns(ms.Length);
            mock.Setup(repo => repo.CreatePost(postModel.Title, postModel.ShortDescription,
                                               postModel.ImageUrl, It.IsAny <byte[]>())).Returns(async() => { return(postModel); });

            var createNewPostController = new CreatePostController(mock.Object);

            var result = createNewPostController.CreatePost(createPostModel);

            Assert.IsType <Post>(result.Result);
        }