protected override void Dispose(bool disposing) { if (disposing) { TestService?.Dispose(); } base.Dispose(disposing); }
public void DisposingEvent() { int called = 0; using (TestService service = new TestService()) { service.Disposing += (s, e) => called++; Assert.That(called, Is.EqualTo(0)); Assert.That(service.Method(), Is.EqualTo(1)); service.Dispose(); Assert.That(called, Is.EqualTo(1)); Assert.Throws<ObjectDisposedException>(() => service.Method()); service.Dispose(); Assert.That(called, Is.EqualTo(1)); } }
public void Dispose() { using (TestService service = new TestService()) { Assert.That(service.OnDisposingCalled, Is.EqualTo(0)); Assert.That(service.DisposeCalled, Is.EqualTo(0)); Assert.That(service.Method(), Is.EqualTo(1)); service.Dispose(); Assert.That(service.OnDisposingCalled, Is.EqualTo(1)); Assert.That(service.DisposeCalled, Is.EqualTo(1)); Assert.Throws<ObjectDisposedException>(() => service.Method()); service.Dispose(); Assert.That(service.OnDisposingCalled, Is.EqualTo(1)); Assert.That(service.DisposeCalled, Is.EqualTo(1)); } }
public void Dispose() { IEnumerable <dynamic> products = _db.Products.FindAll(_db.Products.ProductName.StartsWith("Test") == true); products.ToList().ForEach(x => _db.Products.Delete(ProductID: x.ProductID)); IEnumerable <dynamic> categories = _db.Categories.FindAll(_db.Categories.CategoryName.StartsWith("Test") == true); categories.ToList().ForEach(x => _db.Categories.Delete(CategoryID: x.CategoryID)); if (_service != null) { _service.Dispose(); _service = null; } }
public void Dispose() { #if NET461 && !MOCK_HTTP if (_client != null && !_readOnlyTests) { DeleteTestData().Wait(); } if (_service != null) { _service.Dispose(); _service = null; } #endif GC.SuppressFinalize(this); }
public static void ClassCleanup() { if (service != null) { service.Dispose(); service = null; } foreach (Action a in EndTestAction) { try { a.Invoke(); } catch { } } EndTestAction.Clear(); }