-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tests.cs
205 lines (177 loc) · 6.47 KB
/
Tests.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
/*
*/
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace LicensePlates
{
[TestClass]
public class Tests
{
private IRegistrationService[] _services;
public Tests()
{
_services = new IRegistrationService[] {
new NoPattern.RegistrationService(new FakeLicensePlateRepository()) ,
new NoPattern2.RegistrationService(new FakeLicensePlateRepository()) ,
new Factory.RegistrationService(new FakeLicensePlateRepository()) ,
new Static.RegistrationService(new FakeLicensePlateRepository()) ,
new RuleEngine.RegistrationService(new FakeLicensePlateRepository()) ,
new ChainOfResponsibility.RegistrationService(new FakeLicensePlateRepository()) ,
};
}
// NORMAL CUSTOMER
[TestMethod]
[DataRow("ABC 123")]
[DataRow("ABC 12B")] // (last character may be a letter)
public void return_Success_when_plate_has_correct_format(string plate)
{
foreach (var service in _services)
{
Assert.AreEqual(Result.Success, service.AddLicensePlate(plate, CustomerType.Normal));
}
}
[TestMethod]
[DataRow("ABC X23")]
[DataRow("ÅBC 123")] // Å is a swedish letter but not a valid letter anyway
[DataRow("QBC 123")] // Q is not a valid letter (too similair to O)
[DataRow("1BC 123")]
[DataRow("ABC 123")]
public void return_InvalidFormat_when_format_is_incorrect(string plate)
{
foreach (var service in _services)
{
var result = service.AddLicensePlate(plate, CustomerType.Normal);
Assert.AreEqual(Result.InvalidFormat, result);
}
}
[TestMethod]
[DataRow("MLB 123")]
[DataRow("MLB 456")]
public void return_InvalidFormat_when_non_advertisment_try_register_plate_starting_with_MLB(string plate)
{
foreach (var service in _services)
{
var result = service.AddLicensePlate(plate, CustomerType.Normal);
Assert.AreEqual(Result.InvalidFormat, result);
}
}
[TestMethod]
[DataRow("ABC 12T")]
[DataRow("CCC 77T")]
public void return_InvalidFormat_when_plate_ends_with_T_and_customer_isnot_taxi(string plate)
{
foreach (var service in _services)
{
var result = service.AddLicensePlate(plate, CustomerType.Normal);
Assert.AreEqual(Result.InvalidFormat, result);
}
}
[TestMethod]
public void return_NotAvailable_when_plate_is_already_registered()
{
foreach (var service in _services)
{
service.AddLicensePlate("ABC 123", CustomerType.Normal);
var result = service.AddLicensePlate("ABC 123", CustomerType.Normal);
Assert.AreEqual(Result.NotAvailable, result);
}
}
// ADVERTISMENT CUSTOMER
[TestMethod]
[DataRow("ABC 123")]
[DataRow("ABC 12B")]
[DataRow("MLB 123")]
[DataRow("MLB 456")]
public void return_Success_when_plate_has_correct_format_for_advertisment(string plate)
{
foreach (var service in _services)
{
var result = service.AddLicensePlate(plate, CustomerType.Advertisment);
Assert.AreEqual(Result.Success, result);
}
}
[TestMethod]
[DataRow("ABC X23")]
[DataRow("ÅBC 123")]
[DataRow("QBC 123")]
[DataRow("1BC 123")]
[DataRow("ABC 123")]
public void return_InvalidFormat_when_format_is_incorrect_for_advertisment(string plate)
{
foreach (var service in _services)
{
var result = service.AddLicensePlate(plate, CustomerType.Normal);
Assert.AreEqual(Result.InvalidFormat, result);
}
}
// TAXI CUSTOMER
[DataRow("ABC 12T")]
[DataRow("CCC 77T")]
public void return_Success_when_plate_has_correct_format_for_taxi(string plate)
{
foreach (var service in _services)
{
Assert.AreEqual(Result.Success, service.AddLicensePlate(plate, CustomerType.Taxi));
}
}
[TestMethod]
[DataRow("ABC X23")]
[DataRow("ÅBC 123")]
[DataRow("QBC 123")]
[DataRow("1BC 123")]
[DataRow("ABC 123")]
public void return_InvalidFormat_when_format_is_incorrect_for_taxi(string plate)
{
foreach (var service in _services)
{
var result = service.AddLicensePlate(plate, CustomerType.Taxi);
Assert.AreEqual(Result.InvalidFormat, result);
}
}
// DIPLOMAT
/*
First two letters: country code
Three numbers: the embassy's serial number
Last letter: the ambassadors rank
*/
[TestMethod]
[DataRow("AA 111 A")]
[DataRow("CD 777 X")]
public void return_Success_when_plate_has_correct_format_for_diplomats(string plate)
{
foreach (var service in _services)
{
Assert.AreEqual(Result.Success, service.AddLicensePlate(plate, CustomerType.Diplomat));
}
}
[TestMethod]
[DataRow("ABC 123")]
[DataRow("ABC 12B")]
[DataRow("A8 111 A")]
[DataRow("CD A77 X")]
public void return_InvalidFormat_when_format_is_incorrect_for_diplomat(string plate)
{
foreach (var service in _services)
{
var result = service.AddLicensePlate(plate, CustomerType.Diplomat);
Assert.AreEqual(Result.InvalidFormat, result);
}
}
// EXCEPTIONS
[TestMethod]
public void throw_RepositoryException_when_unexpected_problem_with_database()
{
foreach (var service in _services)
{
Assert.ThrowsException<RepositoryException>(() =>
{
service.AddLicensePlate("XXX 666", CustomerType.Normal);
});
Assert.ThrowsException<RepositoryException>(() =>
{
service.AddLicensePlate("YYY 666", CustomerType.Normal);
});
}
}
}
}