public void IntegrationTest_TrackViaClient_GetFile_ShouldReturnUpdatedRecord() { TestHelper.EnsureProductionValuesBeforeRunningIntegrationTests(IntegrationTestConfig.TRACKVIA_VIEWID_DEMOSIMPLECRM_ACCOUNTSDEFAULTVIEW <= 0); // Assemble string tempFilePath = System.IO.Path.GetTempFileName(); System.IO.File.Delete(tempFilePath); TrackViaClient client = new TrackViaClient(IntegrationTestConfig.TRACKVIA_HOSTNAME, IntegrationTestConfig.TRACKVIA_USERNAME, IntegrationTestConfig.TRACKVIA_PASSWORD, IntegrationTestConfig.TRACKVIA_API_KEY); // Act client.getFile(IntegrationTestConfig.TRACKVIA_VIEWID_INCLUDESFILEFIELD, IntegrationTestConfig.TRACKVIA_VIEWID_INCLUDESFILEFIELD_RECORDID, IntegrationTestConfig.TRACKVIA_VIEWID_INCLUDESFILEFIELD_FIELDNAME, tempFilePath); // Assert System.IO.File.Exists(tempFilePath).ShouldBeTrue(); System.IO.File.ReadAllBytes(tempFilePath).Length.ShouldBeGreaterThan(0); System.IO.File.Delete(tempFilePath); }
public void TrackViaClient_GetFile_ShouldReturnFileBytes() { // Assemble string tempFilePath = System.IO.Path.GetTempFileName(); System.IO.File.Delete(tempFilePath); string fileContent = "This is only a test"; byte[] fileData = System.Text.Encoding.UTF8.GetBytes(fileContent); Mock <IAsyncHttpClientHelper> httpClient = new Mock <IAsyncHttpClientHelper>(); TaskCompletionSource <HttpClientResponse> asyncTaskResult = new TaskCompletionSource <HttpClientResponse>(); asyncTaskResult.SetResult(new HttpClientResponse() { Content = Convert.ToBase64String(fileData), FileContent = fileData, ContentType = HttpClientResponseTypes.file, StatusCode = HttpStatusCode.OK }); httpClient.Setup(x => x .SendGetFileRequestAsync(It.IsAny <string>())) .Returns(asyncTaskResult.Task); TrackViaClient client = new TrackViaClient(httpClient.Object, TestHelper.HostName_Fake, TestHelper.ApiKey_Fake); // Act client.getFile(1L, 1L, "Test File", tempFilePath); // Assert System.IO.File.Exists(tempFilePath).ShouldBeTrue(); System.IO.File.ReadAllText(tempFilePath).ShouldEqual(fileContent); System.IO.File.Delete(tempFilePath); }