public void removeDependency(Refreshable refreshable) { if (refreshable != null) { this.dependencies.Remove(refreshable); } }
public void addDependency(Refreshable refreshable) { if (refreshable != null) { this.dependencies.Add(refreshable); } }
public async Task Instance_GivenUnexpired_ShouldRefreshAndReturnOldValue() { // Arrange. const int cacheLifetimeInSeconds = 5; string[] values = { "abc", "def" }; int valueIndex = 0; var time = Substitute.For <IDateTimeService>(); var timeAtInstantiation = new DateTime(); var refreshable = new Refreshable(); time .Now .Returns(timeAtInstantiation); var testObject = new TimeBasedAutoRefresher <Refreshable>( refreshable, time, cacheLifetimeInSeconds, () => refreshable.Refresh(values[valueIndex++])); await testObject.Instance(); time .Now .Returns(timeAtInstantiation.AddSeconds(cacheLifetimeInSeconds - 1)); // Act. Refreshable result = await testObject.Instance(); // Assert. Assert.AreEqual(values[0], result.Value); }
public async Task Instance_GivenFirstCall_ShouldRefreshAndReturnValue() { // Arrange. const int cacheLifetimeInSeconds = 5; const string value = "abc"; var time = Substitute.For <IDateTimeService>(); var timeAtInstantiation = new DateTime(); var refreshable = new Refreshable(); time .Now .Returns(timeAtInstantiation); var testObject = new TimeBasedAutoRefresher <Refreshable>( refreshable, time, cacheLifetimeInSeconds, () => refreshable.Refresh(value)); time .Now .Returns(timeAtInstantiation.AddSeconds(cacheLifetimeInSeconds - 1)); // Act. Refreshable result = await testObject.Instance(); // Assert. Assert.AreEqual(value, result.Value); }
public static void maybeRefresh(IList <Refreshable> alreadyRefreshed, Refreshable refreshable) { if (!alreadyRefreshed.Contains(refreshable)) { alreadyRefreshed.Add(refreshable); log.info("Added refreshable: {}", new object[] { refreshable }); refreshable.refresh(alreadyRefreshed); log.info("Refreshed: {}", new object[] { alreadyRefreshed }); } }
private void Unregister(Refreshable refreshable) { if (Refreshables.Contains(refreshables)) { Refreshables.Remove(refreshables); } else { Debug.Warning("Attepted to unregister a non-registered Refreshable"); } }
private void Register(Refreshable refreshable) { Refreshables.Add(refreshables); }