consolidation of some of the modules, localization fixes, product advisories work, qa work
This commit is contained in:
@@ -222,10 +222,10 @@ public sealed class RouterTransportPluginLoaderTests
|
||||
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void LoadFromDirectory_NonExistentDirectory_LogsWarning()
|
||||
public void LoadFromDirectory_NonExistentDirectory_LogsDebug()
|
||||
{
|
||||
// Arrange
|
||||
var loggerMock = new Mock<ILogger>();
|
||||
var loggerMock = new Mock<ILogger<RouterTransportPluginLoader>>();
|
||||
var loader = new RouterTransportPluginLoader(loggerMock.Object);
|
||||
var nonExistentDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
||||
|
||||
@@ -236,9 +236,9 @@ public sealed class RouterTransportPluginLoaderTests
|
||||
loader.Plugins.Should().BeEmpty();
|
||||
loggerMock.Verify(
|
||||
x => x.Log(
|
||||
LogLevel.Warning,
|
||||
LogLevel.Debug,
|
||||
It.IsAny<EventId>(),
|
||||
It.Is<It.IsAnyType>((v, t) => v.ToString()!.Contains("does not exist")),
|
||||
It.Is<It.IsAnyType>((v, t) => v.ToString()!.Contains("does not exist or is empty")),
|
||||
It.IsAny<Exception>(),
|
||||
It.IsAny<Func<It.IsAnyType, Exception?, string>>()),
|
||||
Times.Once);
|
||||
@@ -269,7 +269,7 @@ public sealed class RouterTransportPluginLoaderTests
|
||||
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void LoadFromDirectory_MethodChaining_Works()
|
||||
public void LoadFromDirectory_ExistingDirectory_DoesNotThrow()
|
||||
{
|
||||
// Arrange
|
||||
var loader = new RouterTransportPluginLoader();
|
||||
@@ -279,10 +279,10 @@ public sealed class RouterTransportPluginLoaderTests
|
||||
try
|
||||
{
|
||||
// Act
|
||||
var result = loader.LoadFromDirectory(emptyDir);
|
||||
var act = () => loader.LoadFromDirectory(emptyDir);
|
||||
|
||||
// Assert
|
||||
result.Should().BeSameAs(loader);
|
||||
act.Should().NotThrow();
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -292,23 +292,27 @@ public sealed class RouterTransportPluginLoaderTests
|
||||
|
||||
#endregion
|
||||
|
||||
#region RegisterConfiguredTransport Tests
|
||||
#region Plugin Registration Context Tests
|
||||
|
||||
[Trait("Category", TestCategories.Integration)]
|
||||
[Fact]
|
||||
public void RegisterConfiguredTransport_WithExplicitTransport_RegistersCorrectPlugin()
|
||||
public void GetPlugin_TcpRegister_RegistersClientAndServer()
|
||||
{
|
||||
// Arrange
|
||||
var loader = new RouterTransportPluginLoader();
|
||||
loader.LoadFromAssembly(typeof(TcpTransportPlugin).Assembly);
|
||||
loader.LoadFromAssembly(typeof(InMemoryTransportPlugin).Assembly);
|
||||
var plugin = loader.GetPlugin("tcp");
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging();
|
||||
var config = new ConfigurationBuilder().Build();
|
||||
|
||||
// Act
|
||||
loader.RegisterConfiguredTransport(services, config, RouterTransportMode.Both, "tcp");
|
||||
plugin.Should().NotBeNull();
|
||||
plugin!.Register(new RouterTransportRegistrationContext(
|
||||
services,
|
||||
config,
|
||||
RouterTransportMode.Both));
|
||||
|
||||
// Assert
|
||||
var provider = services.BuildServiceProvider();
|
||||
@@ -318,94 +322,28 @@ public sealed class RouterTransportPluginLoaderTests
|
||||
|
||||
[Trait("Category", TestCategories.Integration)]
|
||||
[Fact]
|
||||
public void RegisterConfiguredTransport_FromConfiguration_ReadsTransportType()
|
||||
public void GetPlugin_InMemoryRegister_RegistersConnectionRegistry()
|
||||
{
|
||||
// Arrange
|
||||
var loader = new RouterTransportPluginLoader();
|
||||
loader.LoadFromAssembly(typeof(InMemoryTransportPlugin).Assembly);
|
||||
var plugin = loader.GetPlugin("inmemory");
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging();
|
||||
var config = new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(new Dictionary<string, string?>
|
||||
{
|
||||
["Router:Transport:Type"] = "inmemory"
|
||||
})
|
||||
.Build();
|
||||
var config = new ConfigurationBuilder().Build();
|
||||
|
||||
// Act
|
||||
loader.RegisterConfiguredTransport(services, config, RouterTransportMode.Both);
|
||||
plugin.Should().NotBeNull();
|
||||
plugin!.Register(new RouterTransportRegistrationContext(
|
||||
services,
|
||||
config,
|
||||
RouterTransportMode.Both));
|
||||
|
||||
// Assert
|
||||
var provider = services.BuildServiceProvider();
|
||||
provider.GetService<InMemoryConnectionRegistry>().Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Trait("Category", TestCategories.Integration)]
|
||||
[Fact]
|
||||
public void RegisterConfiguredTransport_DefaultsToTcp()
|
||||
{
|
||||
// Arrange
|
||||
var loader = new RouterTransportPluginLoader();
|
||||
loader.LoadFromAssembly(typeof(TcpTransportPlugin).Assembly);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging();
|
||||
var config = new ConfigurationBuilder().Build();
|
||||
|
||||
// Act
|
||||
loader.RegisterConfiguredTransport(services, config, RouterTransportMode.Both);
|
||||
|
||||
// Assert
|
||||
var provider = services.BuildServiceProvider();
|
||||
provider.GetService<ITransportServer>().Should().BeOfType<TcpTransportServer>();
|
||||
}
|
||||
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void RegisterConfiguredTransport_UnknownTransport_ThrowsException()
|
||||
{
|
||||
// Arrange
|
||||
var loader = new RouterTransportPluginLoader();
|
||||
var services = new ServiceCollection();
|
||||
var config = new ConfigurationBuilder().Build();
|
||||
|
||||
// Act
|
||||
var act = () => loader.RegisterConfiguredTransport(services, config, RouterTransportMode.Both, "unknown");
|
||||
|
||||
// Assert
|
||||
act.Should().Throw<InvalidOperationException>()
|
||||
.WithMessage("*unknown*not found*");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RegisterAllTransports Tests
|
||||
|
||||
[Trait("Category", TestCategories.Integration)]
|
||||
[Fact]
|
||||
public void RegisterAllTransports_RegistersAllLoadedPlugins()
|
||||
{
|
||||
// Arrange
|
||||
var loader = new RouterTransportPluginLoader();
|
||||
loader.LoadFromAssembly(typeof(TcpTransportPlugin).Assembly);
|
||||
loader.LoadFromAssembly(typeof(InMemoryTransportPlugin).Assembly);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging();
|
||||
var config = new ConfigurationBuilder().Build();
|
||||
|
||||
// Act
|
||||
loader.RegisterAllTransports(services, config, RouterTransportMode.Both);
|
||||
|
||||
// Assert - Both transports should have registered their services
|
||||
var descriptors = services.Where(d =>
|
||||
d.ServiceType == typeof(ITransportServer) ||
|
||||
d.ServiceType == typeof(ITransportClient)).ToList();
|
||||
|
||||
// InMemory uses TryAdd, so whichever is registered first will be in the container
|
||||
descriptors.Should().HaveCountGreaterThanOrEqualTo(2);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user