RE: How do I unit test a Dispose method ?

<[email protected]> 11 Feb 2014 00:21:22 -0800
Newsgroups gmane.comp.programming.test-driven-development
Message-ID <[email protected]>
Whoops just saw yesterday's message came in all garbled..
 here it is again properly formatted..
 

 ==========================
 

 Hi again Gishu and all, 
 

 Seems like this thread has grown since I last looked :)
 

 What I used to do in this case is inject the disposable object as a collaborator (interface representing its role) into the class that uses it, 
 

 so the class that uses it doesn't need to know about if it is or isn't disposable.
 

 E.g: 
 

 class connection 
 {
  ISecurePassword pswd 
 }
 

 interface ISecurePassword 
 { 
  Void doSomethingThatSecurePasswordsDo(); 
 }
 

 class DispisableSecurePassword : ISecurePassword, IDisposable
 {
   ... 
 }
 

 Application:
 void Main(){
   using (DisposableSecurePassword pswd = new DisposableSecurePassword())

   {
     Connection conn = new connection(pswd):
     conn.DoSomethingThatNeedsToBeDone();
   }

 }
 

 Makes any sense? 
 

 Written hastily from iPhone waiting for a buss
 

 Avi