- 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.
138 lines
3.4 KiB
C#
138 lines
3.4 KiB
C#
using StellaOps.Microservice;
|
|
using StellaOps.Router.Common.Enums;
|
|
using Xunit;
|
|
|
|
namespace StellaOps.Microservice.Tests;
|
|
|
|
public class StellaMicroserviceOptionsTests
|
|
{
|
|
[Fact]
|
|
public void StellaMicroserviceOptions_CanBeCreated()
|
|
{
|
|
// Arrange & Act
|
|
var options = new StellaMicroserviceOptions
|
|
{
|
|
ServiceName = "test-service",
|
|
Version = "1.0.0",
|
|
Region = "eu1"
|
|
};
|
|
|
|
// Assert
|
|
Assert.Equal("test-service", options.ServiceName);
|
|
Assert.Equal("1.0.0", options.Version);
|
|
Assert.Equal("eu1", options.Region);
|
|
Assert.NotEmpty(options.InstanceId);
|
|
}
|
|
|
|
[Fact]
|
|
public void RouterEndpointConfig_CanBeCreated()
|
|
{
|
|
// Arrange & Act
|
|
var config = new RouterEndpointConfig
|
|
{
|
|
Host = "localhost",
|
|
Port = 5000,
|
|
TransportType = TransportType.Tcp
|
|
};
|
|
|
|
// Assert
|
|
Assert.Equal("localhost", config.Host);
|
|
Assert.Equal(5000, config.Port);
|
|
Assert.Equal(TransportType.Tcp, config.TransportType);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_ThrowsIfServiceNameEmpty()
|
|
{
|
|
// Arrange
|
|
var options = new StellaMicroserviceOptions
|
|
{
|
|
ServiceName = "",
|
|
Version = "1.0.0",
|
|
Region = "eu1"
|
|
};
|
|
|
|
// Act & Assert
|
|
Assert.Throws<InvalidOperationException>(() => options.Validate());
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_ThrowsIfVersionInvalid()
|
|
{
|
|
// Arrange
|
|
var options = new StellaMicroserviceOptions
|
|
{
|
|
ServiceName = "test",
|
|
Version = "not-semver",
|
|
Region = "eu1"
|
|
};
|
|
|
|
// Act & Assert
|
|
var ex = Assert.Throws<InvalidOperationException>(() => options.Validate());
|
|
Assert.Contains("not valid semver", ex.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_ThrowsIfNoRouters()
|
|
{
|
|
// Arrange
|
|
var options = new StellaMicroserviceOptions
|
|
{
|
|
ServiceName = "test",
|
|
Version = "1.0.0",
|
|
Region = "eu1"
|
|
};
|
|
|
|
// Act & Assert
|
|
var ex = Assert.Throws<InvalidOperationException>(() => options.Validate());
|
|
Assert.Contains("router endpoint is required", ex.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_AcceptsValidSemver()
|
|
{
|
|
// Arrange
|
|
var options = new StellaMicroserviceOptions
|
|
{
|
|
ServiceName = "test",
|
|
Version = "1.0.0",
|
|
Region = "eu1",
|
|
Routers = [new RouterEndpointConfig { Host = "localhost", Port = 5000 }]
|
|
};
|
|
|
|
// Act & Assert - no exception
|
|
options.Validate();
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_AcceptsSemverWithPrerelease()
|
|
{
|
|
// Arrange
|
|
var options = new StellaMicroserviceOptions
|
|
{
|
|
ServiceName = "test",
|
|
Version = "2.1.0-beta.1",
|
|
Region = "eu1",
|
|
Routers = [new RouterEndpointConfig { Host = "localhost", Port = 5000 }]
|
|
};
|
|
|
|
// Act & Assert - no exception
|
|
options.Validate();
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultHeartbeatInterval_Is10Seconds()
|
|
{
|
|
// Arrange & Act
|
|
var options = new StellaMicroserviceOptions
|
|
{
|
|
ServiceName = "test",
|
|
Version = "1.0.0",
|
|
Region = "eu1"
|
|
};
|
|
|
|
// Assert
|
|
Assert.Equal(TimeSpan.FromSeconds(10), options.HeartbeatInterval);
|
|
}
|
|
}
|