- Added InMemoryTransportOptions class for configuration settings including timeouts and latency. - Developed InMemoryTransportServer class to handle connections, frame processing, and event management. - Created ServiceCollectionExtensions for easy registration of InMemory transport services. - Established project structure and dependencies for InMemory transport library. - Implemented comprehensive unit tests for endpoint discovery, connection management, request/response flow, and streaming capabilities. - Ensured proper handling of cancellation, heartbeat, and hello frames within the transport layer.
107 lines
2.6 KiB
C#
107 lines
2.6 KiB
C#
using StellaOps.Router.Transport.InMemory;
|
|
using Xunit;
|
|
|
|
namespace StellaOps.Router.Transport.InMemory.Tests;
|
|
|
|
public class InMemoryConnectionRegistryTests
|
|
{
|
|
[Fact]
|
|
public void CreateChannel_CreatesNewChannel()
|
|
{
|
|
// Arrange
|
|
using var registry = new InMemoryConnectionRegistry();
|
|
|
|
// Act
|
|
var channel = registry.CreateChannel("conn-1");
|
|
|
|
// Assert
|
|
Assert.NotNull(channel);
|
|
Assert.Equal("conn-1", channel.ConnectionId);
|
|
Assert.Equal(1, registry.Count);
|
|
}
|
|
|
|
[Fact]
|
|
public void CreateChannel_ThrowsIfDuplicate()
|
|
{
|
|
// Arrange
|
|
using var registry = new InMemoryConnectionRegistry();
|
|
registry.CreateChannel("conn-1");
|
|
|
|
// Act & Assert
|
|
Assert.Throws<InvalidOperationException>(() => registry.CreateChannel("conn-1"));
|
|
}
|
|
|
|
[Fact]
|
|
public void GetChannel_ReturnsNullForUnknown()
|
|
{
|
|
// Arrange
|
|
using var registry = new InMemoryConnectionRegistry();
|
|
|
|
// Act
|
|
var channel = registry.GetChannel("unknown");
|
|
|
|
// Assert
|
|
Assert.Null(channel);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetChannel_ReturnsExistingChannel()
|
|
{
|
|
// Arrange
|
|
using var registry = new InMemoryConnectionRegistry();
|
|
var created = registry.CreateChannel("conn-1");
|
|
|
|
// Act
|
|
var retrieved = registry.GetChannel("conn-1");
|
|
|
|
// Assert
|
|
Assert.Same(created, retrieved);
|
|
}
|
|
|
|
[Fact]
|
|
public void RemoveChannel_RemovesAndDisposes()
|
|
{
|
|
// Arrange
|
|
using var registry = new InMemoryConnectionRegistry();
|
|
var channel = registry.CreateChannel("conn-1");
|
|
|
|
// Act
|
|
var removed = registry.RemoveChannel("conn-1");
|
|
|
|
// Assert
|
|
Assert.True(removed);
|
|
Assert.Equal(0, registry.Count);
|
|
Assert.True(channel.LifetimeToken.IsCancellationRequested);
|
|
}
|
|
|
|
[Fact]
|
|
public void RemoveChannel_ReturnsFalseForUnknown()
|
|
{
|
|
// Arrange
|
|
using var registry = new InMemoryConnectionRegistry();
|
|
|
|
// Act
|
|
var removed = registry.RemoveChannel("unknown");
|
|
|
|
// Assert
|
|
Assert.False(removed);
|
|
}
|
|
|
|
[Fact]
|
|
public void Dispose_DisposesAllChannels()
|
|
{
|
|
// Arrange
|
|
var registry = new InMemoryConnectionRegistry();
|
|
var channel1 = registry.CreateChannel("conn-1");
|
|
var channel2 = registry.CreateChannel("conn-2");
|
|
|
|
// Act
|
|
registry.Dispose();
|
|
|
|
// Assert
|
|
Assert.True(channel1.LifetimeToken.IsCancellationRequested);
|
|
Assert.True(channel2.LifetimeToken.IsCancellationRequested);
|
|
Assert.Equal(0, registry.Count);
|
|
}
|
|
}
|