public void Parameter_Constructor() { HttpResponseMessage[] responses = new HttpResponseMessage[0]; ChangeSetResponseItem responseItem = new ChangeSetResponseItem(responses); Assert.Same(responses, responseItem.Responses); }
public void WriteResponseAsync_NullWriter_Throws() { ChangeSetResponseItem responseItem = new ChangeSetResponseItem(new HttpResponseMessage[0]); Assert.ThrowsArgumentNull( () => responseItem.WriteResponseAsync(null).Wait(), "writer"); }
public void Dispose_DisposesAllHttpResponseMessages() { ChangeSetResponseItem responseItem = new ChangeSetResponseItem(new MockHttpResponseMessage[] { new MockHttpResponseMessage(), new MockHttpResponseMessage(), new MockHttpResponseMessage() }); responseItem.Dispose(); Assert.Equal(3, responseItem.Responses.Count()); foreach (var response in responseItem.Responses) { Assert.True(((MockHttpResponseMessage)response).IsDisposed); } }
public override async Task<ODataBatchResponseItem> SendRequestAsync(HttpMessageInvoker invoker, CancellationToken cancellationToken) { if (invoker == null) { throw new ArgumentNullException("invoker"); } List<HttpResponseMessage> responses = new List<HttpResponseMessage>(); SetUpChangeSetContext(_parentRequest); ChangeSetResponseItem changeSetResponse; try { foreach (HttpRequestMessage request in Requests) { HttpResponseMessage response = await SendSubRequestAsync(invoker, request, cancellationToken); if (response.IsSuccessStatusCode) { responses.Add(response); } else { // In the case of an error response, just return the single error response responses.DisposeAll(); responses.Clear(); responses.Add(response); break; } } // Execute the changeset completion actions await ExecuteChangeSetCompletionActions(responses, cancellationToken); changeSetResponse = new ChangeSetResponseItem(responses); } catch { responses.DisposeAll(); throw; } return changeSetResponse; }
public void WriteResponseAsync_WritesChangeSet() { HttpResponseMessage[] responses = new HttpResponseMessage[] { new HttpResponseMessage(HttpStatusCode.Accepted), new HttpResponseMessage(HttpStatusCode.NoContent) }; ChangeSetResponseItem responseItem = new ChangeSetResponseItem(responses); MemoryStream memoryStream = new MemoryStream(); IODataResponseMessage responseMessage = new ODataMessageWrapper(memoryStream); ODataMessageWriter writer = new ODataMessageWriter(responseMessage); ODataBatchWriter batchWriter = writer.CreateODataBatchWriter(); batchWriter.WriteStartBatch(); responseItem.WriteResponseAsync(batchWriter).Wait(); batchWriter.WriteEndBatch(); memoryStream.Position = 0; string responseString = new StreamReader(memoryStream).ReadToEnd(); Assert.Contains("changesetresponse", responseString); Assert.Contains("Accepted", responseString); Assert.Contains("No Content", responseString); }