public void Dispose_DisposesODataBatchResponseItems() { MockHttpResponseMessage[] responses = new MockHttpResponseMessage[] { new MockHttpResponseMessage(), new MockHttpResponseMessage(), new MockHttpResponseMessage() }; ODataBatchContent batchContent = CreateBatchContent(new ODataBatchResponseItem[] { new OperationResponseItem(responses[0]), new ChangeSetResponseItem(new HttpResponseMessage[] { responses[1], responses[2] }), }); HttpResponseMessage batchResponse = new HttpResponseMessage { Content = batchContent }; batchResponse.Dispose(); foreach (var response in responses) { Assert.True(response.IsDisposed); } }
public async Task SendRequestAsync_DisposesResponseInCaseOfException() { List <MockHttpResponseMessage> responses = new List <MockHttpResponseMessage>(); ChangeSetRequestItem requestItem = new ChangeSetRequestItem(new HttpRequestMessage[] { new HttpRequestMessage(HttpMethod.Get, "http://example.com"), new HttpRequestMessage(HttpMethod.Post, "http://example.com"), new HttpRequestMessage(HttpMethod.Put, "http://example.com") }); Mock <HttpMessageInvoker> invoker = new Mock <HttpMessageInvoker>(new HttpServer()); invoker.Setup(i => i.SendAsync(It.IsAny <HttpRequestMessage>(), CancellationToken.None)) .Returns <HttpRequestMessage, CancellationToken>((req, cancel) => { if (req.Method == HttpMethod.Put) { throw new InvalidOperationException(); } var response = new MockHttpResponseMessage(); responses.Add(response); return(Task.FromResult <HttpResponseMessage>(response)); }); await ExceptionAssert.ThrowsAsync <InvalidOperationException>( () => requestItem.SendRequestAsync(invoker.Object, CancellationToken.None)); Assert.Equal(2, responses.Count); foreach (var response in responses) { Assert.True(response.IsDisposed); } }