Re: How do I unit test a Dispose method ?

Charlie Poole <[email protected]> Wed, 22 Jan 2014 23:42:12 -0800
Newsgroups gmane.comp.programming.test-driven-development
Message-ID <CAJ+=fjjFNYhLyZzpY29Ffkxo=6akVajoL22S8h42rdAZx+A-PA@mail.gmail.com>
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 <[email protected]>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
>
>  
>