public async Task UploadAsyncTest_Base() { var xml = XElement.Parse(uploadXmlString); var comm = new SevisComm(appSettings, mockedEcaHttpMesssageHandlerService); Action <HttpResponseMessage> tester = async(s) => { Assert.IsTrue(s.IsSuccessStatusCode); var xmlResult = await s.Content.ReadAsStringAsync(); Assert.AreEqual(xmlResult, uploadResultXml); }; var response = await comm.UploadAsync(xml, batchId, orgId, sevisUser); tester(response); }
/// <summary> /// Uploads a batch to the sevis api. /// </summary> /// <param name="batchComm">The sevis communication instance.</param> /// <param name="dtoToUpload">The batch to upload.</param> /// <returns></returns> public async Task UploadBatchAsync(SevisComm batchComm, SevisBatchProcessingDTO dtoToUpload) { Contract.Requires(batchComm != null, "The batchComm must not be null."); Contract.Requires(dtoToUpload != null, "The dto to upload must not be null."); //do the send here logger.Info("Sending Upload, BatchId: {0}", dtoToUpload.BatchId); var response = await batchComm.UploadAsync(XElement.Parse(dtoToUpload.SendString), dtoToUpload.BatchId, dtoToUpload.SevisOrgId, dtoToUpload.SevisUsername); //process response message if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); await responseHandler.HandleUploadResponseStreamAsync(GetSystemUser(), dtoToUpload, stream); logger.Info("Processed Upload Response"); } else { logger.Error("Upload encountered an error, status code: {0}, reason: {1}", response.StatusCode.ToString(), response.ReasonPhrase); await service.HandleFailedUploadBatchAsync(dtoToUpload.Id, null); } }