示例#1
0
        public async void UpdateArticle_ValidArticle_Success()
        {
            var result = await ariclesController.SaveArticle(validArticleRequest);

            var okResult  = result.Should().BeOfType <OkObjectResult>().Subject;
            var articleId = okResult.Value.Should().BeAssignableTo <ArticleId>().Subject;

            var updatedArticleRequest = new ArticleBasicInfo()
            {
                Id         = articleId.Id,
                Abstract   = "Updated Abstract",
                Categories = new string[] { "1", "2" },
                Content    = "Updated Content",
                CoverImage = "Updated CoverImage",
                IsPrivate  = true,
                Title      = "Updated Title"
            };

            result = await ariclesController.SaveArticle(updatedArticleRequest);

            result.Should().BeOfType <OkObjectResult>();
            okResult = result.Should().BeOfType <OkObjectResult>().Subject;
            var articleIdResponse = okResult.Value.Should().BeAssignableTo <ArticleId>().Subject;

            result = await ariclesController.GetArticleDetails(articleIdResponse.Id);

            result.Should().BeOfType <OkObjectResult>();
            okResult = result.Should().BeOfType <OkObjectResult>().Subject;
            var articleResponse = okResult.Value.Should().BeAssignableTo <ArticleDetails>().Subject;


            articleResponse.Should().NotBeNull();
            articleResponse.Title.Should().Be(updatedArticleRequest.Title);
            articleResponse.Id.Should().Be(articleId.Id);  // Make sure the ID is the same old ID
            articleResponse.Abstract.Should().Be(updatedArticleRequest.Abstract);
            articleResponse.Content.Should().Be(updatedArticleRequest.Content);
            articleResponse.Author.Id.Should().Be(currentUserId);
            articleResponse.IsPrivate.Should().Be(updatedArticleRequest.IsPrivate);
            articleResponse.IsApproved.Should().Be(false);
            //articleDetailsResponse.Categories.Should().Be(validArticleRequest.Categories.Count);
            articleResponse.Content.Should().Be(updatedArticleRequest.Content);
            articleResponse.UpdatedOn.Should().BeCloseTo(DateTime.UtcNow, TWO_SECONDS_IN_MILLIONSECONDS);
            articleResponse.CreatedOn.Should().BeCloseTo(DateTime.UtcNow, TWO_SECONDS_IN_MILLIONSECONDS);
        }