forked from theRainbird/CoreRemoting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemotingConfigurationTests.cs
120 lines (98 loc) · 4.81 KB
/
RemotingConfigurationTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using System.IO;
using System.Reflection;
using CoreRemoting.Authentication;
using CoreRemoting.Channels.Websocket;
using CoreRemoting.ClassicRemotingApi;
using CoreRemoting.DependencyInjection;
using CoreRemoting.Serialization.Binary;
using CoreRemoting.Tests.Tools;
using Xunit;
namespace CoreRemoting.Tests
{
public class RemotingConfigurationTests : IClassFixture<ServerFixture>
{
[Fact]
public void RegisterWellKnownServiceType_should_register_type_resolved_at_runtime()
{
RemotingConfiguration.RegisterServer(new ServerConfig()
{
UniqueServerInstanceName = "Server1"
});
var server = RemotingConfiguration.GetRegisteredServer("Server1");
RemotingConfiguration.RegisterWellKnownServiceType(
interfaceType: typeof(ITestService),
implementationType: typeof(TestService),
lifetime: ServiceLifetime.Singleton,
serviceName: "Service1",
uniqueServerInstanceName: "Server1");
var service = server.ServiceRegistry.GetService("Service1");
Assert.NotNull(service);
Assert.Equal(typeof(TestService), service.GetType());
RemotingConfiguration.ShutdownAll();
}
[Fact]
public void RemotingServer_should_register_on_construction_AND_unregister_on_Dispose()
{
RemotingConfiguration.RegisterServer(new ServerConfig()
{
UniqueServerInstanceName = "Server1"
});
Assert.NotNull(RemotingConfiguration.GetRegisteredServer("Server1"));
var server = RemotingConfiguration.GetRegisteredServer("Server1");
server.Dispose();
Assert.Null(RemotingConfiguration.GetRegisteredServer("Server1"));
}
[Fact]
public void RemotingConfiguration_Configure_should_configure_a_server_and_a_client()
{
// See TestConfig.xml to check test configuration
var configFileName =
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!,
"TestConfig.xml");
RemotingConfiguration.Configure(
fileName: configFileName,
credentials: new []
{
new Credential() { Name = "token", Value = "123" }
});
var server = RemotingConfiguration.GetRegisteredServer("TestServer4711");
if (!server.Config.Channel.IsListening)
throw new ApplicationException("Channel is listening.");
var authProvider = (FakeAuthProvider) server.Config.AuthenticationProvider;
authProvider.AuthenticateFake = credentials =>
credentials.Length == 1 &&
credentials[0].Name == "token" &&
credentials[0].Value == "123";
Assert.NotNull(server);
Assert.Equal(8089, server.Config.NetworkPort);
Assert.Equal("localhost", server.Config.HostName);
Assert.Equal(2048, server.Config.KeySize);
Assert.IsType<BinarySerializerAdapter>(server.Serializer);
Assert.IsType<WebsocketServerChannel>(server.Config.Channel);
Assert.IsType<FakeAuthProvider>(server.Config.AuthenticationProvider);
Assert.True(server.Config.AuthenticationRequired);
Assert.True(server.Config.MessageEncryption);
Assert.NotNull(server.ServiceRegistry.GetService("TestService"));
Assert.IsType<TestService>(server.ServiceRegistry.GetService("TestService"));
var client = RemotingConfiguration.GetRegisteredClient("TestClient");
Assert.NotNull(client);
Assert.Equal(8089, client.Config.ServerPort);
Assert.Equal("localhost", client.Config.ServerHostName);
Assert.Equal(2048, client.Config.KeySize);
Assert.IsType<BinarySerializerAdapter>(client.Config.Serializer);
Assert.IsType<WebsocketClientChannel>(client.Config.Channel);
Assert.True(client.Config.MessageEncryption);
Assert.True(client.Config.IsDefault);
Assert.Equal(200, client.Config.ConnectionTimeout);
Assert.Equal(110, client.Config.AuthenticationTimeout);
Assert.Equal(30000, client.Config.InvocationTimeout);
var proxy = (ITestService)RemotingServices.Connect(typeof(ITestService), "TestService");
Assert.True(client.IsConnected);
var result = proxy.Echo("hello");
Assert.Equal("hello", result);
RemotingConfiguration.ShutdownAll();
}
}
}