-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for dispatching events with a non-int id
- Loading branch information
demidov-ad
committed
Mar 12, 2024
1 parent
8cc6556
commit 931403a
Showing
3 changed files
with
51 additions
and
0 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
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
36 changes: 36 additions & 0 deletions
36
...redKernel.UnitTests/MediatRDomainEventDispatcherTests/DispatchAndClearEventsWithGuidId.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,36 @@ | ||
using FluentAssertions; | ||
using MediatR; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Ardalis.SharedKernel.UnitTests.MediatRDomainEventDispatcherTests; | ||
|
||
public class DispatchAndClearEventsWithGuidId | ||
{ | ||
private class TestDomainEvent : DomainEventBase { } | ||
private class TestEntity : EntityBase<Guid> | ||
{ | ||
public void AddTestDomainEvent() | ||
{ | ||
var domainEvent = new TestDomainEvent(); | ||
RegisterDomainEvent(domainEvent); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async void CallsPublishAndClearDomainEvents() | ||
{ | ||
// Arrange | ||
var mediatorMock = new Mock<IMediator>(); | ||
var domainEventDispatcher = new MediatRDomainEventDispatcher(mediatorMock.Object); | ||
var entity = new TestEntity(); | ||
entity.AddTestDomainEvent(); | ||
|
||
// Act | ||
await domainEventDispatcher.DispatchAndClearEvents(new List<EntityBase<Guid>> { entity }); | ||
|
||
// Assert | ||
mediatorMock.Verify(m => m.Publish(It.IsAny<DomainEventBase>(), It.IsAny<CancellationToken>()), Times.Once); | ||
entity.DomainEvents.Should().BeEmpty(); | ||
} | ||
} |