Path: redb-route/tests/redb.Route.Tests.Grpc/GrpcComponentTests.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Grpc/GrpcComponentTests.cs ---- using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Grpc; namespace redb.Route.Tests.Grpc; public class GrpcComponentTests { [Fact] public void Scheme_IsGrpc() { var component = new GrpcComponent(); component.Scheme.Should().Be("grpc"); } [Fact] public void CreateEndpoint_ReturnsGrpcEndpoint() { var component = new GrpcComponent(); var uri = new EndpointUri("grpc", "/localhost:50051", "grpc:localhost:50051", new Dictionary()); var endpoint = component.CreateEndpoint(uri); endpoint.Should().BeOfType(); } [Fact] public void CreateEndpoint_DefaultOptions() { var component = new GrpcComponent(); var uri = new EndpointUri("grpc", "/localhost:50051", "grpc:localhost:50051", new Dictionary()); var endpoint = (GrpcEndpoint)component.CreateEndpoint(uri); endpoint.EndpointOptions.Deadline.Should().Be(30_000); endpoint.EndpointOptions.Plaintext.Should().BeTrue(); endpoint.EndpointOptions.Port.Should().Be(50051); endpoint.EndpointOptions.Host.Should().Be("localhost"); endpoint.EndpointOptions.Ssl.Should().BeFalse(); endpoint.EndpointOptions.InOut.Should().BeTrue(); endpoint.EndpointOptions.MaxSendMessageSize.Should().Be(4 * 1024 * 1024); endpoint.EndpointOptions.MaxReceiveMessageSize.Should().Be(4 * 1024 * 1024); endpoint.EndpointOptions.MaxRequestMessageSize.Should().Be(4 * 1024 * 1024); } [Fact] public void CreateEndpoint_BindsUriParameters() { var component = new GrpcComponent(); var parameters = new Dictionary { ["deadline"] = "5000", ["plaintext"] = "false", ["port"] = "9999", ["host"] = "127.0.0.1", ["inOut"] = "false", ["maxSendMessageSize"] = "1048576", ["maxReceiveMessageSize"] = "2097152" }; var uri = new EndpointUri("grpc", "/localhost:9999", "grpc:localhost:9999", parameters); var endpoint = (GrpcEndpoint)component.CreateEndpoint(uri); endpoint.EndpointOptions.Deadline.Should().Be(5000); endpoint.EndpointOptions.Plaintext.Should().BeFalse(); endpoint.EndpointOptions.Port.Should().Be(9999); endpoint.EndpointOptions.Host.Should().Be("127.0.0.1"); endpoint.EndpointOptions.InOut.Should().BeFalse(); endpoint.EndpointOptions.MaxSendMessageSize.Should().Be(1048576); endpoint.EndpointOptions.MaxReceiveMessageSize.Should().Be(2097152); } [Fact] public void CreateEndpoint_InvalidPort_Throws() { var component = new GrpcComponent(); var parameters = new Dictionary { ["port"] = "70000" }; var uri = new EndpointUri("grpc", "/localhost:70000", "grpc:localhost:70000", parameters); var act = () => component.CreateEndpoint(uri); act.Should().Throw().WithMessage("*Port*"); } [Fact] public void CreateEndpoint_NegativeDeadline_Throws() { var component = new GrpcComponent(); var parameters = new Dictionary { ["deadline"] = "-1" }; var uri = new EndpointUri("grpc", "/localhost:50051", "grpc:localhost:50051", parameters); var act = () => component.CreateEndpoint(uri); act.Should().Throw().WithMessage("*Deadline*"); } [Fact] public void CreateEndpoint_SslWithoutCert_DefersToTheBind() { // The certificate may come from a named connection factory or from the host default // (HttpHostingOptions.Tls), which an endpoint cannot see. "TLS asked for and nothing // resolves" is enforced once, at the bind, by SharedHttpServerManager — see // SharedHostTlsTests, which asserts the listener refuses to open rather than serving // plaintext under an https:// banner. var component = new GrpcComponent(); var parameters = new Dictionary { ["ssl"] = "true" }; var uri = new EndpointUri("grpc", "/localhost:50051", "grpc:localhost:50051", parameters); var act = () => component.CreateEndpoint(uri); act.Should().NotThrow(); } [Fact] public void BuildProducerAddress_Plaintext_ReturnsHttp() { var component = new GrpcComponent(); var parameters = new Dictionary { ["plaintext"] = "true" }; var uri = new EndpointUri("grpc", "/localhost:50051", "grpc:localhost:50051", parameters); var endpoint = (GrpcEndpoint)component.CreateEndpoint(uri); endpoint.BuildProducerAddress().Should().Be("http://localhost:50051"); } [Fact] public void BuildProducerAddress_NoPlaintext_ReturnsHttps() { var component = new GrpcComponent(); var parameters = new Dictionary { ["plaintext"] = "false" }; var uri = new EndpointUri("grpc", "/localhost:50051", "grpc:localhost:50051", parameters); var endpoint = (GrpcEndpoint)component.CreateEndpoint(uri); endpoint.BuildProducerAddress().Should().Be("https://localhost:50051"); } [Fact] public void CreateProducer_ReturnsGrpcProducer() { var component = new GrpcComponent(); var uri = new EndpointUri("grpc", "/localhost:50051", "grpc:localhost:50051", new Dictionary()); var endpoint = component.CreateEndpoint(uri); var producer = endpoint.CreateProducer(); producer.Should().BeOfType(); } [Fact] public void CreateConsumer_ReturnsGrpcConsumer() { var component = new GrpcComponent(); var uri = new EndpointUri("grpc", "/localhost:50051", "grpc:localhost:50051", new Dictionary()); var endpoint = component.CreateEndpoint(uri); var processor = Substitute.For(); var consumer = endpoint.CreateConsumer(processor); consumer.Should().BeOfType(); } [Fact] public void CreateConsumer_NullProcessor_Throws() { var component = new GrpcComponent(); var uri = new EndpointUri("grpc", "/localhost:50051", "grpc:localhost:50051", new Dictionary()); var endpoint = component.CreateEndpoint(uri); var act = () => endpoint.CreateConsumer(null!); act.Should().Throw(); } }