public void HttpRouteCollection_Dispose_UniquifiesHandlers() { // Arrange var collection = new HttpRouteCollection(); var handler1 = new Mock<HttpMessageHandler>(); handler1.Protected().Setup("Dispose", true).Verifiable(); var handler2 = new Mock<HttpMessageHandler>(); handler1.Protected().Setup("Dispose", true).Verifiable(); var route1 = new Mock<IHttpRoute>(); route1.SetupGet(r => r.Handler).Returns(handler1.Object); var route2 = new Mock<IHttpRoute>(); route2.SetupGet(r => r.Handler).Returns(handler1.Object); var route3 = new Mock<IHttpRoute>(); route3.SetupGet(r => r.Handler).Returns(handler2.Object); collection.Add("route1", route1.Object); collection.Add("route2", route2.Object); collection.Add("route3", route3.Object); // Act collection.Dispose(); // Assert handler1.Protected().Verify("Dispose", Times.Once(), true); handler2.Protected().Verify("Dispose", Times.Once(), true); }
protected override void Dispose(bool disposing) { if (disposing) { (_secretManager as IDisposable)?.Dispose(); _metricsLogger?.Dispose(); _httpRoutes?.Dispose(); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { if (_secretManager != null) { (_secretManager as IDisposable).Dispose(); } if (_metricsLogger != null) { _metricsLogger.Dispose(); } if (_httpRoutes != null) { _httpRoutes.Dispose(); } } base.Dispose(disposing); }