public void FixedIntervalWithoutResultTest() { const int retryCount = 5; TimeSpan retryInterval = TimeSpan.FromSeconds(1); Counter <InvalidOperationException> counter = new Counter <InvalidOperationException>(retryCount); int retryFuncCount = 0; int retryHandlerCount = 0; Retry.FixedInterval( () => { retryFuncCount++; counter.Increase(); }, retryCount, exception => exception is InvalidOperationException, (sender, e) => { Assert.IsInstanceOfType(e.LastException, typeof(InvalidOperationException)); Assert.AreEqual(retryInterval, e.Delay); Assert.AreEqual(counter.Time.Count, e.CurrentRetryCount); retryHandlerCount++; }, retryInterval, false); Assert.AreEqual(retryCount, retryFuncCount); Assert.AreEqual(retryCount - 1, retryHandlerCount); Assert.AreEqual(retryCount, counter.Time.Count); TimeSpan[] intervals = counter.Time.Take(counter.Time.Count - 1).Zip(counter.Time.Skip(1), (a, b) => b - a).ToArray(); Assert.AreEqual(retryCount - 1, intervals.Length); Assert.IsTrue(intervals.All(interval => interval >= retryInterval)); }
private static void SaveCharacterWithRetry(string cacheRoot, ICharacter character) => Retry.FixedInterval( () => { string path = Path.Combine(cacheRoot, character.Path()); Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllBytes(path, Convert.FromBase64String(character.ImageBase64)); }, retryInterval: TimeSpan.Zero, retryCount: 3);