public void MessageBoxShow_should_be_callable_indirectly() { using (new IndirectionsContext()) { // Arrange var mockMessageBox = new Mock <IndirectionFunc <string, DialogResult> >(); mockMessageBox.Setup(_ => _(string.Empty)).Returns(DialogResult.OK); PMessageBox.ShowString().Body = mockMessageBox.Object; // Act MessageBox.Show("This is a message"); // Assert mockMessageBox.Verify(_ => _("This is a message")); } }
public void UserOfSomeClassDoSomething_should_show_MessageBox_if_an_exception_is_thrown() { using (new IndirectionsContext()) { // Arrange PSomeClass.MyMethod().Body = () => { throw new Exception("foo"); }; var mockMessageBox = new Mock <IndirectionFunc <string, DialogResult> >(); mockMessageBox.Setup(_ => _(string.Empty)).Returns(DialogResult.OK); PMessageBox.ShowString().Body = mockMessageBox.Object; // Act var user = new UserOfSomeClass(); user.DoSomething(); // Assert mockMessageBox.Verify(_ => _("Exception caught: foo")); } }