测试属性是否与nunit抛出异常

ata*_*man 9 c# delegates properties nunit-2.5 c#-2.0

似乎没有属性的代表.有没有方便的方法来做到以下几点?

Assert.Throws<InvalidOperationException>(
       delegate
       {
           // Current is a property as we all know
           nullNodeList.GetEnumerator().Current;
       });
Run Code Online (Sandbox Code Playgroud)

Edd*_*ter 10

快进四年,NUnit现在支持这个(当前版本是v2.6 - 我没有检查引入了哪个版本).

Assert.That(() => nullNodeList.GetEnumerator().Current,
    Throws.InvalidOperationException);
Run Code Online (Sandbox Code Playgroud)


Ant*_*lev 7

Assert.Throws<InvalidOperationException>(
    delegate { object current = nullNodeList.GetEnumerator().Current; });
Run Code Online (Sandbox Code Playgroud)