Created
May 16, 2015 15:43
-
-
Save hatelove/76348a505542ad710cba to your computer and use it in GitHub Desktop.
xUnit 驗證 exception 內容的方式
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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