Add tests/Svrnty.CQRS.Tests with 61 tests covering: - CommandMeta and QueryMeta metadata creation and naming conventions - CommandDiscovery and QueryDiscovery lookup, existence, and enumeration - DI service registration for commands (with/without result) and queries - Full pipeline integration (register -> discover -> resolve) - CqrsBuilder fluent API configuration - CqrsConfiguration generic storage and mapping callbacks - Handler execution via DI-resolved instances Co-Authored-By: Svrnty Inc. <eng@svrnty.com>
82 lines
2.0 KiB
C#
82 lines
2.0 KiB
C#
using Svrnty.CQRS.Abstractions;
|
|
using Svrnty.CQRS.Abstractions.Attributes;
|
|
|
|
namespace Svrnty.CQRS.Tests;
|
|
|
|
// Commands
|
|
public class CreatePersonCommand
|
|
{
|
|
public string FirstName { get; set; } = string.Empty;
|
|
public string LastName { get; set; } = string.Empty;
|
|
}
|
|
|
|
public class DeletePersonCommand
|
|
{
|
|
public int Id { get; set; }
|
|
}
|
|
|
|
[CommandName("customCreate")]
|
|
public class CreateWidgetCommand
|
|
{
|
|
public string Name { get; set; } = string.Empty;
|
|
}
|
|
|
|
// Command results
|
|
public class CreatePersonResult
|
|
{
|
|
public int Id { get; set; }
|
|
}
|
|
|
|
// Queries
|
|
public class PersonQuery
|
|
{
|
|
public string? NameFilter { get; set; }
|
|
}
|
|
|
|
[QueryName("customPersonLookup")]
|
|
public class PersonLookupQuery
|
|
{
|
|
public int Id { get; set; }
|
|
}
|
|
|
|
// Handlers
|
|
public class CreatePersonCommandHandler : ICommandHandler<CreatePersonCommand, CreatePersonResult>
|
|
{
|
|
public Task<CreatePersonResult> HandleAsync(CreatePersonCommand command, CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.FromResult(new CreatePersonResult { Id = 1 });
|
|
}
|
|
}
|
|
|
|
public class DeletePersonCommandHandler : ICommandHandler<DeletePersonCommand>
|
|
{
|
|
public Task HandleAsync(DeletePersonCommand command, CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
public class CreateWidgetCommandHandler : ICommandHandler<CreateWidgetCommand>
|
|
{
|
|
public Task HandleAsync(CreateWidgetCommand command, CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
public class PersonQueryHandler : IQueryHandler<PersonQuery, IEnumerable<string>>
|
|
{
|
|
public Task<IEnumerable<string>> HandleAsync(PersonQuery query, CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.FromResult<IEnumerable<string>>(["Alice", "Bob"]);
|
|
}
|
|
}
|
|
|
|
public class PersonLookupQueryHandler : IQueryHandler<PersonLookupQuery, string>
|
|
{
|
|
public Task<string> HandleAsync(PersonLookupQuery query, CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.FromResult("Alice");
|
|
}
|
|
}
|