public async Task ShouldMapArticleCorrectly(string slug, string title) { // arrange var rdm = new Random(); var expectedComment = new CommentDto { AuthorId = Guid.NewGuid(), Content = "This is a comment... NARF", DisplayName = "Commenty McCommentFace", Email = "*****@*****.**", Id = rdm.Next(1000, 1000000) }; var article = new ArticleReadingDto { Slug = slug, Topic = title, Version = rdm.Next(1, 10000), ViewCount = rdm.Next(1, 10000), Comments = new[] { expectedComment } }; _Mediator.Setup(m => m.Send(It.IsAny <GetArticleQuery>(), default(CancellationToken))).ReturnsAsync(article); // act var sut = new DetailsModel(_Mediator.Object, _Mapper); sut.AddPageContext("", Guid.Empty); await sut.OnGetAsync(article.Slug); // assert Assert.Equal(article.Slug, sut.Article.Slug); Assert.Equal(article.Topic, sut.Article.Topic); Assert.Equal(article.ViewCount + 1, sut.Article.ViewCount); Assert.Equal(article.Version, sut.Article.Version); Assert.Equal(article.Comments.Length, sut.Article.Comments.Count); var actualComment = sut.Article.Comments.FirstOrDefault(); Assert.NotNull(actualComment); Assert.Equal(expectedComment.Content, actualComment.Content); Assert.Equal(expectedComment.Email, actualComment.Email); Assert.Equal(expectedComment.DisplayName, actualComment.DisplayName); }
public async Task OnGet_WithValidSlug_ShouldReturnArticle() { var article = new Article { Topic = "test topic", Slug = "test-topic", Content = "test content" }; this.context.Articles.Add(article); await this.context.SaveChangesAsync(); this.mockMediator .Setup(m => m.Send(It.IsAny <GetArticleDetailsQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(article); var detaisModel = new DetailsModel(this.mockMediator.Object, null); detaisModel.AddPageContext("", Guid.Empty.ToString()); await detaisModel.OnGetAsync(article.Slug); Assert.Equal(article.Topic, detaisModel.Article.Topic); Assert.Equal(article.Slug, detaisModel.Article.Slug); }