nUnit似乎已删除nUnit 3中的ExpectedException属性。所以我的问题是:当我将无效参数传递给类时,如何捕获并测试我的构造函数抛出ArgumentOutOfRangeException?
public Year(int value)
{
if (value < 1) throw new ArgumentOutOfRangeException(nameof(value), "Cannot be less than 1.");
if (value > 9999) throw new ArgumentOutOfRangeException(nameof(value), "Cannot be greater than 9999.");
Value = value;
AddMonths();
}
我的测试:
[Test]
public void ShouldNotBeAbleToCreateYear()
{
// Arrange...
const int yearValue = 0;
// Act...
var year = new Year(yearValue);
// Assert...
// Need to test that an ArgumentOutOfRangeException was thrown!?
}
我已经检查了nUnits文档,而答案之谜使我难以理解!
非常感谢...