insightly-api
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
|
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TS.Insightly.API;
using TS.Insightly.API.Contract;
namespace UnitTestInsightly
{
[TestClass]
public class ContactOrganisationTests
{
#region Get
#endregion Get
#region Post
/// <summary>
/// Test adding a new contact with an existing organisation set as the default organisation.
/// </summary>
[TestMethod]
public void AddNewContactWithExistingOrganisation()
{
InsightlyAPI api = new InsightlyAPI(APIUser.PLAIN_API_KEY);
const string orgName = "Smith Enterprises";
var orgs = api.GetOrganisationsForName(orgName);
Assert.IsTrue(orgs.Count > 0, "Failed to get organisation to link to new contact");
Contact addedContact = null;
try
{
Contact newContact = new Contact();
newContact.FIRST_NAME = "Mary";
newContact.LAST_NAME = "Jones";
newContact.DEFAULT_LINKED_ORGANISATION = orgs[0].ORGANISATION_ID;
addedContact = api.AddNewContact(newContact);
Assert.IsNotNull(addedContact);
Assert.AreEqual(newContact.FIRST_NAME, addedContact.FIRST_NAME);
Assert.AreEqual(newContact.LAST_NAME, addedContact.LAST_NAME);
Assert.AreEqual(orgs[0].ORGANISATION_ID, addedContact.DEFAULT_LINKED_ORGANISATION);
}
finally
{
DeleteContact(api, addedContact);
}
}
#endregion Post
#region Put
#endregion Put
#region Delete
#endregion Delete
/// <summary>
/// Deletes the contact.
/// </summary>
/// <param name="api">The API.</param>
/// <param name="contact">The contact.</param>
private void DeleteContact(InsightlyAPI api, Contact contact)
{
try
{
if (contact != null && contact.CONTACT_ID > 0)
{
api.DeleteContact(contact.CONTACT_ID);
}
}
catch (Exception)
{
// Ignore any error.
}
}
}
}
|
Revision |
Author |
Commited |
Message |
14
|
HadleyHope
|
Mon 30 Sep, 2013 15:36:43 +0000 |
Refactor unit tests. Refactor API use get method to return REST client. |