public void AdditionalSubsequentDelay() { Delayer delayer = new Delayer(100); delayer.AdditionalDelay = 100; TestSubsequentDelay(delayer, 100); }
public void AdditionalImmediateDelay() { Delayer delayer = new Delayer(100); delayer.AdditionalDelay = 100; TestImmediateDelay(delayer, 200); }
public Delicious(string username, string password) { Delayer delayer = new Delayer(1000); QueryTranslatorFactory translatorFactory = new QueryTranslatorFactory(); IHttpWebRequestFactory requestFactory = new HttpWebRequestFactory(username, password); QueryProvider provider = new DeliciousQueryProvider(requestFactory, delayer, translatorFactory); Posts = new Query<Post>(provider); }
private void TestSubsequentDelay(Delayer delayer, int delay) { ManualResetEvent manualEvent = new ManualResetEvent(false); bool called = false; DateTime timeCalled = DateTime.MaxValue; Object obj = new Object(); Callback nop = delegate() { return null; }; Callback callback = delegate() { called = true; timeCalled = DateTime.Now; manualEvent.Set(); return obj; }; // This is the difference between this method and TestImmediateDelay. // This method ignores the first call to Delay and tests the delay of the // second call to Delay. delayer.Delay(nop); DateTime timeStarted = DateTime.Now; Object result = delayer.Delay(callback); manualEvent.WaitOne(delay * 2, false); int timeElapsed = (int)(timeCalled - timeStarted).TotalMilliseconds; double elapsedError = delay * TIME_DIFFERENCE; Assert.IsTrue(called); Assert.AreSame(obj, result); Assert.IsTrue(timeElapsed >= delay - elapsedError, "Delay was not at least (" + delay + " - " + elapsedError + ") msec; total time elapsed was " + timeElapsed); if (timeElapsed > delay + elapsedError) { Assert.Inconclusive("Test failed, or specified delay was too small to be supported. Time elapsed was " + timeElapsed + " msec; expected <= " + elapsedError); } }
private void TestImmediateDelay(Delayer delayer, int delay) { ManualResetEvent manualEvent = new ManualResetEvent(false); bool called = false; DateTime timeCalled = DateTime.MaxValue; Object obj = new Object(); Callback callback = delegate() { called = true; timeCalled = DateTime.Now; manualEvent.Set(); return obj; }; DateTime timeStarted = DateTime.Now; Object result = delayer.Delay(callback); manualEvent.WaitOne(delay * 2, false); int timeElapsed = (int)(timeCalled - timeStarted).TotalMilliseconds; Assert.IsTrue(called); Assert.AreSame(obj, result); if (timeElapsed > delay * IMMEDIATE_TIME_DIFFERENCE) { Assert.Inconclusive("Test failed, or delay was too small. Time elapsed was " + timeElapsed + " msec; expected <= " + (delay * IMMEDIATE_TIME_DIFFERENCE)); } }