Exemplo n.º 1
0
 public ActionResult <bool> DeleteArticle(string articleId)
 {
     if (string.IsNullOrEmpty(articleId))
     {
         return(NotFound());
     }
     _articlesService.DeleteArticle(articleId);
     return(true);
 }
Exemplo n.º 2
0
        public void DeleteArticle_ReceivesDeleteArticleRequest_ExpectsEmptyReply()
        {
            var username  = "******";
            var title     = "My Article 1";
            var content   = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
            var thumbnail = new byte[] { 72, 101, 108, 108, 111 };

            var article = new Article(
                username,
                title,
                content,
                thumbnail);

            var mockArticlesRepo = new Mock <IArticlesRepository>();

            mockArticlesRepo.Setup(x => x.DeleteAsync(3)).ReturnsAsync(true);

            var mockCommentsRepo = new Mock <ICommentsRepository>();

            var mockLogger = new Mock <ILogger <ArticlesService> >();

            var mockValidationFactory = new Mock <IValidatorFactory>();

            mockValidationFactory.Setup(x =>
                                        x.GetValidator <AddCommentRequest>()).Returns(new AddCommentRequestValidator());

            var mockContext = GetServerCallContext("DeleteArticle");

            var service = new ArticlesService(
                mockLogger.Object,
                mockArticlesRepo.Object,
                mockCommentsRepo.Object,
                mockValidationFactory.Object);

            var result = service.DeleteArticle(new DeleteArticleRequest {
                ArticleId = 3
            }, mockContext).Result;

            Assert.IsType <EmptyReply>(result);
        }