Using MOQ to mock a MessageBox

372 views
Skip to first unread message

huntantr

unread,
May 22, 2012, 2:12:28 PM5/22/12
to Moq Discussions
I'm new to using MOQ and I need to mock the C# MessageBox class. I'm
trying to test a method that displays a message under certain
conditions. During our automated build, I don't want this message to
appear.

Any guidance on this would be appreciated.


Thanks.

Daniel Cazzulino

unread,
May 22, 2012, 2:44:27 PM5/22/12
to moq...@googlegroups.com
make up an IDialogService thinghy that is implemented using a messagebox in normal runs, but is mocked to do nothing on test runs.

/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471



Tim Kellogg

unread,
May 22, 2012, 2:52:40 PM5/22/12
to moq...@googlegroups.com

Daniel is right. Does anyone know of a standard set of facades for people to consume? file system access is a continuous problem. I'd love to stop writing wrappers

Daniel Cazzulino

unread,
May 22, 2012, 3:04:06 PM5/22/12
to moq...@googlegroups.com
There should be a netfx for that :)


hehe

(and in one project I got THIS close to it by having T4 templates generate the wrappers using Reflection over the actual System.IO types.... )

/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471


Tim Kellogg

unread,
May 22, 2012, 3:19:43 PM5/22/12
to moq...@googlegroups.com
Kzu,

Would you mind pulling those into github under the moq organization? I would love to promote it.

--Tim

Daniel Cazzulino

unread,
May 22, 2012, 3:33:06 PM5/22/12
to moq...@googlegroups.com
yup, thinking that it might be a better fit... specially if I could get something like this worked out... http://kzu.to/Kwfi41


/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471


Tim Kellogg

unread,
May 22, 2012, 3:41:06 PM5/22/12
to moq...@googlegroups.com
Yeah, I remember talking about that a while ago. It's an excellent idea.

The root problem is trying to get developers to contribute back to OSS projects. I'm taking quite a different approach by starting a meetup group in Boulder, Colorado for getting people comfortable with contributing to open source projects through hands-on mentorship & pair programming. If anyone knows of some open space we can use in Boulder, please let me know!


https://github.com/OpenHatchX/BoulderMeetup 

(sorry about the self-plug there, it seemed appropriate)

--Tim
Reply all
Reply to author
Forward
0 new messages