Subversion Repository Public Repository

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
´╗┐using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TS.Insightly.API;
using TS.Insightly.API.Contract;
using TS.Insightly.API.Interface;

namespace UnitTestInsightly
{
    [TestClass]
    public class ContactOrganisationTests
    {
        private static IApi _api;

        /// <summary>
        /// Test class initialise.
        /// </summary>
        /// <param name="context">The context.</param>
        [ClassInitialize]
        public static void ContactTestsInitialise(TestContext context)
        {
            _api = new InsightlyAPI(APIUser.PLAIN_API_KEY);
        }

        /// <summary>
        /// Test class cleanup.
        /// </summary>
        [ClassCleanup]
        public static void ContactTestsCleanup()
        {
            _api = null;
        }

        #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()
        {
            //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(addedContact);
            //}
        }

        #endregion Post

        #region Put



        #endregion Put

        #region Delete

        #endregion Delete

        /// <summary>
        /// Deletes the contact.
        /// </summary>
        /// <param name="contact">The contact.</param>
        private void DeleteContact(Contact contact)
        {
            try
            {
                if (contact != null && contact.CONTACT_ID > 0)
                {
                    _api.DeleteContact(contact.CONTACT_ID);
                }
            }
            catch (Exception)
            {
                // Ignore any error.
            }
        }

    }
}

Commits for insightly-api/trunk/UnitTestInsightly/ContactOrganisationTests.cs

Diff revisions: vs.
Revision Author Commited Message
16 Diff Diff HadleyHope picture HadleyHope Tue 01 Oct, 2013 14:59:43 +0000

Refactored unit tests.

15 Diff Diff HadleyHope picture HadleyHope Tue 01 Oct, 2013 13:47:15 +0000

Refactored, added Ninject to load controllers for each part of the API.
InsightlyAPI class is now a true facade for the API.

14 HadleyHope picture HadleyHope Mon 30 Sep, 2013 15:36:43 +0000

Refactor unit tests.
Refactor API use get method to return REST client.