RE: How do I unit test a Dispose method ?
"Donaldson, John" <[email protected]> Thu, 23 Jan 2014 09:57:51 +0000
| Newsgroups | gmane.comp.programming.test-driven-development |
|---|---|
| Message-ID | <716D07F3CBA94244A0922E7A99837C3A13AB4E0A@G5W2731.americas.hpqcorp.net> |
Gishu, Could you inject a mocked SecureString? Then you can check if the SecureString.Dispose is called. Seems like a good place to use a mock as it's a "tell" pattern. John D. From: [email protected] [mailto:[email protected]] On Behalf Of Gishu Pillai Sent: 23 January 2014 08:26 To: [email protected] Subject: [TDD] How do I unit test a Dispose method ? 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