How do I unit test a Dispose method ?

Gishu Pillai <[email protected]> Thu, 23 Jan 2014 12:56:04 +0530
Newsgroups gmane.comp.programming.test-driven-development
Message-ID <CABT02tutwD4S=VF7QZuuWx8C6UKpLPbZXJgvQdPrjm-uoxa-fw@mail.gmail.com>
The question is a bit .Net specific.
Assuming the simple case, where I have a type which wraps a internal
IDisposable member.

class Connection
{
   private SecureString password;
}

SecureString is Disposable. That mandates that Connection should have a
Dispose method, which should dispose its members.

Options:
* To know whether the internal member has been disposed, I'd have to expose
it (so that the unit test can see it). Doesn't feel right to me.
* The other hack would be to promote it from private to internal + use the
InternalVisibleTo path to access it.

Does anyone have something better ?

Gishu