Skip to content

Instantly share code, notes, and snippets.

@hatelove
Created May 16, 2015 15:43
Show Gist options
  • Save hatelove/76348a505542ad710cba to your computer and use it in GitHub Desktop.
Save hatelove/76348a505542ad710cba to your computer and use it in GitHub Desktop.
xUnit 驗證 exception 內容的方式
public class UnitTest1
{
[Fact]
public void TestMethod1()
{
var target = new Joey();
var ex = Assert.Throws(typeof(ArgumentException), () => { target.ThrowEx(2); });
Assert.True(ex.Message.Contains("不能是偶數"));
}
}
internal class Joey
{
public void ThrowEx(int number)
{
if (number % 2 == 0)
{
throw new ArgumentException("不能是偶數", "number");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment