0
0
mirror of https://github.com/alex289/CleanArchitecture.git synced 2025-07-01 11:02:57 +00:00
CleanArchitecture/CleanArchitecture.Infrastructure.Tests/InMemoryBusTests.cs
Alexander Konietzko 53e0966f51
Add event sourcing
2023-07-01 16:46:08 +02:00

64 lines
2.0 KiB
C#

using System;
using System.Threading;
using System.Threading.Tasks;
using CleanArchitecture.Domain.Commands.Users.DeleteUser;
using CleanArchitecture.Domain.DomainEvents;
using CleanArchitecture.Domain.Events.User;
using CleanArchitecture.Domain.Notifications;
using MediatR;
using Moq;
using Xunit;
namespace CleanArchitecture.Infrastructure.Tests;
public sealed class InMemoryBusTests
{
[Fact]
public async Task InMemoryBus_Should_Publish_When_Not_DomainNotification()
{
var mediator = new Mock<IMediator>();
var domainEventStore = new Mock<IDomainEventStore>();
var inMemoryBus = new InMemoryBus(mediator.Object, domainEventStore.Object);
const string key = "Key";
const string value = "Value";
const string code = "Code";
var domainEvent = new DomainNotification(key, value, code);
await inMemoryBus.RaiseEventAsync(domainEvent);
mediator.Verify(x => x.Publish(domainEvent, CancellationToken.None), Times.Once);
}
[Fact]
public async Task InMemoryBus_Should_Save_And_Publish_When_DomainNotification()
{
var mediator = new Mock<IMediator>();
var domainEventStore = new Mock<IDomainEventStore>();
var inMemoryBus = new InMemoryBus(mediator.Object, domainEventStore.Object);
var userDeletedEvent = new UserDeletedEvent(Guid.NewGuid());
await inMemoryBus.RaiseEventAsync(userDeletedEvent);
mediator.Verify(x => x.Publish(userDeletedEvent, CancellationToken.None), Times.Once);
}
[Fact]
public async Task InMemoryBus_Should_Send_Command_Async()
{
var mediator = new Mock<IMediator>();
var domainEventStore = new Mock<IDomainEventStore>();
var inMemoryBus = new InMemoryBus(mediator.Object, domainEventStore.Object);
var deleteUserCommand = new DeleteUserCommand(Guid.NewGuid());
await inMemoryBus.SendCommandAsync(deleteUserCommand);
mediator.Verify(x => x.Send(deleteUserCommand, CancellationToken.None), Times.Once);
}
}