|
@@ -21,6 +21,27 @@ |
21 |
21 |
|
/// </summary> |
22 |
22 |
|
private const int JohnSmithContactId = 39547555; |
23 |
23 |
|
|
|
24 |
+ |
private static IApi _api; |
|
25 |
+ |
|
|
26 |
+ |
/// <summary> |
|
27 |
+ |
/// Test class initialise. |
|
28 |
+ |
/// </summary> |
|
29 |
+ |
/// <param name="context">The context.</param> |
|
30 |
+ |
[ClassInitialize] |
|
31 |
+ |
public static void ContactTestsInitialise(TestContext context) |
|
32 |
+ |
{ |
|
33 |
+ |
_api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
|
34 |
+ |
} |
|
35 |
+ |
|
|
36 |
+ |
/// <summary> |
|
37 |
+ |
/// Test class cleanup. |
|
38 |
+ |
/// </summary> |
|
39 |
+ |
[ClassCleanup] |
|
40 |
+ |
public static void ContactTestsCleanup() |
|
41 |
+ |
{ |
|
42 |
+ |
_api = null; |
|
43 |
+ |
} |
|
44 |
+ |
|
24 |
45 |
|
#region Get |
25 |
46 |
|
|
26 |
47 |
|
/// <summary> |
|
@@ -52,9 +73,7 @@ |
52 |
73 |
|
[TestMethod] |
53 |
74 |
|
public void GetJohnSmithForCRMContactId() |
54 |
75 |
|
{ |
55 |
|
- |
InsightlyAPI api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
56 |
|
- |
|
57 |
|
- |
var contact = api.GetContact(JohnSmithContactId); |
|
76 |
+ |
var contact = _api.GetContact(JohnSmithContactId); |
58 |
77 |
|
|
59 |
78 |
|
Assert.IsNotNull(contact); |
60 |
79 |
|
Assert.IsInstanceOfType(contact, typeof(Contact)); |
|
@@ -68,9 +87,8 @@ |
68 |
87 |
|
public void GetJohnSmithForEmailAddress() |
69 |
88 |
|
{ |
70 |
89 |
|
const string contactEmail = "johnsmith@smith.net"; |
71 |
|
- |
IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
72 |
90 |
|
|
73 |
|
- |
var contacts = api.GetContactsForEmail(contactEmail); |
|
91 |
+ |
var contacts = _api.GetContactsForEmail(contactEmail); |
74 |
92 |
|
|
75 |
93 |
|
Assert.IsNotNull(contacts); |
76 |
94 |
|
Assert.IsInstanceOfType(contacts, typeof(List<Contact>)); |
|
@@ -95,9 +113,8 @@ |
95 |
113 |
|
public void GetForNonExistentEmailAddress() |
96 |
114 |
|
{ |
97 |
115 |
|
const string contactEmail = "abcde@123.net"; |
98 |
|
- |
IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
99 |
116 |
|
|
100 |
|
- |
var contacts = api.GetContactsForEmail(contactEmail); |
|
117 |
+ |
var contacts = _api.GetContactsForEmail(contactEmail); |
101 |
118 |
|
|
102 |
119 |
|
Assert.IsNotNull(contacts); |
103 |
120 |
|
Assert.IsTrue(contacts.Count == 0); |
|
@@ -109,9 +126,7 @@ |
109 |
126 |
|
[TestMethod] |
110 |
127 |
|
public void GetPostalAddressForJohnSmith() |
111 |
128 |
|
{ |
112 |
|
- |
IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
113 |
|
- |
|
114 |
|
- |
var contact = api.GetContact(JohnSmithContactId); |
|
129 |
+ |
var contact = _api.GetContact(JohnSmithContactId); |
115 |
130 |
|
|
116 |
131 |
|
Assert.IsNotNull(contact); |
117 |
132 |
|
Assert.IsInstanceOfType(contact, typeof(Contact)); |
|
@@ -130,9 +145,7 @@ |
130 |
145 |
|
[TestMethod] |
131 |
146 |
|
public void GetCustomField1ForJohnSmith() |
132 |
147 |
|
{ |
133 |
|
- |
IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
134 |
|
- |
|
135 |
|
- |
var contact = api.GetContact(JohnSmithContactId); |
|
148 |
+ |
var contact = _api.GetContact(JohnSmithContactId); |
136 |
149 |
|
|
137 |
150 |
|
Assert.IsNotNull(contact); |
138 |
151 |
|
Assert.AreEqual("Custom Country Field (One)", contact.CONTACT_FIELD_1); |
|
@@ -149,7 +162,6 @@ |
149 |
162 |
|
public void AddBasicContactRecord() |
150 |
163 |
|
{ |
151 |
164 |
|
Contact addedContact = null; |
152 |
|
- |
IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
153 |
165 |
|
|
154 |
166 |
|
try |
155 |
167 |
|
{ |
|
@@ -158,7 +170,7 @@ |
158 |
170 |
|
newContact.FIRST_NAME = "Mary"; |
159 |
171 |
|
newContact.LAST_NAME = "Jones"; |
160 |
172 |
|
|
161 |
|
- |
addedContact = api.AddNewContact(newContact); |
|
173 |
+ |
addedContact = _api.AddNewContact(newContact); |
162 |
174 |
|
|
163 |
175 |
|
Assert.IsNotNull(addedContact); |
164 |
176 |
|
Assert.AreEqual(newContact.SALUTATION, addedContact.SALUTATION); |
|
@@ -167,7 +179,7 @@ |
167 |
179 |
|
} |
168 |
180 |
|
finally |
169 |
181 |
|
{ |
170 |
|
- |
DeleteContact(api, addedContact); |
|
182 |
+ |
DeleteContact(addedContact); |
171 |
183 |
|
} |
172 |
184 |
|
} |
173 |
185 |
|
|
|
@@ -178,7 +190,6 @@ |
178 |
190 |
|
public void AddContactWithEmailAddress() |
179 |
191 |
|
{ |
180 |
192 |
|
Contact addedContact = null; |
181 |
|
- |
IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
182 |
193 |
|
|
183 |
194 |
|
try |
184 |
195 |
|
{ |
|
@@ -193,7 +204,7 @@ |
193 |
204 |
|
newContact.LAST_NAME = "Harper"; |
194 |
205 |
|
newContact.CONTACTINFOS = new List<ContactInfo> { newInfo }; |
195 |
206 |
|
|
196 |
|
- |
addedContact = api.AddNewContact(newContact); |
|
207 |
+ |
addedContact = _api.AddNewContact(newContact); |
197 |
208 |
|
|
198 |
209 |
|
Assert.IsNotNull(addedContact); |
199 |
210 |
|
Assert.AreEqual(newContact.LAST_NAME, addedContact.LAST_NAME); |
|
@@ -206,7 +217,7 @@ |
206 |
217 |
|
} |
207 |
218 |
|
finally |
208 |
219 |
|
{ |
209 |
|
- |
DeleteContact(api, addedContact); |
|
220 |
+ |
DeleteContact(addedContact); |
210 |
221 |
|
} |
211 |
222 |
|
} |
212 |
223 |
|
|
|
@@ -217,7 +228,6 @@ |
217 |
228 |
|
public void AddContactWithEmailAndPostalAddress() |
218 |
229 |
|
{ |
219 |
230 |
|
Contact addedContact = null; |
220 |
|
- |
IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
221 |
231 |
|
|
222 |
232 |
|
try |
223 |
233 |
|
{ |
|
@@ -240,7 +250,7 @@ |
240 |
250 |
|
newContact.CONTACTINFOS = new List<ContactInfo> { newInfo }; |
241 |
251 |
|
newContact.ADDRESSES = new List<Address> { newAddress }; |
242 |
252 |
|
|
243 |
|
- |
addedContact = api.AddNewContact(newContact); |
|
253 |
+ |
addedContact = _api.AddNewContact(newContact); |
244 |
254 |
|
|
245 |
255 |
|
Assert.IsNotNull(addedContact); |
246 |
256 |
|
Assert.AreEqual(newContact.LAST_NAME, addedContact.LAST_NAME); |
|
@@ -259,7 +269,7 @@ |
259 |
269 |
|
} |
260 |
270 |
|
finally |
261 |
271 |
|
{ |
262 |
|
- |
DeleteContact(api, addedContact); |
|
272 |
+ |
DeleteContact(addedContact); |
263 |
273 |
|
} |
264 |
274 |
|
} |
265 |
275 |
|
|
|
@@ -270,7 +280,6 @@ |
270 |
280 |
|
public void AddNewContactWithCustomField1() |
271 |
281 |
|
{ |
272 |
282 |
|
Contact addedContact = null; |
273 |
|
- |
IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
274 |
283 |
|
|
275 |
284 |
|
try |
276 |
285 |
|
{ |
|
@@ -279,13 +288,13 @@ |
279 |
288 |
|
newContact.LAST_NAME = "Custom Field 1"; |
280 |
289 |
|
newContact.CONTACT_FIELD_1 = "Custom Field Text"; |
281 |
290 |
|
|
282 |
|
- |
addedContact = api.AddNewContact(newContact); |
|
291 |
+ |
addedContact = _api.AddNewContact(newContact); |
283 |
292 |
|
|
284 |
293 |
|
Assert.AreEqual(newContact.CONTACT_FIELD_1, addedContact.CONTACT_FIELD_1); |
285 |
294 |
|
} |
286 |
295 |
|
finally |
287 |
296 |
|
{ |
288 |
|
- |
DeleteContact(api, addedContact); |
|
297 |
+ |
DeleteContact(addedContact); |
289 |
298 |
|
} |
290 |
299 |
|
} |
291 |
300 |
|
|
|
@@ -295,8 +304,6 @@ |
295 |
304 |
|
[TestMethod] |
296 |
305 |
|
public void DoNotAddExistingContact() |
297 |
306 |
|
{ |
298 |
|
- |
IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
299 |
|
- |
|
300 |
307 |
|
ContactInfo newInfo = new ContactInfo(); |
301 |
308 |
|
newInfo.TYPE = ContactInfo.InfoType.Email.GetDescription(); |
302 |
309 |
|
newInfo.LABEL = ContactInfo.InfoLabelEmail.Work.GetDescription(); |
|
@@ -307,7 +314,7 @@ |
307 |
314 |
|
newContact.LAST_NAME = "Smith"; |
308 |
315 |
|
newContact.CONTACTINFOS = new List<ContactInfo> { newInfo }; |
309 |
316 |
|
|
310 |
|
- |
var addResult = api.AddNewContactIfNotExists(newContact); |
|
317 |
+ |
var addResult = _api.AddNewContactIfNotExists(newContact); |
311 |
318 |
|
|
312 |
319 |
|
Assert.IsFalse(addResult.NewContactAdded); |
313 |
320 |
|
|
|
@@ -320,7 +327,6 @@ |
320 |
327 |
|
public void AddBasicContactRecordUsingExistsCheck() |
321 |
328 |
|
{ |
322 |
329 |
|
Contact addedContact = null; |
323 |
|
- |
IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
324 |
330 |
|
|
325 |
331 |
|
try |
326 |
332 |
|
{ |
|
@@ -335,7 +341,7 @@ |
335 |
341 |
|
newContact.LAST_NAME = "Jones"; |
336 |
342 |
|
newContact.CONTACTINFOS = new List<ContactInfo> { newInfo }; |
337 |
343 |
|
|
338 |
|
- |
var addResult = api.AddNewContactIfNotExists(newContact); |
|
344 |
+ |
var addResult = _api.AddNewContactIfNotExists(newContact); |
339 |
345 |
|
|
340 |
346 |
|
Assert.IsTrue(addResult.NewContactAdded); |
341 |
347 |
|
|
|
@@ -347,7 +353,7 @@ |
347 |
353 |
|
} |
348 |
354 |
|
finally |
349 |
355 |
|
{ |
350 |
|
- |
DeleteContact(api, addedContact); |
|
356 |
+ |
DeleteContact(addedContact); |
351 |
357 |
|
} |
352 |
358 |
|
} |
353 |
359 |
|
|
|
@@ -358,9 +364,7 @@ |
358 |
364 |
|
[ExpectedException(typeof(ContactException))] |
359 |
365 |
|
public void ContactExceptionWhenInvalidAdd() |
360 |
366 |
|
{ |
361 |
|
- |
IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
362 |
|
- |
|
363 |
|
- |
api.AddNewContact(null); |
|
367 |
+ |
_api.AddNewContact(null); |
364 |
368 |
|
} |
365 |
369 |
|
|
366 |
370 |
|
#endregion Post |
|
@@ -378,18 +382,16 @@ |
378 |
382 |
|
[TestMethod] |
379 |
383 |
|
public void DeleteExistingContact() |
380 |
384 |
|
{ |
381 |
|
- |
IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
382 |
|
- |
|
383 |
385 |
|
Contact newContact = new Contact(); |
384 |
386 |
|
newContact.SALUTATION = "Dr"; |
385 |
387 |
|
newContact.FIRST_NAME = "Temp"; |
386 |
388 |
|
newContact.LAST_NAME = "Delete"; |
387 |
389 |
|
|
388 |
|
- |
Contact addedContact = api.AddNewContact(newContact); |
|
390 |
+ |
Contact addedContact = _api.AddNewContact(newContact); |
389 |
391 |
|
|
390 |
392 |
|
Assert.IsNotNull(addedContact, "Failed to add contact to test delete!"); |
391 |
393 |
|
|
392 |
|
- |
bool deleteResult = api.DeleteContact(addedContact.CONTACT_ID); |
|
394 |
+ |
bool deleteResult = _api.DeleteContact(addedContact.CONTACT_ID); |
393 |
395 |
|
|
394 |
396 |
|
Assert.IsTrue(deleteResult); |
395 |
397 |
|
} |
|
@@ -400,9 +402,7 @@ |
400 |
402 |
|
[TestMethod] |
401 |
403 |
|
public void DeleteNonExistentContact() |
402 |
404 |
|
{ |
403 |
|
- |
IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY); |
404 |
|
- |
|
405 |
|
- |
bool deleteResult = api.DeleteContact(1); |
|
405 |
+ |
bool deleteResult = _api.DeleteContact(1); |
406 |
406 |
|
|
407 |
407 |
|
Assert.IsFalse(deleteResult); |
408 |
408 |
|
} |
|
@@ -412,15 +412,14 @@ |
412 |
412 |
|
/// <summary> |
413 |
413 |
|
/// Deletes the contact. |
414 |
414 |
|
/// </summary> |
415 |
|
- |
/// <param name="api">The API.</param> |
416 |
415 |
|
/// <param name="contact">The contact.</param> |
417 |
|
- |
private void DeleteContact(IApi api, Contact contact) |
|
416 |
+ |
private void DeleteContact(Contact contact) |
418 |
417 |
|
{ |
419 |
418 |
|
try |
420 |
419 |
|
{ |
421 |
420 |
|
if (contact != null && contact.CONTACT_ID > 0) |
422 |
421 |
|
{ |
423 |
|
- |
api.DeleteContact(contact.CONTACT_ID); |
|
422 |
+ |
_api.DeleteContact(contact.CONTACT_ID); |
424 |
423 |
|
} |
425 |
424 |
|
} |
426 |
425 |
|
catch (Exception) |