public void Error() { // ARRANGE Sample[] samples = CreateSampleObjects(false, true, true); SampleCollection target = CreateArgument(samples); TestLogMonitor logMonitor = new TestLogMonitor(); // ACT logMonitor.StartLogging(filterByCurrentThread: !this.UseParallel); try { CallTargetMethod(target); } finally { logMonitor.StopLogging(); } // ASSERT Assert.True(AreAllDisposed(samples)); Assert.True(IsCleared(target)); AssertLog(samples, $"{this.TestClassName}.CallTargetMethod()", logMonitor); }
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); }
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); }