Re: [TFUI] Dialogs and EventHandlers
Anthony Williams <anthony_w.geo-/[email protected]> Tue, 08 Nov 2005 15:46:51 +0000
| Newsgroups | gmane.comp.programming.test-first-user-interfaces |
|---|---|
| Organization | Just Software Solutions Ltd |
| Message-ID | <[email protected]> |
Tim Haughton <[email protected]> writes: > On 07/11/05, Anthony Williams > <anthony_w.geo-/[email protected]> wrote: > > Hi Anthony, > >> http://www.livejournal.com/users/anthony_w/8000.html >> >> The key difference is that I believe the GetFontFromUserSelection function >> does not belong on the MyForm class, so I would extract it to a collaborator >> instead of mocking the FontDialog. > > MyForm : Form > { > MyForm( MyCollaborator mc) > { > this.mc= mc; > this.mc.Parent = this; > } > } > > The model class would look something like... > > MyCollaborator > { > public virtual Font GetFontFromUserSelection( Font defaultFont ) > { > FontDialog fd = new FontDialog(); > _GetFontFromUserSelection( fd, defaultFont ); > } > > public virtual DialogueResult _GetFontFromUserSelection( > FontDialogue fd, Font defaultFont ) > { > fd.Font = defaultFont; > if(fd.ShowDialog( Parent ) != DialogResult.Cancel ) > { > return Fdialog.Font; > } > > return defaultFont; > } > } So, you're not using an interface, but rather a class with virtual methods, and you've extracted a second method from the first, so you can verify the interactions with the FontDialog. I'm not sure it's materially different from my solution, other than using virtual functions rather than interfaces. Certainly, you can do the extract method when working on my SelectFontUsingFontDialog class, in order to facilitate testing. I appreciate that you prefer using real classes with virtual functions, and then using things like your dynamic mock to override them, but I'd rather use interfaces and hand-crafted mocks where possible. Thank you for highlighting a way of testing SelectFontUsingFontDialog. Anthony -- Anthony Williams Software Developer Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk ------------------------ Yahoo! Groups Sponsor --------------------~--> Fair play? Video games influencing politics. Click and talk back! http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/nhFolB/TM --------------------------------------------------------------------~-> To unsubscribe, email: TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/TestFirstUserInterfaces/ <*> To unsubscribe from this group, send an email to: TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/