public void ValueIsNotDisposedBeforeCall()
            {
                var disposable = new CustomDisposable();
                var valueInfo  = new CacheStorageValueInfo <CustomDisposable>(disposable, TimeSpan.FromMilliseconds(250));

                Assert.That(disposable.IsDiposed, Is.False);
            }
            public void ValueIsDisposedAfterCall()
            {
                var disposable = new CustomDisposable();
                var valueInfo  = new CacheStorageValueInfo <CustomDisposable>(disposable, TimeSpan.FromMilliseconds(250));

                valueInfo.DisposeValue();

                Assert.That(disposable.IsDiposed, Is.True);
            }
Beispiel #3
0
            public void DoesNotDisposeItemsOnClearWhenDisposingNotEnabled()
            {
                var disposable = new CustomDisposable();
                var cache      = new CacheStorage <string, CustomDisposable>();

                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);

                cache.Add("disposable", disposable, expiration: TimeSpan.FromMilliseconds(250));

                Assert.IsFalse(disposable.IsDiposed);

                cache.Clear();

                Assert.IsFalse(disposable.IsDiposed);
            }
Beispiel #4
0
            public void DisposesItemOnRemoveWhenDisposingEnabled()
            {
                var disposable = new CustomDisposable();
                var cache      = new CacheStorage <string, CustomDisposable>();

                cache.DisposeValuesOnRemoval  = true;
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);

                cache.Add("disposable", disposable, expiration: TimeSpan.FromMilliseconds(250));

                Assert.IsFalse(disposable.IsDiposed);

                cache.Remove("disposable");

                Assert.IsTrue(disposable.IsDiposed);
            }
Beispiel #5
0
            public void DisposesExpiredItemWhenDisposingNotEnabledButForcedByEventArgs()
            {
                var disposable = new CustomDisposable();
                var cache      = new CacheStorage <string, CustomDisposable>();

                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);
                cache.Expired += (sender, e) =>
                {
                    e.Dispose = true;
                };

                cache.Add("disposable", disposable, expiration: TimeSpan.FromMilliseconds(250));

                ThreadHelper.Sleep(750);

                Assert.IsTrue(disposable.IsDiposed);
            }
Beispiel #6
0
            public void DoesNotDisposeExpiredItemWhenDisposingEnabledButCanceledByEventArgs()
            {
                var disposable = new CustomDisposable();
                var cache      = new CacheStorage <string, CustomDisposable>();

                cache.DisposeValuesOnRemoval  = true;
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);
                cache.Expired += (sender, e) =>
                {
                    e.Dispose = false;
                };

                cache.Add("disposable", disposable, expiration: TimeSpan.FromMilliseconds(250));

                ThreadHelper.Sleep(750);

                Assert.IsFalse(disposable.IsDiposed);
            }
Beispiel #7
0
            public void DisposesExpiredItemWhenDisposingNotEnabledButForcedByEventArgs()
            {
                var disposable = new CustomDisposable();
                var cache = new CacheStorage<string, CustomDisposable>();
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);
                cache.Expired += (sender, e) =>
                {
                    e.Dispose = true;
                };

                cache.Add("disposable", disposable, expiration: TimeSpan.FromMilliseconds(250));

                ThreadHelper.Sleep(750);

                Assert.IsTrue(disposable.IsDiposed);
            }
Beispiel #8
0
            public void DoesNotDisposeItemsOnClearWhenDisposingNotEnabled()
            {
                var disposable = new CustomDisposable();
                var cache = new CacheStorage<string, CustomDisposable>();
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);

                cache.Add("disposable", disposable, expiration: TimeSpan.FromMilliseconds(250));

                Assert.IsFalse(disposable.IsDiposed);

                cache.Clear();

                Assert.IsFalse(disposable.IsDiposed);
            }
Beispiel #9
0
            public void DoesNotDisposeExpiredItemWhenDisposingEnabledButCanceledByEventArgs()
            {
                var disposable = new CustomDisposable();
                var cache = new CacheStorage<string, CustomDisposable>();
                cache.DisposeValuesOnRemoval = true;
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);
                cache.Expired += (sender, e) =>
                {
                    e.Dispose = false;
                };

                cache.Add("disposable", disposable, expiration: TimeSpan.FromMilliseconds(250));

                ThreadHelper.Sleep(750);

                Assert.IsFalse(disposable.IsDiposed);
            }
Beispiel #10
0
            public void DisposesItemOnRemoveWhenDisposingEnabled()
            {
                var disposable = new CustomDisposable();
                var cache = new CacheStorage<string, CustomDisposable>();
                cache.DisposeValuesOnRemoval = true;
                cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);

                cache.Add("disposable", disposable, expiration: TimeSpan.FromMilliseconds(250));

                Assert.IsFalse(disposable.IsDiposed);

                cache.Remove("disposable");

                Assert.IsTrue(disposable.IsDiposed);
            }
            public void ValueIsDisposedAfterCall()
            {
                var disposable = new CustomDisposable();
                var valueInfo = new CacheStorageValueInfo<CustomDisposable>(disposable, TimeSpan.FromMilliseconds(250));

                valueInfo.DisposeValue();

                Assert.That(disposable.IsDiposed, Is.True);
            }
            public void ValueIsNotDisposedBeforeCall()
            {
                var disposable = new CustomDisposable();
                var valueInfo = new CacheStorageValueInfo<CustomDisposable>(disposable, TimeSpan.FromMilliseconds(250));

                Assert.That(disposable.IsDiposed, Is.False);
            }