/
BigRemoteServicesIntegrationTester.cs
269 lines (221 loc) · 8.83 KB
/
BigRemoteServicesIntegrationTester.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
using System;
using System.IO;
using System.Threading;
using Bottles.Services.Messaging;
using Bottles.Services.Remote;
using NUnit.Framework;
using System.Linq;
using FubuTestingSupport;
using Rhino.Mocks.Constraints;
using SampleService;
using FubuCore;
using Bottles.Services.Messaging.Tracking;
namespace Bottles.Services.Tests.Remote
{
[Explicit("Only for examples")]
public class Examples
{
[Test]
public void loading_a_custom_application_loader()
{
// SAMPLE: bootstrap-custom-loader
var runner = RemoteServiceRunner.For<IApplicationLoader>(x => {
// more AppDomain configuration
});
// -- or --
runner = new RemoteServiceRunner(x => {
// Can be the assembly qualified name of either:
// 1. An IApplicationLoader class
// 2. An IApplicationSource<,> class
// 3. An IBootstrapper class
x.BootstrapperName = "MyLib.AppLoader, MyLib";
});
// ENDSAMPLE
}
[Test]
public void overriding_the_configuration_file()
{
// SAMPLE: override-config-file
var runner = new RemoteServiceRunner(x => {
x.Setup.ConfigurationFile = "Web.config";
});
// ENDSAMPLE
}
// SAMPLE: custom-application-loader
public class CustomApplicationLoader : IApplicationLoader, IDisposable
{
public IDisposable Load()
{
// Bootstrap the application or service
return this;
}
public void Dispose()
{
// shutdown
}
}
// ENDSAMPLE
[Test]
public void simplest_usage()
{
// SAMPLE: simple-remote-service-runner
var runner = new RemoteServiceRunner(x => {
x.ServiceDirectory = @"c:\code\other-service\src\other-service";
x.Setup.ShadowCopyFiles = true.ToString();
});
// stop and restart the remote AppDomain
runner.Recycle();
// There is support for event aggregation between
// AppDomain's for coordination
runner.SendRemotely(new SomeMessage());
// Shut down and close the remote AppDomain
runner.Dispose();
// ENDSAMPLE
}
public class SomeMessage{}
[Test]
public void open_to_a_parallel_directory()
{
// SAMPLE: parallel-service
var runner = new RemoteServiceRunner(x => {
x.UseParallelServiceDirectory("Service1");
});
// ENDSAMPLE
}
[Test]
public void control_appdomain_setup()
{
// SAMPLE: appdomain-setup
var runner = new RemoteServiceRunner(x => {
// ShadowCopyFiles should be either "true" or "false"
x.Setup.ShadowCopyFiles = true.ToString();
// RemoteServiceRunner makes some guesses about the
// PrivateBinPath based on the folders it sees,
// but once in a while you may want to override
// the bin path
x.Setup.PrivateBinPath = "bin";
});
// ENDSAMPLE
}
[Test]
public void load_assemblies()
{
// SAMPLE: require-assemblies
var runner = new RemoteServiceRunner(x => {
// This line of code will copy the Bottles.dll assembly
// into the remote AppDomain location
x.RequireAssemblyContainingType<Bottles.IPackageFacility>();
x.RequireAssembly("MyAssembly");
});
// ENDSAMPLE
}
}
[TestFixture, Explicit("These tests do not play nice on the build server")]
public class BigRemoteServicesIntegrationTester
{
private RemoteServiceRunner start()
{
return new RemoteServiceRunner(x => {
x.LoadAssemblyContainingType<SampleService.SampleService>();
x.RequireAssemblyContainingType<BigRemoteServicesIntegrationTester>(); // This is mostly a smoke test
});
}
[Test]
public void start_with_only_the_folder_name_with_an_IBottleService()
{
var servicePath = ".".ToFullPath().ParentDirectory().ParentDirectory().ParentDirectory().AppendPath("SampleService");
using (var runner = new RemoteServiceRunner(servicePath))
{
runner.WaitForServiceToStart<SampleService.SampleService>();
runner.Started.Any().ShouldBeTrue();
}
}
[Test]
public void start_with_only_the_folder_name_with_an_IApplicationLoader()
{
var servicePath = ".".ToFullPath().ParentDirectory().ParentDirectory().ParentDirectory().AppendPath("ApplicationLoaderService");
using (var runner = new RemoteServiceRunner(servicePath))
{
runner.WaitForMessage<LoaderStarted>().LoaderTypeName.ShouldContain("MyApplicationLoader");
}
}
[Test]
public void start_with_a_parallel_folder()
{
using (var runner = new RemoteServiceRunner(x => {
x.UseParallelServiceDirectory("ApplicationLoaderService");
}))
{
runner.WaitForMessage<LoaderStarted>().LoaderTypeName.ShouldContain("MyApplicationLoader");
}
}
[Test]
public void run_a_specific_bootstrapper()
{
using (var runner = RemoteServiceRunner.For<SampleBootstrapper>())
{
runner.WaitForServiceToStart<SampleService.SampleService>();
runner.WaitForServiceToStart<SampleService.RemoteService>();
runner.Started.Any().ShouldBeTrue();
}
}
[Test]
public void coordinate_message_history_via_remote_service()
{
using (var runner = RemoteServiceRunner.For<SampleBootstrapper>())
{
runner.WaitForServiceToStart<SampleService.SampleService>();
runner.WaitForServiceToStart<SampleService.RemoteService>();
MessageHistory.StartListening(runner);
var foo = new Foo();
EventAggregator.SentMessage(foo);
EventAggregator.Messaging.WaitForMessage<AllMessagesComplete>(() => runner.SendRemotely(foo), 60000)
.ShouldNotBeNull();
}
}
[Test]
public void coordinate_message_history_via_remote_service_and_clear_data_does_not_remove_listeners()
{
using (var runner = RemoteServiceRunner.For<SampleBootstrapper>())
{
runner.WaitForServiceToStart<SampleService.SampleService>();
runner.WaitForServiceToStart<SampleService.RemoteService>();
MessageHistory.StartListening(runner);
MessageHistory.ClearHistory();
var foo = new Foo();
EventAggregator.SentMessage(foo);
EventAggregator.Messaging.WaitForMessage<AllMessagesComplete>(() => runner.SendRemotely(foo))
.ShouldNotBeNull();
}
}
[Test]
public void spin_up_the_remote_service_for_the_sample_and_send_messages_back_and_forth()
{
using (var runner = start())
{
runner.WaitForServiceToStart<SampleService.SampleService>();
runner.WaitForServiceToStart<SampleService.RemoteService>();
runner.Started.Any().ShouldBeTrue();
}
}
[Test]
public void spin_up_and_send_and_receive_messages()
{
using (var runner = start())
{
runner.WaitForServiceToStart<SampleService.RemoteService>();
runner.WaitForMessage<TestResponse>(() => {
runner.SendRemotely(new TestSignal { Number = 1 });
}).Number.ShouldEqual(1);
runner.WaitForMessage<TestResponse>(() =>
{
runner.SendRemotely(new TestSignal { Number = 3 });
}).Number.ShouldEqual(3);
runner.WaitForMessage<TestResponse>(() =>
{
runner.SendRemotely(new TestSignal { Number = 5 });
}).Number.ShouldEqual(5);
}
}
}
}