예제 #1
0
 public void removeDependency(Refreshable refreshable)
 {
     if (refreshable != null)
     {
         this.dependencies.Remove(refreshable);
     }
 }
예제 #2
0
 public void addDependency(Refreshable refreshable)
 {
     if (refreshable != null)
     {
         this.dependencies.Add(refreshable);
     }
 }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
 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 });
     }
 }
예제 #6
0
 private void Unregister(Refreshable refreshable)
 {
     if (Refreshables.Contains(refreshables))
     {
         Refreshables.Remove(refreshables);
     }
     else
     {
         Debug.Warning("Attepted to unregister a non-registered Refreshable");
     }
 }
예제 #7
0
 private void Register(Refreshable refreshable)
 {
     Refreshables.Add(refreshables);
 }