Exemplo n.º 1
0
        public async Task DeleteBlogPostShouldTurnItToIsDeleted()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var dbContext = new ApplicationDbContext(options);

            var blogPostRepository = new EfDeletableEntityRepository <BlogPost>(dbContext);

            var service = new BlogPostService(blogPostRepository);

            await blogPostRepository.AddAsync(new BlogPost
            {
                Id        = "blogPostId",
                ImageName = "imageName",
                Text      = "text",
                CreatedOn = DateTime.UtcNow,
                UserId    = "userId",
            });

            await blogPostRepository.SaveChangesAsync();

            await service.DeleteBlogPost("blogPostId");

            Assert.True(dbContext.BlogPosts.FindAsync("blogPostId").Result.IsDeleted);
        }
Exemplo n.º 2
0
 public IActionResult Delete(int id)
 {
     if (_blogPostService.DeleteBlogPost(id))
     {
         return(Ok());
     }
     else
     {
         return(BadRequest());
     }
 }
Exemplo n.º 3
0
        public void ShouldDeleteBlogPost()
        {
            Mock <IAuthorRepository>   authorRepositoryMock   = new Mock <IAuthorRepository>();
            Mock <IBlogPostRepository> blogPostRepositoryMock = new Mock <IBlogPostRepository>();

            blogPostRepositoryMock.Setup(x => x.GetByUserIdAndId(It.IsAny <string>(), It.IsAny <string>())).Returns(new BlogPost());
            var mapper = TestHelper.GetMapper();
            var sut    = new BlogPostService(authorRepositoryMock.Object, blogPostRepositoryMock.Object, mapper);

            sut.DeleteBlogPost("12345", "5b9d8e952e6adf8005dbcf17");
        }
        public IActionResult DeleteBlogPost(string id)
        {
            _blogPostService.DeleteBlogPost(id);

            return(Ok());
        }