-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51d89d0
commit 92041c5
Showing
2 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
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
66 changes: 66 additions & 0 deletions
66
tests/Blogger.IntegrationTests/Subscribers/SubscribeCommandHandlerTests.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,66 @@ | ||
using Blogger.Application.Subscribers; | ||
using Blogger.Application.Subscribers.Subscribe; | ||
using Blogger.Domain.SubscriberAggregate; | ||
using Blogger.Infrastructure.Persistence.Repositories; | ||
using Blogger.IntegrationTests.Fixtures; | ||
|
||
using FluentAssertions; | ||
|
||
namespace Blogger.IntegrationTests.Subscribers; | ||
public class SubscribeCommandHandlerTests : IClassFixture<BloggerDbContextFixture> | ||
{ | ||
private readonly BloggerDbContextFixture _fixture; | ||
|
||
public SubscribeCommandHandlerTests(BloggerDbContextFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task Handle_DuplicateSubscriber_ShouldThrowDuplicateSubscriptionException() | ||
{ | ||
// Arrange | ||
var dbContext = _fixture.BuildDbContext(Guid.NewGuid().ToString()); | ||
var subscribeRepository = new SubscriberRepository(dbContext); | ||
|
||
var subscriberId = SubscriberId.CreateUniqueId("[email protected]"); | ||
var subscriber = Subscriber.Create(subscriberId); | ||
await subscribeRepository.CreateAsync(subscriber, CancellationToken.None); | ||
await subscribeRepository.SavaChangesAsync(CancellationToken.None); | ||
|
||
var subscriberService = new SubscriberService(subscribeRepository); | ||
|
||
var sut = new SubscribeCommandHandler(subscribeRepository, subscriberService); | ||
|
||
var command = new SubscribeCommand(subscriberId); | ||
|
||
// Act | ||
Func<Task> act = async () => await sut.Handle(command, CancellationToken.None); | ||
|
||
// Assert | ||
await act.Should().ThrowAsync<DuplicateSubscribtionException>(); | ||
} | ||
|
||
[Fact] | ||
public async Task Handle_NewSubscriber_ShouldCreateSubscriberAndSaveChanges() | ||
{ | ||
// Arrange | ||
var dbContext = _fixture.BuildDbContext(Guid.NewGuid().ToString()); | ||
var subscribeRepository = new SubscriberRepository(dbContext); | ||
|
||
var subscriberId = SubscriberId.CreateUniqueId("[email protected]"); | ||
|
||
var subscriberService = new SubscriberService(subscribeRepository); | ||
|
||
var sut = new SubscribeCommandHandler(subscribeRepository, subscriberService); | ||
|
||
var command = new SubscribeCommand(subscriberId); | ||
|
||
// Act | ||
await sut.Handle(command, CancellationToken.None); | ||
|
||
// Assert | ||
var subscriber = await subscribeRepository.FindByIdAsync(subscriberId); | ||
subscriber.Should().NotBeNull(); | ||
} | ||
} |