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
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
´╗┐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 OrganisationTests
    {
        /// <summary>
        /// Contact ID for the default organisation, which should not be changed for
        /// removed from the CRM.
        /// </summary>
        private const int SmithEnterprisesOrganisationId = 19483007;

        #region Get

        /// <summary>
        /// Test returns organisation record smith enterprises for CRM organisation unique identifier.
        /// </summary>
        [TestMethod]
        public void GetSmithEnterprisesForCRMOrganisationId()
        {
            IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY);

            var organisation = api.GetOrganisation(SmithEnterprisesOrganisationId);

            Assert.IsNotNull(organisation);
            Assert.IsInstanceOfType(organisation, typeof(Organisation));
            Assert.AreEqual(SmithEnterprisesOrganisationId, organisation.ORGANISATION_ID);
        }

        /// <summary>
        /// Test getting the basic organisation details.
        /// </summary>
        [TestMethod]
        public void GetBasicOrganisationDetails()
        {
            IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY);

            var orgs = api.GetOrganisations(false);

            Assert.IsTrue(orgs.Count > 0);
            Assert.IsNull(orgs[0].ADDRESSES);
        }

        /// <summary>
        /// Test getting the full organisation details.
        /// </summary>
        [TestMethod]
        public void GetFullOrganisationDetails()
        {
            IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY);

            var orgs = api.GetOrganisations(true);

            Assert.IsTrue(orgs.Count > 0);
            Assert.IsNotNull(orgs[0].ADDRESSES);
        }

        /// <summary>
        /// Test getting an organisation by name.
        /// </summary>
        [TestMethod]
        public void GetOrganisationByName()
        {
            IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY);
            const string testName = "Smith Enterprises";

            var orgs = api.GetOrganisationsForName(testName);
            Assert.IsTrue(orgs.Count > 0);

            Organisation namedOrg = orgs[0];

            Assert.AreEqual(testName, namedOrg.ORGANISATION_NAME);
        }

        #endregion Get

        #region Post

        /// <summary>
        /// Test writing a very basic organisation record, with just the name set.
        /// </summary>
        [TestMethod]
        public void AddBasicOrganisationRecord()
        {
            Organisation addedOrg = null;
            IApi api = new InsightlyAPI(APIUser.PLAIN_API_KEY);

            try
            {
                Organisation newOrg = new Organisation();
                newOrg.ORGANISATION_NAME = "Kodak Picture Inc.";

                addedOrg = api.AddNewOrganisation(newOrg);

                Assert.IsNotNull(addedOrg);
                Assert.AreEqual(newOrg.ORGANISATION_NAME, addedOrg.ORGANISATION_NAME);
            }
            finally
            {
                DeleteOrganisation(api, addedOrg);
            }
        }

        #endregion Post

        #region Put



        #endregion Put

        #region Delete

        #endregion Delete

        /// <summary>
        /// Deletes the organisation.
        /// </summary>
        /// <param name="api">The API.</param>
        /// <param name="organisation">The organisation.</param>
        private void DeleteOrganisation(IApi api, Organisation organisation)
        {
            try
            {
                if (organisation != null && organisation.ORGANISATION_ID > 0)
                {
                    api.DeleteOrganisation(organisation.ORGANISATION_ID);
                }
            }
            catch (Exception)
            {
                // Ignore any error.
            }
        }
    }
}

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

Diff revisions: vs.
Revision Author Commited Message
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.