From 81c1e50357b580837ce36a6ca73485e819858894 Mon Sep 17 00:00:00 2001 From: yallie Date: Thu, 28 Nov 2024 02:06:19 +0300 Subject: [PATCH] Running RpcTests on all supported channels. --- CoreRemoting.Tests/AsyncTests.cs | 1 + CoreRemoting.Tests/CallContextTests.cs | 1 + CoreRemoting.Tests/LinqExpressionTests.cs | 1 + .../RemotingConfigurationTests.cs | 7 ++++- CoreRemoting.Tests/ReturnAsProxyTests.cs | 1 + CoreRemoting.Tests/RpcTests.cs | 26 ++++++++++++++-- CoreRemoting.Tests/RpcTests_WatsonTcp.cs | 18 +++++++++++ CoreRemoting.Tests/RpcTests_Websockets.cs | 18 +++++++++++ CoreRemoting.Tests/ServerFixture.cs | 30 +++++++++++++------ CoreRemoting.Tests/SessionTests.cs | 1 + 10 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 CoreRemoting.Tests/RpcTests_WatsonTcp.cs create mode 100644 CoreRemoting.Tests/RpcTests_Websockets.cs diff --git a/CoreRemoting.Tests/AsyncTests.cs b/CoreRemoting.Tests/AsyncTests.cs index 9ba7871..fc41299 100644 --- a/CoreRemoting.Tests/AsyncTests.cs +++ b/CoreRemoting.Tests/AsyncTests.cs @@ -11,6 +11,7 @@ public class AsyncTests : IClassFixture public AsyncTests(ServerFixture serverFixture) { _serverFixture = serverFixture; + _serverFixture.Start(); } [Fact] diff --git a/CoreRemoting.Tests/CallContextTests.cs b/CoreRemoting.Tests/CallContextTests.cs index 76ee726..c6d3a3a 100644 --- a/CoreRemoting.Tests/CallContextTests.cs +++ b/CoreRemoting.Tests/CallContextTests.cs @@ -12,6 +12,7 @@ public class CallContextTests : IClassFixture public CallContextTests(ServerFixture serverFixture) { _serverFixture = serverFixture; + _serverFixture.Start(); } [Fact] diff --git a/CoreRemoting.Tests/LinqExpressionTests.cs b/CoreRemoting.Tests/LinqExpressionTests.cs index 621e833..b22b9ff 100644 --- a/CoreRemoting.Tests/LinqExpressionTests.cs +++ b/CoreRemoting.Tests/LinqExpressionTests.cs @@ -11,6 +11,7 @@ public class LinqExpressionTests : IClassFixture public LinqExpressionTests(ServerFixture serverFixture) { _serverFixture = serverFixture; + _serverFixture.Start(); } [Fact] diff --git a/CoreRemoting.Tests/RemotingConfigurationTests.cs b/CoreRemoting.Tests/RemotingConfigurationTests.cs index 9afa4e7..9a53c00 100644 --- a/CoreRemoting.Tests/RemotingConfigurationTests.cs +++ b/CoreRemoting.Tests/RemotingConfigurationTests.cs @@ -12,7 +12,12 @@ namespace CoreRemoting.Tests { public class RemotingConfigurationTests : IClassFixture - { + { + public RemotingConfigurationTests(ServerFixture serverFixture) + { + serverFixture.Start(); + } + [Fact] public void RegisterWellKnownServiceType_should_register_type_resolved_at_runtime() { diff --git a/CoreRemoting.Tests/ReturnAsProxyTests.cs b/CoreRemoting.Tests/ReturnAsProxyTests.cs index 2eee64c..c60affe 100644 --- a/CoreRemoting.Tests/ReturnAsProxyTests.cs +++ b/CoreRemoting.Tests/ReturnAsProxyTests.cs @@ -17,6 +17,7 @@ public ReturnAsProxyTests(ServerFixture serverFixture, ITestOutputHelper testOut { _serverFixture = serverFixture; _testOutputHelper = testOutputHelper; + _serverFixture.Start(); } [Fact] diff --git a/CoreRemoting.Tests/RpcTests.cs b/CoreRemoting.Tests/RpcTests.cs index 2cae79b..b3dddfc 100644 --- a/CoreRemoting.Tests/RpcTests.cs +++ b/CoreRemoting.Tests/RpcTests.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Threading; using System.Threading.Tasks; +using CoreRemoting.Channels; using CoreRemoting.Serialization; using CoreRemoting.Tests.ExternalTypes; using CoreRemoting.Tests.Tools; @@ -18,6 +19,10 @@ public class RpcTests : IClassFixture private readonly ITestOutputHelper _testOutputHelper; private bool _remoteServiceCalled; + protected virtual IServerChannel ServerChannel => null; + + protected virtual IClientChannel ClientChannel => null; + public RpcTests(ServerFixture serverFixture, ITestOutputHelper testOutputHelper) { _serverFixture = serverFixture; @@ -28,6 +33,8 @@ public RpcTests(ServerFixture serverFixture, ITestOutputHelper testOutputHelper) _remoteServiceCalled = true; return arg; }; + + _serverFixture.Start(ServerChannel); } [Fact] @@ -44,7 +51,8 @@ void ClientAction() { ConnectionTimeout = 0, MessageEncryption = false, - ServerPort = _serverFixture.Server.Config.NetworkPort + Channel = ClientChannel, + ServerPort = _serverFixture.Server.Config.NetworkPort, }); stopWatch.Stop(); @@ -115,8 +123,9 @@ void ClientAction() using var client = new RemotingClient(new ClientConfig() { ConnectionTimeout = 0, + Channel = ClientChannel, ServerPort = _serverFixture.Server.Config.NetworkPort, - MessageEncryption = true + MessageEncryption = true, }); stopWatch.Stop(); @@ -183,6 +192,7 @@ void ClientAction() new ClientConfig() { ConnectionTimeout = 0, + Channel = ClientChannel, MessageEncryption = false, ServerPort = _serverFixture.Server.Config.NetworkPort, }); @@ -218,6 +228,7 @@ public void Events_should_work_remotely() { ConnectionTimeout = 0, SendTimeout = 0, + Channel = ClientChannel, MessageEncryption = false, ServerPort = _serverFixture.Server.Config.NetworkPort, }); @@ -270,6 +281,7 @@ void ClientAction() using var client = new RemotingClient(new ClientConfig() { ConnectionTimeout = 0, + Channel = ClientChannel, MessageEncryption = false, ServerPort = _serverFixture.Server.Config.NetworkPort, }); @@ -302,6 +314,7 @@ public void Generic_methods_should_be_called_correctly() using var client = new RemotingClient(new ClientConfig() { ConnectionTimeout = 0, + Channel = ClientChannel, MessageEncryption = false, ServerPort = _serverFixture.Server.Config.NetworkPort, }); @@ -320,6 +333,7 @@ public void Inherited_methods_should_be_called_correctly() using var client = new RemotingClient(new ClientConfig() { ConnectionTimeout = 0, + Channel = ClientChannel, MessageEncryption = false, ServerPort = _serverFixture.Server.Config.NetworkPort, }); @@ -338,6 +352,7 @@ public void Enum_arguments_should_be_passed_correctly() using var client = new RemotingClient(new ClientConfig() { ConnectionTimeout = 0, + Channel = ClientChannel, MessageEncryption = false, ServerPort = _serverFixture.Server.Config.NetworkPort }); @@ -360,6 +375,7 @@ public void Missing_method_throws_RemoteInvocationException() ConnectionTimeout = 0, InvocationTimeout = 0, SendTimeout = 0, + Channel = ClientChannel, MessageEncryption = false, ServerPort = _serverFixture.Server.Config.NetworkPort }); @@ -395,6 +411,7 @@ public void Missing_service_throws_RemoteInvocationException() ConnectionTimeout = 0, InvocationTimeout = 0, SendTimeout = 0, + Channel = ClientChannel, MessageEncryption = false, ServerPort = _serverFixture.Server.Config.NetworkPort }); @@ -419,6 +436,7 @@ public void Error_method_throws_Exception() ConnectionTimeout = 5, InvocationTimeout = 5, SendTimeout = 5, + Channel = ClientChannel, MessageEncryption = false, ServerPort = _serverFixture.Server.Config.NetworkPort }); @@ -450,6 +468,7 @@ public async Task ErrorAsync_method_throws_Exception() ConnectionTimeout = 5, InvocationTimeout = 5, SendTimeout = 5, + Channel = ClientChannel, MessageEncryption = false, ServerPort = _serverFixture.Server.Config.NetworkPort }); @@ -481,6 +500,7 @@ public void NonSerializableError_method_throws_Exception() ConnectionTimeout = 5, InvocationTimeout = 5, SendTimeout = 5, + Channel = ClientChannel, MessageEncryption = false, ServerPort = _serverFixture.Server.Config.NetworkPort }); @@ -523,6 +543,7 @@ async Task Roundtrip(bool encryption) { RemotingClient CreateClient() => new RemotingClient(new ClientConfig() { + Channel = ClientChannel, ServerPort = _serverFixture.Server.Config.NetworkPort, MessageEncryption = encryption, }); @@ -570,6 +591,7 @@ public void DataTable_roundtrip_works_issue60() ConnectionTimeout = 0, InvocationTimeout = 0, SendTimeout = 0, + Channel = ClientChannel, MessageEncryption = false, ServerPort = _serverFixture.Server.Config.NetworkPort, }); diff --git a/CoreRemoting.Tests/RpcTests_WatsonTcp.cs b/CoreRemoting.Tests/RpcTests_WatsonTcp.cs new file mode 100644 index 0000000..852c27b --- /dev/null +++ b/CoreRemoting.Tests/RpcTests_WatsonTcp.cs @@ -0,0 +1,18 @@ +using CoreRemoting.Channels; +using CoreRemoting.Channels.Tcp; +using Xunit; +using Xunit.Abstractions; + +namespace CoreRemoting.Tests +{ + public class RpcTests_WatsonTcp : RpcTests + { + protected override IServerChannel ServerChannel => new TcpServerChannel(); + + protected override IClientChannel ClientChannel => new TcpClientChannel(); + + public RpcTests_WatsonTcp(ServerFixture s, ITestOutputHelper h) : base(s, h) + { + } + } +} \ No newline at end of file diff --git a/CoreRemoting.Tests/RpcTests_Websockets.cs b/CoreRemoting.Tests/RpcTests_Websockets.cs new file mode 100644 index 0000000..8a86408 --- /dev/null +++ b/CoreRemoting.Tests/RpcTests_Websockets.cs @@ -0,0 +1,18 @@ +using CoreRemoting.Channels; +using CoreRemoting.Channels.Websocket; +using Xunit; +using Xunit.Abstractions; + +namespace CoreRemoting.Tests +{ + public class RpcTests_Websockets : RpcTests + { + protected override IServerChannel ServerChannel => new WebsocketServerChannel(); + + protected override IClientChannel ClientChannel => new WebsocketClientChannel(); + + public RpcTests_Websockets(ServerFixture fixture, ITestOutputHelper helper) : base(fixture, helper) + { + } + } +} \ No newline at end of file diff --git a/CoreRemoting.Tests/ServerFixture.cs b/CoreRemoting.Tests/ServerFixture.cs index 3b2ae21..0ae80c3 100644 --- a/CoreRemoting.Tests/ServerFixture.cs +++ b/CoreRemoting.Tests/ServerFixture.cs @@ -1,5 +1,6 @@ using System; using System.Threading; +using CoreRemoting.Channels; using CoreRemoting.DependencyInjection; using CoreRemoting.Tests.Tools; using Xunit; @@ -14,7 +15,7 @@ public ServerFixture() { TestService = new TestService(); - var serverConfig = + ServerConfig = new ServerConfig() { UniqueServerInstanceName = "DefaultServer", @@ -49,20 +50,31 @@ public ServerFixture() lifetime: ServiceLifetime.Singleton); } }; - - Server = new RemotingServer(serverConfig); - - Server.Error += (_ , _) => + } + + public void Start(IServerChannel channel = null) + { + if (Server != null) + return; + + if (channel != null) + ServerConfig.Channel = channel; + + Server = new RemotingServer(ServerConfig); + Server.Error += (_, _) => { ServerErrorCount++; }; - + Server.Start(); } - - public RemotingServer Server { get; } + + public RemotingServer Server { get; private set; } + + public ServerConfig ServerConfig { get; set; } + public TestService TestService { get; } - + public void Dispose() { if (Server != null) diff --git a/CoreRemoting.Tests/SessionTests.cs b/CoreRemoting.Tests/SessionTests.cs index d56bc95..aea7c86 100644 --- a/CoreRemoting.Tests/SessionTests.cs +++ b/CoreRemoting.Tests/SessionTests.cs @@ -19,6 +19,7 @@ public class SessionTests : IClassFixture public SessionTests(ServerFixture serverFixture) { _serverFixture = serverFixture; + _serverFixture.Start(); } [Fact]