public async Task When_empty_NextTimeToRunQuery_is_1_minute() { var now = DateTime.UtcNow; var persister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); var result = await persister.GetNextChunk(now); Assert.That(result.NextTimeToQuery, Is.EqualTo(now.AddMinutes(1)).Within(100).Milliseconds); }
void GetNextChunk(InMemoryTimeoutPersister inMemoryTimeoutPersister) { for (var i = 0; i < 10; i++) { DateTime nextTimeToRunQuery; inMemoryTimeoutPersister.GetNextChunk(DateTime.MinValue, out nextTimeToRunQuery).ToList(); } }
public async Task When_multiple_NextTimeToRunQuery_is_min_date() { var now = DateTime.UtcNow; var persister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(2) }, new ContextBag()); var expectedDate = DateTime.Now.AddDays(1); await persister.Add(new TimeoutData { Time = expectedDate }, new ContextBag()); var result = await persister.GetNextChunk(now); Assert.AreEqual(expectedDate, result.NextTimeToQuery); }
public void When_multiple_NextTimeToRunQuery_is_min_date() { DateTime nextTimeToRunQuery; var now = DateTime.UtcNow; var persister = new InMemoryTimeoutPersister(); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(2) }); var expectedDate = DateTime.Now.AddDays(1); persister.Add(new TimeoutData { Time = expectedDate }); persister.GetNextChunk(now, out nextTimeToRunQuery); Assert.AreEqual(expectedDate, nextTimeToRunQuery); }
public async Task When_multiple_future_are_returned() { var persister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-2) }, new ContextBag()); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-4) }, new ContextBag()); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-1) }, new ContextBag()); var result = await persister.GetNextChunk(DateTime.Now.AddDays(-3)); Assert.AreEqual(2, result.DueTimeouts.Count()); }
public void When_all_in_past_NextTimeToRunQuery_is_1_minute() { DateTime nextTimeToRunQuery; var now = DateTime.UtcNow; var persister = new InMemoryTimeoutPersister(); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-1) }); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-3) }); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-2) }); persister.GetNextChunk(now, out nextTimeToRunQuery); Assert.That(nextTimeToRunQuery, Is.EqualTo(now.AddMinutes(1)).Within(100).Milliseconds); }
public void When_multiple_future_are_returned() { DateTime nextTime; var persister = new InMemoryTimeoutPersister(); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-2) }); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-4) }); persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-1) }); var nextChunk = persister.GetNextChunk(DateTime.Now.AddDays(-3), out nextTime); Assert.AreEqual(2, nextChunk.Count()); }
public async Task When_all_in_past_NextTimeToRunQuery_is_1_minute() { var now = DateTime.UtcNow; var persister = new InMemoryTimeoutPersister(() => DateTime.UtcNow); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-1) }, new ContextBag()); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-3) }, new ContextBag()); await persister.Add(new TimeoutData { Time = DateTime.Now.AddDays(-2) }, new ContextBag()); var result = await persister.GetNextChunk(now); Assert.That(result.NextTimeToQuery, Is.EqualTo(now.AddMinutes(1)).Within(100).Milliseconds); }
Task <TimeoutsChunk> GetNextChunk() { return(persister.GetNextChunk(DateTime.UtcNow.AddYears(-3))); }