RE: How do I unit test a Dispose method ?

<[email protected]> 10 Feb 2014 09:25:13 -0800
Newsgroups gmane.comp.programming.test-driven-development
Message-ID <[email protected]>
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: Using (disposableSecurePassword pswd = new disposableSecurePassword()){ Connection conn = new connection(pswd): ... } Makes any sense? Written hastily from iPhone waiting for a buss Avi