2010-07-30 7 views

risposta

7

fast-forward quattro anni e NUnit ora supporta questo (la versione corrente è la v2.6 - Non ho controllato quale versione è stata introdotta).

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

perché non dicono:

Assert.Throws<InvalidOperationException>(
    () => nullNodeList.GetEnumerator().Current); 
+0

im lavorare con C# 2.0:/ – atamanroman

+1

Sarà comunque necessario fare un vero e proprio (buttare via) Assegnazione e mantenere il {}, quindi: (() => {var x = nullNodeList.GetEnumerator(). Current;}) – nashwan

6
Assert.Throws<InvalidOperationException>(
    delegate { object current = nullNodeList.GetEnumerator().Current; }); 
+0

grazie mille. questo è stato facile (ma non molto intuitivo) – atamanroman

+0

@Anton Ciao anton Vorrei sapere se questo è il modo di usare Test per la proprietà readonly di una classe pubblica? – Deeptechtons

1

Si potrebbe provare assegnandolo ad una variabile o provare enumerare:

Assert.Throws<InvalidOperationException>(delegate 
{ 
    // Current is a property as we all know 
    object current = nullNodeList.GetEnumerator().Current; 
}); 
Problemi correlati