public void GetItem_OfCacheableClassWhenInitialisationTimesOut_ReturnsInitialValueOfNull()
        {
            // Arrange
            AutoRefreshingItemCache <CacheableClass> cache = new AutoRefreshingItemCache <CacheableClass>(
                new FakeLogger(),
                async(ct) => { await TimeDelay.WaitForAsync(500); return(new CacheableClass(100)); },
                null,
                TimeSpan.FromMinutes(2)
                );
            CacheableClass actualResult;

            cache.StartInitialisation();
            cache.TryCompleteInitialisation(TimeSpan.FromMilliseconds(50));

            // Act
            actualResult = cache.GetItem();

            // Assert
            Assert.IsNull(actualResult);
        }
        public void TryCompleteInitialisation_VerySlowCacheLoad_TimesOut()
        {
            // Arrange
            AutoRefreshingItemCache <int> cache = new AutoRefreshingItemCache <int>(
                new FakeLogger(),
                new NonCloningClonerFactory <int>(),
                async(ct) => { await TimeDelay.WaitForAsync(30000); return(125); },
                0,
                TimeSpan.FromMinutes(30)
                );
            bool actualResult;
            bool expectedResult = false;

            cache.StartInitialisation();

            // Act
            actualResult = cache.TryCompleteInitialisation(TimeSpan.FromMilliseconds(50));

            // Assert
            Assert.AreEqual(expectedResult, actualResult);
        }
        public void TryCompleteInitialisation_ImmediateCacheLoad_DoesNotTimeOut()
        {
            // Arrange
            AutoRefreshingItemCache <int> cache = new AutoRefreshingItemCache <int>(
                new FakeLogger(),
                new NonCloningClonerFactory <int>(),
                (ct) => { return(Task.FromResult(125)); },
                0,
                TimeSpan.FromMinutes(30)
                );
            bool actualResult;
            bool expectedResult = true;

            cache.StartInitialisation();

            // Act
            actualResult = cache.TryCompleteInitialisation(TimeSpan.FromMilliseconds(50));

            // Assert
            Assert.AreEqual(expectedResult, actualResult);
        }
        public void Initialise_CacheLoadThrowsException_TimesOut()
        {
            // Arrange
            AutoRefreshingItemCache <int> cache = new AutoRefreshingItemCache <int>(
                new FakeLogger(),
                new NonCloningClonerFactory <int>(),
                (ct) => { throw new Exception("Test exception raised during cache load tests"); },
                0,
                TimeSpan.FromMinutes(30)
                );
            bool actualResult;
            bool expectedResult = false;

            cache.StartInitialisation();

            // Act
            actualResult = cache.TryCompleteInitialisation(TimeSpan.FromMilliseconds(50));

            // Assert
            Assert.AreEqual(expectedResult, actualResult);
        }
        public void GetItem_OfIntWhenInitialialisationTimesOut_ReturnsInitialValueOfZero()
        {
            // Arrange
            AutoRefreshingItemCache <int> cache = new AutoRefreshingItemCache <int>(
                new FakeLogger(),
                new NonCloningClonerFactory <int>(),
                async(ct) => { await TimeDelay.WaitForAsync(500); return(125); },
                0,
                TimeSpan.FromMinutes(2)
                );
            int actualResult;
            int expectedResult = 0;

            cache.StartInitialisation();
            cache.TryCompleteInitialisation(TimeSpan.FromMilliseconds(50));

            // Act
            actualResult = cache.GetItem();

            // Assert
            Assert.AreEqual(expectedResult, actualResult);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Attempt to wait for initialisation to complete, using a timeout to avoid permanently
 /// blocking further progress of the consuming application.
 /// </summary>
 /// <param name="timeout">The timeout to apply before returning if validation fails to initialise</param>
 /// <returns>Boolean true if the initialisation completes successfully, otherwise false</returns>
 bool IDisallowedFragmentListCacheInitialiser.TryCompleteInitialisation(TimeSpan timeout)
 {
     return(_cache.TryCompleteInitialisation(timeout));
 }
 /// <summary>
 /// Attempt to wait for initialisation to complete, using a timeout to avoid permanently
 /// blocking further progress of the consuming application.
 /// </summary>
 /// <param name="timeout">The timeout to apply before returning if validation fails to initialise</param>
 /// <returns>Boolean true if the initialisation completes successfully, otherwise false</returns>
 bool ICharacterSetListCacheInitialiser.TryCompleteInitialisation(TimeSpan timeout)
 {
     return(_cache.TryCompleteInitialisation(timeout));
 }