public void EnsureModifiabilityPostSend(Type handlerType) { var wrapper = HandlerWrapper.GetWrapper(handlerType); using (var client = new HttpClient(wrapper.Handler)) using (var request = new HttpRequestMessage(HttpMethod.Get, "http://xamarin.com")) { var token = new CancellationTokenSource(); client.SendAsync(request, token.Token); Assert.Throws <InvalidOperationException> (() => wrapper.AllowAutoRedirect = !wrapper.AllowAutoRedirect); // cancel to ensure that we do not have side effects token.Cancel(); } }
public void EnsureModifiabilityPostSend(Type handlerType, int macOSMinVersion) { TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, macOSMinVersion, throwIfOtherPlatform: false); var wrapper = HandlerWrapper.GetWrapper(handlerType); using (var client = new HttpClient(wrapper.Handler)) using (var request = new HttpRequestMessage(HttpMethod.Get, "http://xamarin.com")) { var token = new CancellationTokenSource(); client.SendAsync(request, token.Token); Assert.Throws <InvalidOperationException> (() => wrapper.AllowAutoRedirect = !wrapper.AllowAutoRedirect); // cancel to ensure that we do not have side effects token.Cancel(); } }
public void EnsureModifiabilityPostSend(Type handlerType, int macOSMinVersion) { TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, macOSMinVersion, throwIfOtherPlatform: false); var wrapper = HandlerWrapper.GetWrapper(handlerType); using (var client = new HttpClient(wrapper.Handler)) using (var request = new HttpRequestMessage(HttpMethod.Get, "http://xamarin.com")) { var token = new CancellationTokenSource(); client.SendAsync(request, token.Token); Exception e = null; try { wrapper.AllowAutoRedirect = !wrapper.AllowAutoRedirect; Assert.Fail("Unexpectedly able to change AllowAutoRedirect"); } catch (InvalidOperationException ioe) { e = ioe; } catch (TargetInvocationException tie) { e = tie.InnerException; } Assert.That(e, Is.InstanceOf <InvalidOperationException> (), "AllowAutoRedirect"); // cancel to ensure that we do not have side effects token.Cancel(); } }