Skip to content

Instantly share code, notes, and snippets.

@urasandesu
Created November 14, 2014 22:25
08. 移行サンプル:Typemock Isolator による… で解説する移行結果(Example Test 2 - Complex Test)。
[Test]
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"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment