//[TestMethod] public async Task GetUploadBatchInfo() { string content = ""; HttpResponseMessage response = null; try { var uploadBatchRequest = new UploadBatchRequest { BatchTag = "Batch 1", BatchDescription = "First Batch in GM" }; var stringContent = JsonConvert.SerializeObject(uploadBatchRequest); var requestContent = new StringContent(stringContent, Encoding.UTF8, "application/json"); response = await client.PostAsync("api/actions/uploadbatch", requestContent); if (response.IsSuccessStatusCode) { content = await response.Content.ReadAsStringAsync(); } Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); var info = JsonConvert.DeserializeObject <UploadBatchResponse>(content); //Assert.AreEqual(uploadBatchRequest.BatchTag, info.BatchTag); } catch (Exception e) { LogInfo(e.Message); throw; } finally { LogInfo($"received response status {response.StatusCode}, response content: {content}"); } }
private static async Task UploadBatchTestCore(UploadBatchRequest request, Func <HttpResponseMessage, string, bool> validator) { string content = ""; HttpResponseMessage response = null; try { var stringContent = JsonConvert.SerializeObject(request); var requestContent = new StringContent(stringContent, Encoding.UTF8, "application/json"); response = await client.PostAsync("api/actions/uploadbatch", requestContent); try { content = await response.Content.ReadAsStringAsync(); } catch (Exception) { } Assert.IsTrue(validator(response, content)); } catch (Exception e) { LogInfo(e.Message); throw; } finally { LogInfo($"received response status {response.StatusCode}, response content: {content}"); } }
/// <exception cref="SwaggerException">A server side error occurred.</exception> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> public async System.Threading.Tasks.Task <SwaggerResponse> PostAsync(UploadBatchRequest request, System.Threading.CancellationToken cancellationToken) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/Batch"); var client_ = _httpClient; try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); PrepareRequest(client_, request_, urlBuilder_); var url_ = urlBuilder_.ToString(); request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); PrepareRequest(client_, request_, url_); var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); try { var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); if (response_.Content != null && response_.Content.Headers != null) { foreach (var item_ in response_.Content.Headers) { headers_[item_.Key] = item_.Value; } } ProcessResponse(client_, response_); var status_ = ((int)response_.StatusCode).ToString(); if (status_ == "204") { return(new SwaggerResponse((int)response_.StatusCode, headers_)); } else if (status_ != "200" && status_ != "204") { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", (int)response_.StatusCode, responseData_, headers_, null); } return(new SwaggerResponse((int)response_.StatusCode, headers_)); } finally { if (response_ != null) { response_.Dispose(); } } } } finally { } }
/// <exception cref="SwaggerException">A server side error occurred.</exception> public System.Threading.Tasks.Task <SwaggerResponse> PostAsync(UploadBatchRequest request) { return(PostAsync(request, System.Threading.CancellationToken.None)); }
public async Task <IHttpActionResult> UploadImageBatchAsync([FromBody] UploadBatchRequest value) { try { if (string.IsNullOrWhiteSpace(value.BatchTag)) { throw new TncException() { StatusCode = HttpStatusCode.BadRequest, ErrorCode = ErrorCode.ProperyCannotBeEmpty, ErrorMessage = string.Format(ErrorMessages.PropertyCannotBeEmpty, "BatchTag") }; } if (string.IsNullOrWhiteSpace(value.CSVMetadata)) { throw new TncException() { StatusCode = HttpStatusCode.BadRequest, ErrorCode = ErrorCode.ProperyCannotBeEmpty, ErrorMessage = string.Format(ErrorMessages.PropertyCannotBeEmpty, "CSVMetadata") }; } List <AnimalImage> animalImages; try { animalImages = AnimalImage.ReadFromCsv(value.CSVMetadata); } catch (Exception ex) { throw new TncException() { StatusCode = HttpStatusCode.BadRequest, ErrorCode = ErrorCode.BadCSVMetadata, ErrorMessage = ex.Message }; } MetadataValidate(animalImages, a => string.IsNullOrWhiteSpace(a.OriginalFileId), "OriginalFileId is not present"); MetadataValidate(animalImages, a => string.IsNullOrWhiteSpace(a.OriginalFolderId), "OriginalFolderId is not present"); MetadataValidate(animalImages, a => string.IsNullOrWhiteSpace(a.OriginalImageId), "OriginalImageId is not present"); MetadataValidate(animalImages, a => string.IsNullOrWhiteSpace(a.FileFormat), "FileFormat is not present"); var operation = new OperationResult { CreationTime = DateTime.UtcNow, Id = Guid.NewGuid().ToString(), Status = new OperationStatus { Code = OperationStage.New } }; await this.AppConfiguration.CosmosDBClient.UpsertDocumentAsync( this.AppConfiguration.OperationResultCollectionUri, operation); Uri originalUri = this.Request.RequestUri; UriBuilder uriBuilder = new UriBuilder(originalUri.Scheme, originalUri.Host, originalUri.Port, $"/api/operationresults/{operation.Id}"); this.Request.Properties[Constants.CustomResponseHeaders] = new Dictionary <string, string>() { { Constants.LocationHeader, uriBuilder.Uri.AbsoluteUri }, { Constants.RetryAfterHeader, Constants.RetryIntervalInSeconds.ToString() } }; return(this.Accepted()); } catch (TncException) { throw; } catch (Exception ex) { throw new TncException { ErrorCode = "UnexpectedException", ErrorMessage = ex.ToString() }; } }
public IActionResult Post(UploadBatchRequest request, CancellationToken cancellationToken) { batchProcessorService.Process(request.ContentBase64, cancellationToken); return(NoContent()); }