Skip to content

Commit

Permalink
Add test case for getArticles
Browse files Browse the repository at this point in the history
  • Loading branch information
Nabi Karampour authored and Nabi Karampour committed Jun 17, 2024
1 parent 7fa659d commit 688f55d
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,39 @@ public async Task Handle_ShouldReturnArticles_WhenArticlesExist()
secondArticleResponse.Tags.Should().BeEquivalentTo(article_1.Tags);
}

[Fact]
public async Task Handle_ShouldReturnArticlesWithTitle_WhenWhenPassTitle()
{
// Arrange
var articleRepository = new ArticleRepository(_fixture.BuildDbContext(Guid.NewGuid().ToString()));
var _sut = new GetArticlesQueryHandler(articleRepository);


var article_1 = Article.CreateArticle("Title 1", "Test Body", "Test Summary", [Tag.Create("tag1"), Tag.Create("tag2")]);
var article_2 = Article.CreateArticle("Title 2", "Test Body", "Test Summary", [Tag.Create("tag1"), Tag.Create("tag2")]);

articleRepository.Add(article_1);
articleRepository.Add(article_2);
await articleRepository.SaveChangesAsync(CancellationToken.None);

var request = new GetArticlesQuery { PageNumber = 1, PageSize = 10, Title= "Title 1" };

// Act
var response = await _sut.Handle(request, CancellationToken.None);

// Assert
response.Should().NotBeNull();
response.Should().HaveCount(1);

var secondArticleResponse = response.First();
secondArticleResponse.ArticleId.Should().Be(article_1.Id);
secondArticleResponse.Title.Should().Be(article_1.Title);
secondArticleResponse.Summary.Should().Be(article_1.Summary);
secondArticleResponse.PublishedOnUtc.Should().Be(article_1.PublishedOnUtc);
secondArticleResponse.ReadOnMinutes.Should().Be(article_1.GetReadOnInMinutes);
secondArticleResponse.Tags.Should().BeEquivalentTo(article_1.Tags);
}

[Fact]
public async Task Handle_ShouldReturnEmpty_WhenNoArticlesExist()
{
Expand Down

0 comments on commit 688f55d

Please sign in to comment.