/
ADTest.cs
386 lines (356 loc) · 13.9 KB
/
ADTest.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
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
/**
* Copyright 2008-2014 Mohawk College of Applied Arts and Technology
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may
* obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* User: fyfej
* Date: 3-6-2013
*/
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MARC.Everest.DataTypes;
namespace MARC.Everest.Test.DataTypes
{
/// <summary>
/// Summary description for ADTest
/// </summary>
[TestClass]
public class ADTest
{
public ADTest()
{
//
// TODO: Add constructor logic here
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
/// <summary>
/// Tests that AD (A) does not equal a string A
/// </summary>
[TestMethod]
public void ADTypeMismatchEqualityTest()
{
AD a = new AD(
new ADXP[] {
new ADXP("123 Main Street West Hamilton ON")
}
);
Assert.IsFalse(a.Equals("123 Main Street West Hamilton ON"));
}
/// <summary>
/// Tests that AD (A) equals AD (B)
/// </summary>
[TestMethod]
public void ADContentSameEqualityTest()
{
AD a = new AD(
new ADXP[] {
new ADXP("123 Main Street West Hamilton ON")
}
), b = new AD(new ADXP[] {
new ADXP("123 Main Street West Hamilton ON")
}
);
Assert.IsTrue(a.Equals(b));
Assert.IsTrue(a.Equals((object)b));
}
/// <summary>
/// Tests that AD (A) does not equal AD (B) with a different address
/// </summary>
[TestMethod]
public void ADContentDifferentEqualityTest()
{
AD a = new AD(
new ADXP[] {
new ADXP("123 Main Street West Hamilton ON")
}
), b = new AD(new ADXP[] {
new ADXP("123 Main Street West Hamilton")
}
);
Assert.IsFalse(a.Equals(b));
}
/// <summary>
/// Test the AD tostring method with no parameters
/// </summary>
[TestMethod]
public void ADToStringTest()
{
AD a = new AD(
new ADXP[] {
new ADXP("123", AddressPartType.BuildingNumber),
new ADXP("Main", AddressPartType.StreetName),
new ADXP("Street", AddressPartType.StreetType),
new ADXP("West", AddressPartType.Direction)
});
Assert.AreEqual(a.ToString(), "123MainStreetWest");
}
/// <summary>
/// Ensures that validation succeeds (return TRUE)
/// When the following values are being populated:
/// NullFlavor
/// And, there are no nullified variables.
/// </summary>
[TestMethod]
public void ADNullFlavorTest()
{
AD ad = new AD();
ad.NullFlavor = NullFlavor.NotAsked;
Assert.IsTrue(ad.Validate());
}
/// <summary>
/// Ensures that validation succeeds (return TRUE)
/// When the following values are being populated:
/// Part : The parts to create
/// And, the following values are nullified.
/// NullFlavor
/// </summary>
[TestMethod]
public void ADPartTest()
{
AD ad = new AD();
ad.Part.AddRange(GenerateAddress());
ad.NullFlavor = null;
Assert.IsTrue(ad.Validate());
}
/// <summary>
/// Ensures that validation fails (return FALSE)
/// When there are no populated variables:
/// And, the following values are nullified.
/// NullFlavor
/// </summary>
[TestMethod]
public void ADNullTest()
{
AD ad = new AD();
ad.NullFlavor = null;
Assert.IsFalse(ad.Validate());
}
/// <summary>
/// Ensures that validation fails (return FALSE)
/// When the following values are being populated:
/// Part : The parts to create
/// NullFlavor
/// And, there are no nullified variables.
/// </summary>
[TestMethod]
public void ADPartNullFlavorTest()
{
AD ad = new AD();
ad.Part.AddRange(GenerateAddress());
ad.NullFlavor = NullFlavor.NotApplicable;
Assert.IsFalse(ad.Validate());
}
/// <summary>
/// Generates the part types for the address: 123 Fake Street Door 1, Anytown, AnyCounty, Ontario, Canada
/// </summary>
/// <returns>a List of ADXP containing the address.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
private List<ADXP> GenerateAddress()
{
List<ADXP> result = new List<ADXP>();
result.Add(new ADXP("123", AddressPartType.BuildingNumber));
result.Add(new ADXP("Fake", AddressPartType.StreetNameBase));
result.Add(new ADXP("Street", AddressPartType.StreetType));
result.Add(new ADXP("1", AddressPartType.UnitIdentifier));
result.Add(new ADXP("Door", AddressPartType.UnitDesignator));
result.Add(new ADXP("Anytown", AddressPartType.City));
result.Add(new ADXP("AnyCounty", AddressPartType.County));
result.Add(new ADXP("Ontario", AddressPartType.State));
result.Add(new ADXP("Canada", AddressPartType.County));
return result;
}
/// <summary>
/// Ensures that validation fails (return FALSE)
/// When the following values are being populated:
/// A List of ADXP containing the address
/// NullFlavor
/// And, there are no nullified variables.
/// </summary>
[TestMethod]
public void ADNullFlavorValidationTest()
{
AD ad = new AD(new ADXP[] {new ADXP("123", AddressPartType.BuildingNumber)});
ad.NullFlavor = NullFlavor.Invalid;
Assert.IsFalse(ad.Validate());
}
/// <summary>
/// Ensures that validation fails (return FALSE)
/// When the following values are being populated:
/// Part where a value of ADXP is being added
/// NullFlavor
/// And, there are no nullified variables.
/// </summary>
[TestMethod]
public void ADPartNullFlavorValidationTest()
{
AD ad = new AD();
ad.NullFlavor = NullFlavor.Invalid;
ad.Part.Add(new ADXP("hello"));
Assert.IsFalse(ad.Validate());
}
/// <summary>
/// Tests the PostalAddressUse/IEnumerable<ADXP> constructor.
/// Add a PostalAddressUse and 4 Address Parts to an AD object in the constructor.
///
/// Expected Result: AD object with 1 PostalAddressUse and 4 Address Parts.
/// /// </summary>
[TestMethod]
public void ADPostalAddressUseIEnumerableADXP_CTORTest()
{
AD ctorPostalAddressUseAndADXPArray =
new AD(
PostalAddressUse.Direct,
new ADXP[]
{
new ADXP("Street",AddressPartType.StreetType),
new ADXP("Main",AddressPartType.StreetName),
new ADXP("122",AddressPartType.BuildingNumber),
new ADXP("Hamilton",AddressPartType.City)
}
);
// True if the the AD object has 4 address parts and 1 postal address use.
Assert.IsTrue(ctorPostalAddressUseAndADXPArray.Part.Count == 4 && ctorPostalAddressUseAndADXPArray.Use.Count == 1);
}
/// <summary>
/// Tests the SET<PostalAddressUse>, IEnumerable<ADXP> constructor.
/// Add 2 PostalAddressUses and 4 Address Parts to an AD object in the constructor.
///
/// Expected result: AD Object with 2 PostalAddressUses and 4 AddressParts.
/// </summary>
[TestMethod]
public void ADSETPostalAddressUseIEnumerableADXP_CTORTest()
{
AD ctorPostalAddressUseAndADXPArray =
new AD(
new SET<CS<PostalAddressUse>>(
new CS<PostalAddressUse>[]
{
PostalAddressUse.HomeAddress,
PostalAddressUse.Direct
},CS<PostalAddressUse>.Comparator
),
new ADXP[]
{
new ADXP("Street",AddressPartType.StreetType),
new ADXP("Main",AddressPartType.StreetName),
new ADXP("122",AddressPartType.BuildingNumber),
new ADXP("Hamilton",AddressPartType.City)
}
);
Assert.AreEqual(ctorPostalAddressUseAndADXPArray.Part.Count ,4);
Assert.AreEqual(ctorPostalAddressUseAndADXPArray.Use.Count ,2);
}
/// <summary>
/// Tests the AD.Basic() static method, which validates the AD object to see if it is a
/// BASIC flavored AD. Basic flavor is defined as "City, Province".
///
/// Expected result: AD.Basic returning False.
/// </summary>
[TestMethod]
public void ADInvalidADBasicFlavorTest()
{
AD invalidBasicFlavorTest = new AD();
invalidBasicFlavorTest.Part.Add(new ADXP("Hamilton",AddressPartType.City));
invalidBasicFlavorTest.Part.Add(new ADXP("Ontario",AddressPartType.State));
invalidBasicFlavorTest.Part.Add(new ADXP("Main Street",AddressPartType.StreetType));
Assert.IsFalse(AD.IsValidBasicFlavor(invalidBasicFlavorTest));
}
/// <summary>
/// Tests the AD.Basic() static method, which validates the AD object to see if it is a
/// BASIC flavored AD. Basic flavor is defined as "City, Province".
///
/// Expected result: AD.Basic returning False.
/// </summary>
[TestMethod]
public void ADValidADBasicFlavorTest()
{
AD invalidBasicFlavorTest = new AD();
invalidBasicFlavorTest.Part.Add(new ADXP("Hamilton", AddressPartType.City));
invalidBasicFlavorTest.Part.Add(new ADXP("Ontario", AddressPartType.State));
Assert.IsTrue(AD.IsValidBasicFlavor(invalidBasicFlavorTest));
}
/// <summary>
/// Tests the .ToString() method for proper formatting.
/// Given a formatted string, the .ToString() method should
/// return an appropriately formatted output.
///
/// Expected Result: "Hamilton Ontario CA"
/// </summary>
[TestMethod]
public void ADToStringCorrectTest()
{
AD toStringValid = new AD(
new ADXP[]
{
new ADXP("Hamilton",AddressPartType.City),
new ADXP("Ontario", AddressPartType.State),
new ADXP("CA",AddressPartType.Country)
}
);
Assert.AreEqual("Hamilton Ontario CA", toStringValid.ToString("{CTY}{STA}{CNT}"));
}
/// <summary>
/// Tests the IsNull property of the ANY Datatype.
/// If the NullFlavor is set, the isNull property should be true.
///
/// Expected Result: "True"
/// </summary>
[TestMethod]
public void ANYIsNullTest()
{
AD isNull = new AD();
isNull.NullFlavor = NullFlavor.AskedUnknown;
Assert.AreEqual(true, isNull.IsNull);
}
}
}