solution files
All checks were successful
.NET Test / test (push) Successful in 6m47s

This commit is contained in:
2025-02-01 20:34:34 +04:00
parent 14937c6964
commit 54ea0925dd
30 changed files with 1388 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
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
);
}
}