public void Error() { // ARRANGE SampleDisposable arg = new SampleDisposable(throwException: true); TestLogMonitor logMonitor = new TestLogMonitor(); // ACT logMonitor.StartLogging(); try { DisposableUtil.DisposeSuppressingErrors(arg); // no exception expected } finally { logMonitor.StopLogging(); } // ASSERT Assert.Equal(1, arg.DisposedCount); LogEntry expectedEntry = new LogEntry(null, TraceEventType.Error, $"Fail to dispose the object at 'DisposeSuppressingErrors.Error()': {arg.DisposeErrorMessage}"); logMonitor.AssertContains(expectedEntry); }
protected void AssertLog(Sample[] samples, string location, TestLogMonitor actual) { // argument checks Debug.Assert(samples != null); Debug.Assert(location != null); Debug.Assert(actual != null); // assert // Note that the log monitor may store logs which other components report. foreach (Sample sample in samples) { string errorMessage = GetDisposeErrorMessage(sample); if (errorMessage != null) { // this sample throws an Exception on Dispose() LogEntry expectedEntry = new LogEntry(null, TraceEventType.Error, $"Fail to dispose the object at '{location}': {errorMessage}"); actual.AssertContains(expectedEntry); } } return; }
public void Error() { // ARRANGE SampleDisposable sample = new SampleDisposable(throwException: true); SampleDisposable arg = sample; TestLogMonitor logMonitor = new TestLogMonitor(); // ACT logMonitor.StartLogging(filterByCurrentThread: true); try { DisposableUtil.ClearDisposableObject(ref arg); } finally { logMonitor.StopLogging(); } // ASSERT Assert.Equal(null, arg); Assert.Equal(1, sample.DisposedCount); LogEntry expectedEntry = new LogEntry(null, TraceEventType.Error, $"Fail to dispose the object at 'ClearDisposableObject.Error()': {sample.DisposeErrorMessage}"); logMonitor.AssertContains(expectedEntry); }