public void RecurringWorker_should_execute_tasks_periodically() { // Arrange var counter = 0; var due = TimeSpan.FromMilliseconds(600); var period = TimeSpan.FromMilliseconds(150); var testTime = TimeSpan.FromMilliseconds(1800); var expectedCount = 9; var tolerance = 4; Func <Task> testAction = () => { counter++; return(TaskUtilities.CompletedTask); }; using (var sut = new RecurringWorker(testAction, due, period)) { Assert.AreEqual(0, counter); // Act Delay(testTime); } // Assert #if (DNXCORE50) Assert.InRange(counter, expectedCount - tolerance, expectedCount + tolerance); #else Assert.GreaterOrEqual(counter, expectedCount - tolerance); Assert.LessOrEqual(counter, expectedCount + tolerance); #endif }
public void RecurringWorker_should_execute_tasks_periodically() { // Arrange var counter = 0; var anyUrl = "http://example.com/links-blacklist.txt"; var httpClient = new HttpClientDouble(); httpClient.Setup_GetString(() => { counter++; return(new SimplifiedHttpResponse() { Body = ".*", Etag = null, NotModified = false }); }); var sut = new SimpleRegex.SimpleRegexRulesHttpUpdater(anyUrl, httpClient); var due = TimeSpan.FromMilliseconds(600); var period = TimeSpan.FromMilliseconds(150); var testTime = TimeSpan.FromMilliseconds(1800); var expectedCount = 9; var tolerance = 4; // Act sut.UpdatePeriodically(due, period); Assert.AreEqual(0, counter); Delay(testTime); // Assert #if (DNXCORE50) Assert.InRange(counter, expectedCount - tolerance, expectedCount + tolerance); #else Assert.GreaterOrEqual(counter, expectedCount - tolerance); Assert.LessOrEqual(counter, expectedCount + tolerance); #endif }