문제

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).

Assert.That(() => nullNodeList.GetEnumerator().Current,
    Throws.InvalidOperationException);

다른 팁

Assert.Throws<InvalidOperationException>(
    delegate { object current = 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;
});

why not say:

Assert.Throws<InvalidOperationException>(
    () => nullNodeList.GetEnumerator().Current);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top