¿ªÔÆÌåÓý

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

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


 

How does a connection get its SecureString? Can you inject one for test purposes, saving a reference to it?

Charlie


On Wed, Jan 22, 2014 at 11:26 PM, Gishu Pillai <gishu.pillai@...> wrote:
?

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