How to unit test IDisposable?

.net, garbage-collection, idisposable, unit-testing

Solution

No, the GC.Collect() call is asynchronous, you would also need to call this:

System.GC.WaitForPendingFinalizers();

Problem

I'm working on a piece of library code around `IDisposable`. The managed path (via `using`) is easily testable. I'm wondering about the finalizer though: Is calling `System.GC.Collect()` sufficient to force the finalizer to run?

Original source

Related problems