/// <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</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 createRecords(long viewId, RecordDataBatch 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); RecordSet recordSet = JsonConvert.DeserializeObject <RecordSet>(Response.Content); return(recordSet); }
public void TrackViaClient_CreateRecordBatch_ShouldCreatedRecords() { // Assemble RecordSet rs = TestData.getUnitTestRecordSet3(); RecordDataBatch batch = new RecordDataBatch(rs.Data); 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); // Act RecordSet rsResponse = client.createRecords(1L, batch); // Assert rsResponse .ShouldNotBeNull() .Count.ShouldEqual(rs.Count); rsResponse.Data .ShouldNotBeNull() .Count.ShouldEqual(rs.Count); for (int i = 0; i < rsResponse.Count; i++) { RecordData rd1 = rs.Data[i]; RecordData rd2 = rsResponse.Data[i]; rd2.Id.ShouldEqual(rd1.Id); } }
private static Record Integration_CreateRecordStep(TrackViaClient client) { RecordData recordData = TestData.IntegrationTest_SimpleCrmContact_GetCreateRecordData(); RecordDataBatch rsBatch = new RecordDataBatch(new RecordData[] { recordData }); // Act RecordSet rsResponse = client.createRecords(IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW, rsBatch); // Assert rsResponse.ShouldNotBeNull(); rsResponse.Count.ShouldEqual(1); rsResponse.Data.ShouldNotBeNull(); rsResponse.Data[0].Id.ShouldBeGreaterThan(0); rsResponse.Data[0].ShouldNotBeNull(); return(new Record(rsResponse.Structure, rsResponse.Data[0])); }
/// <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="recordId">unique record identifier</param> /// <param name="data">data instance of RecordData</param> /// <returns>Update Record</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 Record updateRecord(long viewId, long recordId, RecordData data) { string path = String.Format("{0}/openapi/views/{1}/records/{2}", this._baseUriPath, viewId, recordId); RecordDataBatch batch = new RecordDataBatch(new RecordData[] { data }); string jsonSerializedData = JsonConvert.SerializeObject(batch); HttpClientResponse Response = postCommonSharedCode(path, jsonSerializedData); RecordSet rsResponse = JsonConvert.DeserializeObject <RecordSet>(Response.Content); Record record = (rsResponse != null && rsResponse.Data != null && rsResponse.Data.Count == 1) ? new Record(rsResponse.Structure, rsResponse.Data[0]) : null; return(record); }
public void IntegrationTest_TrackViaClient_CreateRecords_SimpleCRMAccount() { TestHelper.EnsureProductionValuesBeforeRunningIntegrationTests(); // Assemble RecordData recordData = TestData.IntegrationTest_SimpleCrmContact_GetCreateRecordData(); RecordDataBatch rsBatch = new RecordDataBatch(new RecordData[] { recordData }); TrackViaClient client = new TrackViaClient(IntegrationTestConfig.TRACKVIA_HOSTNAME, IntegrationTestConfig.TRACKVIA_USERNAME, IntegrationTestConfig.TRACKVIA_PASSWORD, IntegrationTestConfig.TRACKVIA_API_KEY); // Act RecordSet rsResponse = client.createRecords(IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW, rsBatch); // Assert rsResponse.ShouldNotBeNull(); rsResponse.Data.ShouldNotBeNull(); rsResponse.Count.ShouldEqual(1); rsResponse.Data[0].ShouldNotBeNull(); }