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>
125 lines
3.4 KiB
C#
125 lines
3.4 KiB
C#
using Svrnty.CQRS.Abstractions.Discovery;
|
|
using Svrnty.CQRS.Discovery;
|
|
|
|
namespace Svrnty.CQRS.Tests;
|
|
|
|
public class CommandDiscoveryTests
|
|
{
|
|
private static CommandDiscovery CreateDiscovery(params ICommandMeta[] metas)
|
|
{
|
|
return new CommandDiscovery(metas);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetCommands_ReturnsAllRegistered()
|
|
{
|
|
var meta1 = new CommandMeta(typeof(CreatePersonCommand), typeof(object), typeof(CreatePersonResult));
|
|
var meta2 = new CommandMeta(typeof(DeletePersonCommand), typeof(object));
|
|
var discovery = CreateDiscovery(meta1, meta2);
|
|
|
|
var commands = discovery.GetCommands().ToList();
|
|
|
|
Assert.Equal(2, commands.Count);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetCommands_ReturnsEmpty_WhenNoneRegistered()
|
|
{
|
|
var discovery = CreateDiscovery();
|
|
|
|
var commands = discovery.GetCommands().ToList();
|
|
|
|
Assert.Empty(commands);
|
|
}
|
|
|
|
[Fact]
|
|
public void FindCommand_ByName_ReturnsCorrectMeta()
|
|
{
|
|
var meta = new CommandMeta(typeof(CreatePersonCommand), typeof(object), typeof(CreatePersonResult));
|
|
var discovery = CreateDiscovery(meta);
|
|
|
|
var found = discovery.FindCommand("CreatePerson");
|
|
|
|
Assert.NotNull(found);
|
|
Assert.Equal(typeof(CreatePersonCommand), found.CommandType);
|
|
}
|
|
|
|
[Fact]
|
|
public void FindCommand_ByName_ReturnsNull_WhenNotFound()
|
|
{
|
|
var discovery = CreateDiscovery();
|
|
|
|
var found = discovery.FindCommand("NonExistent");
|
|
|
|
Assert.Null(found);
|
|
}
|
|
|
|
[Fact]
|
|
public void FindCommand_ByType_ReturnsCorrectMeta()
|
|
{
|
|
var meta = new CommandMeta(typeof(CreatePersonCommand), typeof(object), typeof(CreatePersonResult));
|
|
var discovery = CreateDiscovery(meta);
|
|
|
|
var found = discovery.FindCommand(typeof(CreatePersonCommand));
|
|
|
|
Assert.NotNull(found);
|
|
Assert.Equal("CreatePerson", found.Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void FindCommand_ByType_ReturnsNull_WhenNotFound()
|
|
{
|
|
var discovery = CreateDiscovery();
|
|
|
|
var found = discovery.FindCommand(typeof(CreatePersonCommand));
|
|
|
|
Assert.Null(found);
|
|
}
|
|
|
|
[Fact]
|
|
public void CommandExists_ByName_ReturnsTrue_WhenFound()
|
|
{
|
|
var meta = new CommandMeta(typeof(CreatePersonCommand), typeof(object));
|
|
var discovery = CreateDiscovery(meta);
|
|
|
|
Assert.True(discovery.CommandExists("CreatePerson"));
|
|
}
|
|
|
|
[Fact]
|
|
public void CommandExists_ByName_ReturnsFalse_WhenNotFound()
|
|
{
|
|
var discovery = CreateDiscovery();
|
|
|
|
Assert.False(discovery.CommandExists("CreatePerson"));
|
|
}
|
|
|
|
[Fact]
|
|
public void CommandExists_ByType_ReturnsTrue_WhenFound()
|
|
{
|
|
var meta = new CommandMeta(typeof(CreatePersonCommand), typeof(object));
|
|
var discovery = CreateDiscovery(meta);
|
|
|
|
Assert.True(discovery.CommandExists(typeof(CreatePersonCommand)));
|
|
}
|
|
|
|
[Fact]
|
|
public void CommandExists_ByType_ReturnsFalse_WhenNotFound()
|
|
{
|
|
var discovery = CreateDiscovery();
|
|
|
|
Assert.False(discovery.CommandExists(typeof(CreatePersonCommand)));
|
|
}
|
|
|
|
[Fact]
|
|
public void FindCommand_WithCustomName_FindsByAttributeName()
|
|
{
|
|
var meta = new CommandMeta(typeof(CreateWidgetCommand), typeof(object));
|
|
var discovery = CreateDiscovery(meta);
|
|
|
|
var found = discovery.FindCommand("customCreate");
|
|
|
|
Assert.NotNull(found);
|
|
Assert.Equal(typeof(CreateWidgetCommand), found.CommandType);
|
|
}
|
|
}
|