Example #1
0
        public async Task BeginArticleForAuthor()
        {
            string penName      = "nicm";
            string articleTitle = "new article";

            var beginArticle = new Mock <IBeginArticle>();

            beginArticle.Setup(x => x.ExecuteAsync(penName, articleTitle))
            .ReturnsAsync(new ArticleDto(articleTitle, DateTimeOffset.Now, null))
            .Verifiable();

            var sut   = new BeginArticleController(beginArticle.Object);
            var input = new BeginArticleInput {
                PenName      = penName,
                ArticleTitle = articleTitle
            };

            // Act
            ActionResult <IArticle?> response = await sut.ExecuteAsync(input);

            // Assert
            var model = Assert.IsType <OkObjectResult>(response.Result);

            Assert.IsAssignableFrom <IArticle>(model.Value);
        }
Example #2
0
        public async Task NotBeginArticleForAuthor()
        {
            string penName      = "nicm";
            string articleTitle = "new article";

            var beginArticle = new Mock <IBeginArticle>();

            beginArticle.Setup(x => x.ExecuteAsync(penName, articleTitle))
            .ReturnsAsync((IArticle)null !)
            .Verifiable();

            var sut   = new BeginArticleController(beginArticle.Object);
            var input = new BeginArticleInput {
                PenName      = penName,
                ArticleTitle = articleTitle
            };

            // Act
            ActionResult <IArticle?> response = await sut.ExecuteAsync(input);

            Assert.IsType <BadRequestResult>(response.Result);
            Assert.Null(response.Value);
        }