forked from theRainbird/CoreRemoting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemotingServicesTests.cs
111 lines (85 loc) · 3.5 KB
/
RemotingServicesTests.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
using System;
using System.Threading;
using CoreRemoting.ClassicRemotingApi;
using CoreRemoting.Tests.Tools;
using Xunit;
namespace CoreRemoting.Tests
{
[Collection("CoreRemoting")]
public class RemotingServicesTests
{
[Fact]
public void IsOneWay_should_return_true_if_provided_method_is_OneWay()
{
var serviceType = typeof(ITestService);
var isOneWay = RemotingServices.IsOneWay(serviceType.GetMethod("OneWayMethod"));
Assert.True(isOneWay);
isOneWay = RemotingServices.IsOneWay(serviceType.GetMethod("TestMethod"));
Assert.False(isOneWay);
}
[Fact]
public void IsTransparentProxy_should_return_true_if_the_provided_object_is_a_proxy()
{
var client = new RemotingClient(
new ClientConfig()
{
MessageEncryption = false,
ServerPort = 9199,
ServerHostName = "localhost"
});
var proxy = client.CreateProxy<ITestService>();
var isProxy = RemotingServices.IsTransparentProxy(proxy);
Assert.True(isProxy);
var service = new TestService();
isProxy = RemotingServices.IsTransparentProxy(service);
Assert.False(isProxy);
}
[Fact]
public void Marshal_should_register_a_service_instance()
{
var testService = new TestService();
using var server = new RemotingServer();
server.Start();
string serviceName =
RemotingServices.Marshal(testService, "test", typeof(ITestService), server.UniqueServerInstanceName);
var registeredServiceInstance = server.ServiceRegistry.GetService(serviceName);
Assert.Same(testService, registeredServiceInstance);
Assert.True(registeredServiceInstance is ITestService);
}
[Fact]
public void Connect_should_create_a_proxy_for_a_remote_service()
{
var testService =
new TestService
{
TestMethodFake = arg =>
arg
};
using var server =
new RemotingServer(new ServerConfig
{
NetworkPort = 9199,
IsDefault = true
});
RemotingServices.Marshal(testService, "test", typeof(ITestService));
server.Start();
var clientThread = new Thread(() =>
{
// ReSharper disable once ObjectCreationAsStatement
new RemotingClient(new ClientConfig {ServerPort = 9199, MessageEncryption = false, IsDefault = true});
var proxy =
RemotingServices.Connect(
typeof(ITestService),
"test",
string.Empty);
Assert.True(RemotingServices.IsTransparentProxy(proxy));
object result = ((ITestService) proxy).TestMethod(1);
RemotingClient.DefaultRemotingClient.Dispose();
Assert.Equal(1, Convert.ToInt32(result));
});
clientThread.Start();
clientThread.Join();
server.Dispose();
}
}
}