public async Task DownloadAsyncTest_Base() { var comm = new SevisComm(appSettings, mockedEcaHttpMesssageHandlerService); Action <HttpResponseMessage> tester = async(s) => { Assert.IsTrue(s.IsSuccessStatusCode); Stream zipStream = await s.Content.ReadAsStreamAsync(); var zipResult = new ZipArchive(zipStream); var xmlTransactionLogEntry = zipResult.Entries.First(e => e.Name == xmlTransactionLogFileName); Assert.IsNotNull(xmlTransactionLogEntry); StreamReader reader = new StreamReader(xmlTransactionLogEntry.Open()); string xmloutput = reader.ReadToEnd(); Assert.AreEqual(xmloutput, xmlTransactionLogString); }; var response = await comm.DownloadAsync(batchId, orgId, sevisUser); tester(response); }
/// <summary> /// Calls the sevis api for results to the sevis batch. /// </summary> /// <param name="batchComm">The sevis comm instance.</param> /// <param name="dtoToDownload">The batch to get download results for.</param> /// <returns>The task.</returns> public async Task DownloadBatchAsync(SevisComm batchComm, SevisBatchProcessingDTO dtoToDownload) { Contract.Requires(batchComm != null, "The batchComm must not be null."); Contract.Requires(dtoToDownload != null, "The dto to download must not be null."); // ask for download logger.Info("Getting Download, BatchId: {0}", dtoToDownload.BatchId); var response = await batchComm.DownloadAsync(dtoToDownload.BatchId, dtoToDownload.SevisOrgId, dtoToDownload.SevisUsername); //process response if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); await responseHandler.HandleDownloadResponseStreamAsync(GetSystemUser(), dtoToDownload, stream); logger.Info("Processed Download Response"); } else { logger.Error("Download encountered an error, status code: {0}, reason: {1}", response.StatusCode.ToString(), response.ReasonPhrase); await service.HandleFailedDownloadBatchAsync(dtoToDownload.Id, null); } }