public void WebExceptionShouldNotBeSurfacedWhenGetResponseThrowsOnBatch() { IODataRequestMessage requestMessage = new ODataTestMessage(); var context = new DataServiceContextWithCustomTransportLayer(ODataProtocolVersion.V4, () => requestMessage, () => { throw new WebException("web exception on getting response"); }); Action test = () => context.ExecuteBatch(context.CreateQuery<NorthwindModel.Products>("Products")); test.ShouldThrow<WebException>().WithMessage("web exception on getting response"); }
public void NotModifiedTest() { var odataRequestMessage = new ODataTestMessage(); var odataResponseMessage = new ODataTestMessage() { StatusCode = 304, MemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(@"")) }; odataResponseMessage.SetHeader("Content-Type", "0"); DataServiceContextWithCustomTransportLayer context = new DataServiceContextWithCustomTransportLayer(ODataProtocolVersion.V4, () => odataRequestMessage, () => odataResponseMessage); Action test = () => context.CreateQuery<SimpleNorthwind.Product>("Products").ToList(); test.ShouldThrow<DataServiceQueryException>().WithInnerMessage("NotModified"); }
public void WebExceptionShouldeSurfacedWhenGetResponseThrowsOnNonBatch() { IODataRequestMessage requestMessage = new ODataTestMessage(); var context = new DataServiceContextWithCustomTransportLayer(ODataProtocolVersion.V4, () => requestMessage, () => { throw new WebException("web exception on getting response"); }); Action test = () => context.CreateQuery<NorthwindModel.Products>("Products").ToList(); var exception = test.ShouldThrow<Exception>().And; // Should not be surfacing an internal exception exception.Should().BeOfType<WebException>(); exception.Message.Should().Be("web exception on getting response"); }
private static Action GetQueryWithInjectedObjectDisposedOnGetStream(bool useExecuteBatch) { IODataRequestMessage requestMessage = new ODataTestMessage(); var responseMessage = CreateResponseMessageWithGetStreamThrowingObjectDisposeException(); var context = new DataServiceContextWithCustomTransportLayer(ODataProtocolVersion.V4, requestMessage, responseMessage); if (useExecuteBatch) { return () => context.ExecuteBatch(context.CreateQuery<NorthwindModel.Products>("Products")); } else { return () => context.CreateQuery<NorthwindModel.Products>("Products").ToList(); } }