moq how to test method in class throw exception code example Example: moq assert exception Assert.Throws<SomeException>(() => foo.Bar());