-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MakeDraftCommandHandlerTests tests
- Loading branch information
1 parent
d83a3de
commit b41b332
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
tests/Blogger.IntegrationTests/Articles/MakeDraftCommandHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Blogger.Application.Articles.GetTags; | ||
using Blogger.Application.Articles.MakeDraft; | ||
using Blogger.Domain.ArticleAggregate; | ||
using Blogger.Infrastructure.Persistence.Repositories; | ||
using Blogger.IntegrationTests.Fixtures; | ||
|
||
using FluentAssertions; | ||
|
||
namespace Blogger.IntegrationTests.Articles; | ||
public class MakeDraftCommandHandlerTests : IClassFixture<BloggerDbContextFixture> | ||
{ | ||
private readonly BloggerDbContextFixture _fixture; | ||
|
||
public MakeDraftCommandHandlerTests(BloggerDbContextFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task Handle_ShouldCreateDraft_WhenDraftDoesNotExist() | ||
{ | ||
// Arrange | ||
var request = new MakeDraftCommand("Existing Draft", "Draft body", "Draft summary", []); | ||
var articleRepository = new ArticleRepository(_fixture.BuildDbContext(Guid.NewGuid().ToString())); | ||
var sut = new MakeDraftCommandHandler(articleRepository); | ||
|
||
// Act | ||
var response = await sut.Handle(request, CancellationToken.None); | ||
|
||
// Assert | ||
response.Should().NotBeNull(); | ||
response.DraftId.Should().Be(ArticleId.CreateUniqueId(request.Title)); | ||
} | ||
|
||
[Fact] | ||
public async Task Handle_ShouldThrowDraftAlreadyExistsException_WhenDraftAlreadyExists() | ||
{ | ||
// Arrange | ||
var request = new MakeDraftCommand("Existing Draft", "Draft body", "Draft summary", []); | ||
var articleRepository = new ArticleRepository(_fixture.BuildDbContext(Guid.NewGuid().ToString())); | ||
var sut = new MakeDraftCommandHandler(articleRepository); | ||
|
||
var oldDraft = Article.CreateDraft("Existing Draft", "Draft body", "Draft summary"); | ||
|
||
articleRepository.Add(oldDraft); | ||
await articleRepository.SaveChangesAsync(CancellationToken.None); | ||
|
||
// Act | ||
var draft = async () => await sut.Handle(request, CancellationToken.None); | ||
|
||
// Assert | ||
await draft.Should().ThrowAsync<DraftAlreadyExistsException>(); | ||
} | ||
} |