public void IntegrationTest_TrackViaClient_FindDomainRecords_ShouldReturnListOfRecords()
        {
            TestHelper.EnsureProductionValuesBeforeRunningIntegrationTests(IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW <= 0);

            // Assemble
            string searchCriteria = "A";
            int    startIndex     = 0;
            int    maxRecords     = 2;

            TrackViaClient client = new TrackViaClient(IntegrationTestConfig.TRACKVIA_HOSTNAME, IntegrationTestConfig.TRACKVIA_USERNAME,
                                                       IntegrationTestConfig.TRACKVIA_PASSWORD, IntegrationTestConfig.TRACKVIA_API_KEY);

            // Act
            DomainRecordSet <TestData.SimpleCrmContact> domainRecordSet = client.findRecords <TestData.SimpleCrmContact>(
                IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW,
                searchCriteria, startIndex, maxRecords);

            // Assert
            domainRecordSet.ShouldNotBeNull();
            domainRecordSet.Data.ShouldNotBeNull()
            .ShouldNotBeEmpty();
            domainRecordSet.Count.ShouldEqual(2);
            // Assert

            for (int i = 0; i < domainRecordSet.Count; i++)
            {
                TestData.SimpleCrmContact Account = domainRecordSet.Data[i];
                Account.ShouldNotBeNull();
                Account.Id.ShouldBeGreaterThan(0);
                Account.AccountName.ShouldNotBeNull().ShouldNotBeEmpty();
                Account.PrimaryContact.ShouldNotBeNull().ShouldNotBeEmpty();
            }
        }
        /// <summary>
        /// Creates a batch of records in a view accessible to the authenticated user.
        /// Record id field will be set to a newly assigned value.
        /// </summary>
        /// <param name="viewId">view identifier in which to create the record batch</param>
        /// <param name="batch">batch one or more records for creation</param>
        /// <returns>both field metadata and record data, as a record set of <T> objects</returns>
        /// <exception cref="TrackViaApiException">if the service fails to process this request</exception>
        /// <exception cref="TrackviaClientException">if an error occurs outside the service, failing the request</exception>
        public DomainRecordSet <T> createRecords <T>(long viewId, DomainRecordDataBatch <T> batch)
        {
            string path = String.Format("{0}/openapi/views/{1}/records", this._baseUriPath, viewId);

            UriBuilder uriBuilder = new UriBuilder()
            {
                Scheme = this._scheme.ToString(),
                Host   = this._hostName,
                Port   = this._port,
                Path   = path,
                Query  = new UriHelper()
                         .SetParameter(ACCESS_TOKEN_QUERY_PARAM, GetAccessToken())
                         .SetParameter(USER_KEY_QUERY_PARAM, GetApiUserKey())
                         .Build()
            };

            string url = uriBuilder.ToString();

            string jsonSerializedData = JsonConvert.SerializeObject(batch);

            Task <HttpClientResponse> Request = _httpClient.SendPostJsonRequestAsync(url, jsonSerializedData);

            Request.Wait();

            HttpClientResponse Response = Request.Result;

            CheckTrackViaApiResponseForErrors(Response);

            DomainRecordSet <T> recordSet = JsonConvert.DeserializeObject <DomainRecordSet <T> >(Response.Content);

            return(recordSet);
        }
        public void IntegrationTest_TrackViaClient_GetDomainRecords_SimpleCrmAccounts()
        {
            TestHelper.EnsureProductionValuesBeforeRunningIntegrationTests(IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW <= 0);

            // Assemble
            TrackViaClient client = new TrackViaClient(IntegrationTestConfig.TRACKVIA_HOSTNAME, IntegrationTestConfig.TRACKVIA_USERNAME,
                                                       IntegrationTestConfig.TRACKVIA_PASSWORD, IntegrationTestConfig.TRACKVIA_API_KEY);

            // Act
            DomainRecordSet <TestData.SimpleCrmContact> domainRecordSet = client.getRecords <TestData.SimpleCrmContact>(
                IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW);

            // Assert
            domainRecordSet.ShouldNotBeNull()
            .Data.ShouldNotBeNull().ShouldNotBeEmpty();
            domainRecordSet.Count.ShouldBeGreaterThan(1);
            domainRecordSet.Data.Count.ShouldEqual(domainRecordSet.Count);

            for (int i = 0; i < domainRecordSet.Count; i++)
            {
                TestData.SimpleCrmContact Account = domainRecordSet.Data[i];
                Account.ShouldNotBeNull();
                Account.Id.ShouldBeGreaterThan(0);
                Account.AccountName.ShouldNotBeNull().ShouldNotBeEmpty();
                Account.PrimaryContact.ShouldNotBeNull().ShouldNotBeEmpty();
            }
        }
示例#4
0
        public void TrackViaClient_CreateRecordBatchAsDomainClass_ShouldCreatedRecords()
        {
            // Assemble
            Record rawRecord = TestData.getUnitTestRecord1();

            TestData.Contact                   contact  = TestData.getUnitTestContact1();
            List <TestData.Contact>            contacts = new List <TestData.Contact>(new TestData.Contact[] { contact });
            DomainRecordSet <TestData.Contact> rs       = new DomainRecordSet <TestData.Contact>(rawRecord.Structure, contacts);

            Mock <IAsyncHttpClientHelper> httpClient = new Mock <IAsyncHttpClientHelper>();

            TestHelper.HttpClient_SetupPostJsonRequest(HttpStatusCode.Created, rs, httpClient);

            TrackViaClient client = new TrackViaClient(httpClient.Object, TestHelper.HostName_Fake, TestHelper.ApiKey_Fake);

            DomainRecordDataBatch <TestData.Contact> batch = new DomainRecordDataBatch <TestData.Contact>(contacts);

            // Act
            DomainRecordSet <TestData.Contact> rsResponse = client.createRecords <TestData.Contact>(1L, batch);

            // Assert
            rsResponse
            .ShouldNotBeNull()
            .Count.ShouldEqual(rs.Count);
            rsResponse.Data
            .ShouldNotBeNull()
            .Count.ShouldEqual(rs.Count);
        }
        /// <summary>
        /// Finds record matching given search criteria, returning native records.
        /// </summary>
        /// <param name="viewId">view identifier in which to search for records</param>
        /// <param name="searchCriteria">query substring used for a substring match against all of the user-defined fields</param>
        /// <param name="startIndex">the index (0 based) of the first user record, useful for paging</param>
        /// <param name="maxRecords">retrieve no more than this many user records, must be 0 < max < 101</param>
        /// <returns>a list of application objects matching the search criteria, which may be empty</returns>
        /// <exception cref="TrackViaApiException">if the service fails to process this request</exception>
        /// <exception cref="TrackviaClientException">if an error occurs outside the service, failing the request</exception>
        public DomainRecordSet <T> findRecords <T>(long viewId, string searchCriteria, int startIndex, int maxRecords)
        {
            HttpClientResponse Response = findRecordsShared(viewId, searchCriteria, startIndex, maxRecords);

            DomainRecordSet <T> recordSet = JsonConvert.DeserializeObject <DomainRecordSet <T> >(Response.Content);

            return(recordSet);
        }
        /// <summary>
        /// Gets records available to the authenticated user in the given view.
        ///
        /// Use with small tables, when all records can be reasonably transferred in a single call.
        /// </summary>
        /// <typeparam name="T">return instances of this type (instead of a raw record Map<String, Object>)</typeparam>
        /// <param name="viewId">viewId view identifier in which to get records</param>
        /// <returns>both field metadata and record data, as a record set</returns>
        /// <exception cref="TrackViaApiException">if the service fails to process this request</exception>
        /// <exception cref="TrackviaClientException">if an error occurs outside the service, failing the request</exception>
        public DomainRecordSet <T> getRecords <T>(long viewId)
        {
            string path = String.Format("{0}/openapi/views/{1}", this._baseUriPath, viewId);

            HttpClientResponse Response = getCommonSharedCode(path);

            DomainRecordSet <T> recordSet = JsonConvert.DeserializeObject <DomainRecordSet <T> >(Response.Content);

            return(recordSet);
        }
        /*
         * Talking with John from TrackVia this should work in theory, but generating
         * errors. Need to work with TrackVia to see if this is possible. It would
         * GREATLY speed up the update process
         *
         */
        /*
         * /// <summary>
         * /// Updates a record in a view accessible to the authenticated user.
         * /// </summary>
         * /// <param name="viewId">view identifier in which to update the record</param>
         * /// <param name="data">enumerable data instance of RecordData</param>
         * /// <returns>RecordSet of updated records</returns>
         * /// <exception cref="TrackViaApiException">if the service fails to process this request</exception>
         * /// <exception cref="TrackviaClientException">if an error occurs outside the service, failing the request</exception>
         * public RecordSet updateRecords(long viewId, IEnumerable<RecordData> data)
         * {
         *  string path = String.Format("{0}/openapi/views/{1}/records/0", this._baseUriPath, viewId);
         *
         *  RecordDataBatch batch = new RecordDataBatch(data);
         *
         *  string jsonSerializedData = JsonConvert.SerializeObject(batch);
         *
         *  HttpClientResponse Response = postCommonSharedCode(path, jsonSerializedData);
         *
         *  RecordSet rsResponse = JsonConvert.DeserializeObject<RecordSet>(Response.Content);
         *
         *  return rsResponse;
         * }
         *
         */

        /// <summary>
        /// Updates a record in a view accessible to the authenticated user using the typed object.
        /// </summary>
        /// <param name="viewId">view identifier in which to update the record</param>
        /// <param name="recordId">unique record identifier</param>
        /// <param name="data">instance of an application-defined class, representing the record data</param>
        /// <returns></returns>
        /// <exception cref="TrackViaApiException">if the service fails to process this request</exception>
        /// <exception cref="TrackviaClientException">if an error occurs outside the service, failing the request</exception>
        public DomainRecord <T> updateRecord <T>(long viewId, long recordId, T data)
        {
            string path = String.Format("{0}/openapi/views/{1}/records/{2}", this._baseUriPath, viewId, recordId);

            DomainRecordDataBatch <T> batch = new DomainRecordDataBatch <T>(new T[] { data });
            string jsonSerializedData       = JsonConvert.SerializeObject(batch);

            HttpClientResponse Response = postCommonSharedCode(path, jsonSerializedData);

            DomainRecordSet <T> recordSet = JsonConvert.DeserializeObject <DomainRecordSet <T> >(Response.Content);

            DomainRecord <T> record = (recordSet != null && recordSet.Data != null && recordSet.Data.Count == 1) ?
                                      new DomainRecord <T>(recordSet.Structure, recordSet.Data[0])
                : null;

            return(record);
        }
        public void IntegrationTest_TrackViaClient_CreateDomainRecords_SimpleCrmAccounts()
        {
            TestHelper.EnsureProductionValuesBeforeRunningIntegrationTests(IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW <= 0);

            // Assemble
            TrackViaClient client = new TrackViaClient(IntegrationTestConfig.TRACKVIA_HOSTNAME, IntegrationTestConfig.TRACKVIA_USERNAME,
                                                       IntegrationTestConfig.TRACKVIA_PASSWORD, IntegrationTestConfig.TRACKVIA_API_KEY);

            TestData.SimpleCrmContact contact = TestData.IntegrationTest_SimpleCrmContact_GetCreate();

            DomainRecordDataBatch <TestData.SimpleCrmContact> batch = new DomainRecordDataBatch <TestData.SimpleCrmContact>(new TestData.SimpleCrmContact[] {
                contact
            });

            // Act
            DomainRecordSet <TestData.SimpleCrmContact> domainRecordSet = client.createRecords <TestData.SimpleCrmContact>(
                IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW, batch);

            // Assert
            domainRecordSet.ShouldNotBeNull()
            .Data.ShouldNotBeNull().ShouldNotBeEmpty();
            domainRecordSet.Count.ShouldEqual(1);
            domainRecordSet.Data.Count.ShouldEqual(domainRecordSet.Count);

            for (int i = 0; i < domainRecordSet.Count; i++)
            {
                TestData.SimpleCrmContact Account = domainRecordSet.Data[i];
                Account.ShouldNotBeNull();
                Account.Id.ShouldBeGreaterThan(0);
                Account.AccountName.ShouldNotBeNull().ShouldEqual(contact.AccountName);
                Account.PrimaryContact.ShouldNotBeNull().ShouldEqual(contact.PrimaryContact);
                Account.ContactPhone.ShouldNotBeNull().ShouldEqual(contact.ContactPhone);
                Account.ContactEmail.ShouldNotBeNull().ShouldEqual(contact.ContactEmail);
                Account.Address.ShouldNotBeNull().ShouldEqual(contact.Address);
                Account.City.ShouldNotBeNull().ShouldEqual(contact.City);
                Account.State.ShouldNotBeNull().ShouldEqual(contact.State);
                Account.ZipCode.ShouldNotBeNull().ShouldEqual(contact.ZipCode);
            }
        }
示例#9
0
        public void TrackViaClient_GetRecordsAsDomainClass_ShouldReturnListOfRecordsAsType()
        {
            // Assemble
            RecordSet rs = TestData.getUnitTestRecordSet3();

            Mock <IAsyncHttpClientHelper> httpClient = new Mock <IAsyncHttpClientHelper>();

            TestHelper.HttpClient_SetupGetRequest(HttpStatusCode.OK, rs, httpClient);

            TrackViaClient client = new TrackViaClient(httpClient.Object, TestHelper.HostName_Fake, TestHelper.ApiKey_Fake);

            // Act
            DomainRecordSet <TestData.Contact> rsResponse = client.getRecords <TestData.Contact>(1L);

            // Assert
            rsResponse
            .ShouldNotBeNull()
            .Count.ShouldEqual(rs.Count);
            rsResponse.Data
            .ShouldNotBeNull()
            .Count.ShouldEqual(rs.Count);
        }