¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

[TDD] How do I unit test a Dispose method ?


Donaldson, John
 

¿ªÔÆÌåÓý

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: testdrivendevelopment@... [mailto:testdrivendevelopment@...] On Behalf Of Gishu Pillai
Sent: 23 January 2014 08:26
To: testdrivendevelopment@...
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