public void Isolation_AfterLongDelay_GivesUpAndMovesOn()
{
var browser = new BrowserStub();
string target = "any old web address";
var isolator = new NavigationIsolator();
isolator.Navigate(browser, target);
Assert.That(browser.NavigateTarget, Is.EqualTo(target));
string target2 = "some other web address";
isolator.Navigate(browser, target2);
string target3 = "yet another web address";
isolator.Navigate(browser, target3);
Assert.That(browser.NavigateTarget, Is.EqualTo(target), "Second navigation should not have proceeded at once");
var start = DateTime.Now;
while (DateTime.Now - start < new TimeSpan(0, 0, 0, 2, 300))
{
Application.DoEvents(); // allow timer to tick.
}
Assert.That(() => browser.NavigateTarget, Is.EqualTo(target2), "Second navigation should have proceeded eventually");
browser.NormalTermination(); // possibly the long-delayed notification of the first nav, but more likely the second.
Assert.That(() => browser.NavigateTarget, Is.EqualTo(target3), "Third navigation should have proceeded when second finished");
browser.NormalTermination(); // hopefully from the third.
Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
}