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>
107 lines
2.7 KiB
C#
107 lines
2.7 KiB
C#
using Svrnty.CQRS.Configuration;
|
|
|
|
namespace Svrnty.CQRS.Tests;
|
|
|
|
public class CqrsConfigurationTests
|
|
{
|
|
private class TestConfig
|
|
{
|
|
public string Value { get; set; } = string.Empty;
|
|
}
|
|
|
|
private class OtherConfig
|
|
{
|
|
public int Number { get; set; }
|
|
}
|
|
|
|
[Fact]
|
|
public void SetConfiguration_CanBeRetrieved()
|
|
{
|
|
var config = new CqrsConfiguration();
|
|
var testConfig = new TestConfig { Value = "hello" };
|
|
|
|
config.SetConfiguration(testConfig);
|
|
|
|
var retrieved = config.GetConfiguration<TestConfig>();
|
|
Assert.NotNull(retrieved);
|
|
Assert.Equal("hello", retrieved.Value);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetConfiguration_ReturnsNull_WhenNotSet()
|
|
{
|
|
var config = new CqrsConfiguration();
|
|
|
|
var retrieved = config.GetConfiguration<TestConfig>();
|
|
|
|
Assert.Null(retrieved);
|
|
}
|
|
|
|
[Fact]
|
|
public void HasConfiguration_ReturnsTrue_WhenSet()
|
|
{
|
|
var config = new CqrsConfiguration();
|
|
config.SetConfiguration(new TestConfig());
|
|
|
|
Assert.True(config.HasConfiguration<TestConfig>());
|
|
}
|
|
|
|
[Fact]
|
|
public void HasConfiguration_ReturnsFalse_WhenNotSet()
|
|
{
|
|
var config = new CqrsConfiguration();
|
|
|
|
Assert.False(config.HasConfiguration<TestConfig>());
|
|
}
|
|
|
|
[Fact]
|
|
public void SetConfiguration_OverwritesPrevious()
|
|
{
|
|
var config = new CqrsConfiguration();
|
|
config.SetConfiguration(new TestConfig { Value = "first" });
|
|
config.SetConfiguration(new TestConfig { Value = "second" });
|
|
|
|
var retrieved = config.GetConfiguration<TestConfig>();
|
|
Assert.Equal("second", retrieved!.Value);
|
|
}
|
|
|
|
[Fact]
|
|
public void MultipleConfigTypes_AreIndependent()
|
|
{
|
|
var config = new CqrsConfiguration();
|
|
config.SetConfiguration(new TestConfig { Value = "test" });
|
|
config.SetConfiguration(new OtherConfig { Number = 42 });
|
|
|
|
Assert.Equal("test", config.GetConfiguration<TestConfig>()!.Value);
|
|
Assert.Equal(42, config.GetConfiguration<OtherConfig>()!.Number);
|
|
}
|
|
|
|
[Fact]
|
|
public void ExecuteMappingCallbacks_InvokesAllCallbacks()
|
|
{
|
|
var config = new CqrsConfiguration();
|
|
var callCount = 0;
|
|
|
|
config.AddMappingCallback(_ => callCount++);
|
|
config.AddMappingCallback(_ => callCount++);
|
|
|
|
config.ExecuteMappingCallbacks(new object());
|
|
|
|
Assert.Equal(2, callCount);
|
|
}
|
|
|
|
[Fact]
|
|
public void ExecuteMappingCallbacks_PassesAppObject()
|
|
{
|
|
var config = new CqrsConfiguration();
|
|
object? receivedApp = null;
|
|
|
|
config.AddMappingCallback(app => receivedApp = app);
|
|
|
|
var expected = new object();
|
|
config.ExecuteMappingCallbacks(expected);
|
|
|
|
Assert.Same(expected, receivedApp);
|
|
}
|
|
}
|