[英]Test if property throws exception with nunit
it seems there are no delegates to properties. 似乎没有属性的代表。 Is there a convenient way to do the following?
有没有方便的方法来做到以下几点?
Assert.Throws<InvalidOperationException>(
delegate
{
// Current is a property as we all know
nullNodeList.GetEnumerator().Current;
});
Fast-forward four years and NUnit now supports this (current version is v2.6 - I've not checked which version this was introduced). 快进四年,NUnit现在支持这个(当前版本是v2.6 - 我没有检查引入了哪个版本)。
Assert.That(() => nullNodeList.GetEnumerator().Current,
Throws.InvalidOperationException);
Assert.Throws<InvalidOperationException>(
delegate { object current = nullNodeList.GetEnumerator().Current; });
why not say: 为什么不说:
Assert.Throws<InvalidOperationException>(
() => nullNodeList.GetEnumerator().Current);
You could try assigning it to a variable or try enumerating: 您可以尝试将其分配给变量或尝试枚举:
Assert.Throws<InvalidOperationException>(delegate
{
// Current is a property as we all know
object current = nullNodeList.GetEnumerator().Current;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.