public void TestUnbindOnDispose([Values(true, false)] bool async) { WebRequest request; using (request = new JsonWebRequest <HttpBinGetResponse>($"{default_protocol}://{host}/get") { Method = HttpMethod.Get, AllowInsecureRequests = true, }) { request.Started += () => { }; request.Failed += e => { }; request.DownloadProgress += (l1, l2) => { }; request.UploadProgress += (l1, l2) => { }; Assert.DoesNotThrow(request.Perform); } var events = request.GetType().GetEvents(BindingFlags.Instance | BindingFlags.Public); foreach (var e in events) { var field = request.GetType().GetField(e.Name, BindingFlags.Instance | BindingFlags.Public); Assert.IsFalse(((Delegate)field?.GetValue(request))?.GetInvocationList().Length > 0); } }
public void TestUnbindOnDispose(bool async) { WebRequest request; using (request = new JsonWebRequest <HttpBinGetResponse>("https://httpbin.org/get") { Method = HttpMethod.GET }) { request.Started += () => { }; request.Failed += e => { }; request.DownloadProgress += (l1, l2) => { }; request.UploadProgress += (l1, l2) => { }; Assert.DoesNotThrow(request.Perform); } var events = request.GetType().GetEvents(BindingFlags.Instance | BindingFlags.Public); foreach (var e in events) { var field = request.GetType().GetField(e.Name, BindingFlags.Instance | BindingFlags.Public); Assert.IsFalse(((Delegate)field?.GetValue(request))?.GetInvocationList().Length > 0); } }