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
142
143
144
145
146
147
148
149
150
151
152
153
´╗┐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;

        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

        /// <summary>
        /// Test returns organisation record smith enterprises for CRM organisation unique identifier.
        /// </summary>
        [TestMethod]
        public void GetSmithEnterprisesForCRMOrganisationId()
        {
            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()
        {
            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()
        {
            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()
        {
            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;

            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(addedOrg);
            }
        }

        #endregion Post

        #region Put



        #endregion Put

        #region Delete

        #endregion Delete

        /// <summary>
        /// Deletes the organisation.
        /// </summary>
        /// <param name="organisation">The organisation.</param>
        private void DeleteOrganisation(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
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.