RE: How do I unit test a Dispose method ?
Avi Kessner <[email protected]> Mon, 3 Feb 2014 18:39:57 +0200
| Newsgroups | gmane.comp.programming.test-driven-development |
|---|---|
| Message-ID | <CAGEhWpHVbDhEkZgtTSaOmCvWZg=jp_HcEF7iUYgMURMX+=+Rdw@mail.gmail.com> |
Unless it's a factory On Feb 3, 2014 6:34 PM, "Amir Kolsky" <[email protected]> wrote: > > > I agree, my point is that you should ALWAYS be given the object rather > than it belonging to you. Therefore, the whole IDisposable pattern seems > flawed from a design perspective. > > > > All that said, you can still test drive a flawed design.... J > > > > *From:* [email protected] [mailto: > [email protected]] *On Behalf Of *Brad Wilson > *Sent:* Monday, February 3, 2014 7:48 AM > *To:* [email protected] > *Subject:* Re: [TDD] How do I unit test a Dispose method ? > > > > > > ...except, if you're given the object rather than creating it yourself, > then its lifetime doesn't belong to you, and you don't need to be concerned > with whether it's disposable. > > > > On Sun, Feb 2, 2014 at 11:36 PM, Amir Kolsky < > [email protected]> wrote: > > > > If A cares about this specific property it would require B to implement > IDisposable. > > From A's perspective, it is given an object of type B to perform a > specific action. B would be available to A through an interface, not an > implementation. Hence A would not know that (say) B1 is the implementation > of B, but rather know about B alone > > > > > > *From:* [email protected] [mailto: > [email protected]] *On Behalf Of *David Burstin > *Sent:* Sunday, February 2, 2014 9:40 PM > *To:* [email protected] > *Subject:* Re: [TDD] How do I unit test a Dispose method ? > > > > > > Amir, I feel like I might be missing your point. > > > > Why is it unreasonable for A to know that B uses expensive resources and > provides a way to release them early? Surely this was one of the > considerations when choosing B over X or Y or Z. IMHO it's a > characteristic, not an implementation detail. > > > > On 3 February 2014 15:19, Amir Kolsky <[email protected]> > wrote: > > > > > > Except that B must already be IDisposable. The IDisposable pattern > requires that any object that owns an IDisposable must itself implement > IDisposable. > > > > n This is inane, as it requires the owning object to know about > implementation details of it's ownee. > > I disagree. All that A needs to know is that B implements the IDisposable > interface. > > > > * A has to know about something pertaining to B that has nothing to do > with why A needs it. > > > > > > > > >