Files
JustFixMe 54ea0925dd
All checks were successful
.NET Test / test (push) Successful in 6m47s
solution files
2025-02-01 20:34:34 +04:00

64 lines
1.9 KiB
C#

using Microsoft.Extensions.DependencyInjection;
namespace Cqrs.Tests.CqrsServicesExtensionsTests;
public class AddCqrs
{
[Fact]
public void WhenCalled_ShouldRegisterDispatcherClasses()
{
// Given
ServiceCollection services = new();
// When
services.AddCqrs();
// Then
services.ShouldContain(
elementPredicate: descriptor =>
descriptor.ServiceType == typeof(ICommandDispatcher)
&& descriptor.ImplementationType == typeof(CommandDispatcherImpl)
&& descriptor.Lifetime == ServiceLifetime.Transient,
expectedCount: 1
);
services.ShouldContain(
elementPredicate: descriptor =>
descriptor.ServiceType == typeof(IQueryDispatcher)
&& descriptor.ImplementationType == typeof(QueryDispatcherImpl)
&& descriptor.Lifetime == ServiceLifetime.Transient,
expectedCount: 1
);
}
[Fact]
public void WhenCalledMultipleTimes_ShouldRegisterDispatcherClassesOnce()
{
// Given
ServiceCollection services = new();
// When
services.AddCqrs();
services.AddCqrs();
services.AddCqrs();
services.AddCqrs();
// Then
services.ShouldContain(
elementPredicate: descriptor =>
descriptor.ServiceType == typeof(ICommandDispatcher)
&& descriptor.ImplementationType == typeof(CommandDispatcherImpl)
&& descriptor.Lifetime == ServiceLifetime.Transient,
expectedCount: 1
);
services.ShouldContain(
elementPredicate: descriptor =>
descriptor.ServiceType == typeof(IQueryDispatcher)
&& descriptor.ImplementationType == typeof(QueryDispatcherImpl)
&& descriptor.Lifetime == ServiceLifetime.Transient,
expectedCount: 1
);
}
}