-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathEditAuditInstanceValidationTests.cs
More file actions
483 lines (365 loc) · 16.5 KB
/
EditAuditInstanceValidationTests.cs
File metadata and controls
483 lines (365 loc) · 16.5 KB
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
namespace ServiceControl.Config.Tests.Validation
{
using System.ComponentModel;
using System.Linq;
using NUnit.Framework;
using ServiceControlInstaller.Engine.Instances;
using UI.InstanceAdd;
using UI.InstanceEdit;
public class EditAuditInstanceValidationTests
{
#region transport
[TestTheseTransports("AmazonSQS", "AzureServiceBus", "SQLServer", "RabbitMQ", "PostgreSQL")]
public void Transport_connection_string_cannot_be_empty_if_sample_connection_string_is_present_when_editing_audit_instance(
string transportInfoName)
{
var viewModel = new ServiceControlAuditEditViewModel
{
SelectedTransport = ServiceControlCoreTransports.Find(transportInfoName),
SubmitAttempted = true,
ConnectionString = string.Empty
};
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.ConnectionString));
Assert.That(errors, Is.Not.Empty);
}
[TestTheseTransports("AmazonSQS", "AzureServiceBus", "SQLServer", "RabbitMQ", "PostgreSQL")]
public void Transport_connection_string_cannot_be_null_if_sample_connection_string_is_present_when_editing_audit_instance(
string transportInfoName)
{
var viewModel = new ServiceControlAuditEditViewModel
{
SelectedTransport = ServiceControlCoreTransports.Find(transportInfoName),
SubmitAttempted = true,
ConnectionString = null
};
viewModel.NotifyOfPropertyChange(nameof(viewModel.ConnectionString));
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.ConnectionString));
Assert.That(errors, Is.Not.Empty);
}
[TestTheseTransports("MSMQ")]
public void Transport_connection_string_can_be_empty_if_sample_connection_string_is_not_present_when_editing_audit_instance(
string transportInfoName)
{
var viewModel = new ServiceControlAuditEditViewModel
{
SelectedTransport = ServiceControlCoreTransports.Find(transportInfoName),
SubmitAttempted = true,
ConnectionString = string.Empty
};
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.ConnectionString));
Assert.That(errors, Is.Empty);
}
[TestTheseTransports("MSMQ")]
public void Transport_connection_string_can_be_null_if_sample_connection_string_is_not_present_when_editing_audit_instance(
string transportInfoName)
{
var viewModel = new ServiceControlAuditEditViewModel
{
SelectedTransport = ServiceControlCoreTransports.Find(transportInfoName),
SubmitAttempted = true,
ConnectionString = null
};
viewModel.NotifyOfPropertyChange(nameof(viewModel.ConnectionString));
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.ConnectionString));
Assert.That(errors, Is.Empty);
}
#endregion
#region hostname
[Test]
public void Audit_hostname_can_not_be_empty_when_editing_audit_instance()
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
HostName = string.Empty
};
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
Assert.That(notifyErrorInfo.GetErrors(nameof(viewModel.HostName)), Is.Not.Empty);
}
[Test]
public void Audit_hostname_can_not_be_null_when_editing_audit_instance()
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
ServiceControlAudit =
{
HostName = null
}
};
viewModel.NotifyOfPropertyChange(nameof(viewModel.HostName));
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
Assert.That(notifyErrorInfo.GetErrors(nameof(viewModel.HostName)), Is.Not.Empty);
}
[TestCase("192.168.1.1")]
[TestCase("256.0.0.0")]
[TestCase("::1")]
[TestCase("2001:0db8:85a3:0000:0000:8a2e:0370:7334")]
public void Audit_hostname_can_be_an_ip_address_when_editing_an_audit_instance(string ipAddress)
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
HostName = ipAddress
};
viewModel.NotifyOfPropertyChange(nameof(viewModel.HostName));
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
Assert.That(notifyErrorInfo.GetErrors(nameof(viewModel.HostName)), Is.Empty);
}
[TestCase("hostname with spaces")]
[TestCase("bad@hostname")]
[TestCase("bad#hostname")]
[TestCase("badhostname...")]
[TestCase("badhostname[/")]
public void Audit_hostname_cannot_contain_invalid_characters_when_editing_audit_instance(string invalidHostname)
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
HostName = invalidHostname
};
viewModel.NotifyOfPropertyChange(nameof(viewModel.HostName));
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.HostName));
Assert.Multiple(() =>
{
Assert.That(errors, Is.Not.Empty, "Hostname validation should exist and trigger for invalid hostnames");
Assert.That(errors.Cast<string>().Any(error => error.Contains("Hostname is not valid")), Is.True,
"Hostname validation should display the exact error message 'Hostname is not valid'");
});
}
#endregion
#region Portnumber
[Test]
public void Port_cannot_be_empty_when_editing_audit_instance()
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
PortNumber = null
};
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.PortNumber));
Assert.That(errors, Is.Not.Empty);
}
[Test]
public void Port_is_not_in_valid_range_when_editing_audit_instance()
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
PortNumber = "50000"
};
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.PortNumber));
Assert.That(errors, Is.Not.Empty);
}
[Test]
[Explicit]
public void Port_can_not_be_a_port_in_use_by_the_operating_system_when_editing_audit_instance()
{
//port is unique and should not be used in any other instance (audit or error) and any other windows service
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
ServiceControlAudit =
{
PortNumber = "33333"
}
};
viewModel.NotifyOfPropertyChange(nameof(viewModel.PortNumber));
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.PortNumber));
Assert.That(errors, Is.Not.Empty);
}
[Test]
public void Audit_port_is_not_equal_to_database_port_number_when_editing_audit_instance()
{
//port is unique and should not be used in any other instance (audit or error) and any other windows service
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
DatabaseMaintenancePortNumber = "33333",
PortNumber = "33333"
};
viewModel.NotifyOfPropertyChange(nameof(viewModel.PortNumber));
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.PortNumber));
Assert.That(errors, Is.Not.Empty);
}
#endregion
#region DatabaseManintenancePortnumber
[Test]
public void Database_maintenance_port_cannot_be_empty_when_editing_audit_instance()
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
DatabaseMaintenancePortNumber = null
};
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.DatabaseMaintenancePortNumber));
Assert.That(errors, Is.Not.Empty);
}
[Test]
public void Database_maintenance_port_is_not_in_valid_range_when_editing_audit_instance()
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
DatabaseMaintenancePortNumber = "50000"
};
viewModel.NotifyOfPropertyChange(null);
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.DatabaseMaintenancePortNumber));
Assert.That(errors, Is.Not.Empty);
}
[Test]
[Explicit]
public void Database_maintenance_port_can_not_be_a_port_in_use_by_the_operating_system_when_editing_audit_instance()
{
//port is unique and should not be used in any other instance (audit or error) and any other windows service
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
DatabaseMaintenancePortNumber = "33333"
};
viewModel.NotifyOfPropertyChange(null);
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.DatabaseMaintenancePortNumber));
Assert.That(errors, Is.Not.Empty);
}
[Test]
public void Audit_database_maintenance_port_is_not_equal_to_port_number_when_editing_audit_instance()
{
//port is unique and should not be used in any other instance (audit or error) and any other windows service
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
PortNumber = "33333",
DatabaseMaintenancePortNumber = "33333",
};
viewModel.NotifyOfPropertyChange(nameof(viewModel.DatabaseMaintenancePortNumber));
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.DatabaseMaintenancePortNumber));
Assert.That(errors, Is.Not.Empty);
}
#endregion
#region auditinstancelogpath
[Test]
public void Audit_log_path_cannot_be_empty_when_editing_audit_instance()
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
LogPath = string.Empty
};
viewModel.NotifyOfPropertyChange(nameof(viewModel.LogPath));
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
Assert.That(notifyErrorInfo.GetErrors(nameof(viewModel.LogPath)), Is.Not.Empty);
}
[TestCase(@"<")]
[TestCase(@">")]
[TestCase(@"|")]
[TestCase(@"?")]
[TestCase(@"*")]
public void Audit_log_path_should_not_contain_invalid_characters_when_editing_audit_instance(string path)
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
LogPath = path
};
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
Assert.That(notifyErrorInfo.GetErrors(nameof(viewModel.LogPath)), Is.Not.Empty);
}
#endregion
#region auditqueuename
[Test]
public void Audit_queue_name_should_not_be_empty_when_editing_audit_instance()
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
AuditQueueName = string.Empty
};
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
Assert.That(notifyErrorInfo.GetErrors(nameof(viewModel.AuditQueueName)), Is.Not.Empty);
}
[Test]
public void Audit_queue_name_can_not_be_null_when_editing_audit_instance()
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
AuditQueueName = null
};
viewModel.NotifyOfPropertyChange(nameof(viewModel.AuditQueueName));
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
Assert.That(notifyErrorInfo.GetErrors(nameof(viewModel.AuditQueueName)), Is.Not.Empty);
}
#endregion
#region errorforwardingqueuename
[Test]
public void Audit_forwarding_queue_name_should_not_be_null_if_audit_forwarding_enabled_when_editing_audit_instance()
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
AuditForwarding = new ForwardingOption() { Name = "On", Value = true },
AuditForwardingQueueName = null
};
viewModel.NotifyOfPropertyChange(nameof(viewModel.AuditForwardingQueueName));
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.AuditForwardingQueueName));
Assert.That(errors, Is.Not.Empty);
}
[Test]
public void Audit_forwarding_queue_name_can_not_be_empty_if_audit_forwarding_enabled_when_editing_audit_instance()
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
AuditForwarding = new ForwardingOption() { Name = "On", Value = true },
AuditForwardingQueueName = string.Empty
};
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.AuditForwardingQueueName));
Assert.That(errors, Is.Not.Empty);
}
[Test]
public void Audit_forwarding_queue_name_can_be_empty_if_audit_forwarding_not_enabled_when_editing_audit_instance()
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
AuditForwarding = new ForwardingOption() { Name = "Off", Value = false },
AuditForwardingQueueName = string.Empty
};
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.AuditForwardingQueueName));
Assert.That(errors, Is.Empty);
}
[Test]
public void Audit_forwarding_queue_name_can_be_null_if_audit_forwarding_not_enabled_when_editing_audit_instance()
{
var viewModel = new ServiceControlAuditEditViewModel
{
SubmitAttempted = true,
AuditForwarding = new ForwardingOption() { Name = "Off", Value = false },
AuditForwardingQueueName = null
};
viewModel.NotifyOfPropertyChange(viewModel.AuditForwardingQueueName);
var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.AuditForwardingQueueName));
Assert.That(errors, Is.Empty);
}
#endregion
public IDataErrorInfo GetErrorInfo(object vm) => vm as IDataErrorInfo;
public INotifyDataErrorInfo GetNotifyErrorInfo(object vm) => vm as INotifyDataErrorInfo;
}
}