コード例 #1
0
        public async Task DetailNoFoundTest()
        {
            var mockSvc = new Mock <IArticleService>();

            mockSvc
            .Setup(s => s.GetArticleDetailDtoAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(default(ArticleDetailDto)));
            using var controller = new ArticleController(mockSvc.Object, null);
            var result = (await controller.Detail(1)) as NotFoundResult;

            Assert.AreEqual(404, result.StatusCode);
        }
コード例 #2
0
        public async Task DetailTest()
        {
            var mockSvc = new Mock <IArticleService>();

            mockSvc
            .Setup(s => s.GetEnabledArticleDetailDtoAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(new ArticleDetailDto
            {
                Title      = "article 1",
                CategoryId = ArticleCategory.Net,
                Content    = "**Content**"
            }));
            using var controller = new ArticleController(mockSvc.Object, null);
            var result = (await controller.Detail(It.IsAny <int>())) as ViewResult;
            var dto    = result.Model as ArticleDetailDto;

            Assert.AreEqual("article 1", dto.Title);
            Assert.AreEqual(ArticleCategory.Net, dto.CategoryId);
            Assert.IsTrue(dto.Content.StartsWith("<p><strong>Content</strong></p>"));
            mockSvc.Verify(m => m.GetEnabledArticleDetailDtoAsync(It.IsAny <int>()), Times.Once());
        }