When the DelayedConstraint is used with an object (value or reference) it simply waits the specified amount of time before evaluating the base constraint and no polling takes place. When it is used with a reference to an object or with a delegate, polling is used.
So, the following should work as expected:
Assert.That(ref list, Has.Count.EqualTo(1).After(5000, 100));
In the example you give, polling could effectively have been used, since the actual value tested is a property of the object and not the object itself. In other cases, this would not work, since the actual value argument is evaluated only once, before calling Assert.That(). A simple example...
var worker = new BackgroundWorker();
int x = 0;
worker.RunWorkerCompleted += delegate { x = 1; }
worker.DoWork += delegate { Thread.Sleep(1); }
worker.RunWorkerAsync();
Assert.That(x, Is.EqualTo(1).After(5000);
The value of x used in the test is zero because x was evaluated before calling Assert.That().
I'll give this a little more thought to determine whether NUnit can make a runtime distinction between those arguments where polling might make sense and those where it would not. Clearly, we can't make the distinction syntactically.
When the DelayedConstraint is used with an object (value or reference) it simply waits the specified amount of time before evaluating the base constraint and no polling takes place. When it is used with a reference to an object or with a delegate, polling is used.
So, the following should work as expected: EqualTo( 1).After( 5000, 100));
Assert.That(ref list, Has.Count.
In the example you give, polling could effectively have been used, since the actual value tested is a property of the object and not the object itself. In other cases, this would not work, since the actual value argument is evaluated only once, before calling Assert.That(). A simple example...
var worker = new BackgroundWorker(); RunWorkerComple ted += delegate { x = 1; } RunWorkerAsync( ); 1).After( 5000);
int x = 0;
worker.
worker.DoWork += delegate { Thread.Sleep(1); }
worker.
Assert.That(x, Is.EqualTo(
The value of x used in the test is zero because x was evaluated before calling Assert.That().
I'll give this a little more thought to determine whether NUnit can make a runtime distinction between those arguments where polling might make sense and those where it would not. Clearly, we can't make the distinction syntactically.
Charlie