コード例 #1
0
        public void CreateWithLazyLocking_CacheInvalidationTokenOverload_IEqualityComparerOverload()
        {
            var cacheInvalidationToken = InvalidationToken.CreatWithLocking();
            var result = CacheFactory.CreateWithLazyLocking <string, object> (cacheInvalidationToken, _comparer);

            Assert.That(result, Is.TypeOf(typeof(LazyLockingCachingAdapter <string, object>)));
            var innerCache1 = PrivateInvoke.GetNonPublicField(result, "_innerCache");

            Assert.That(
                innerCache1,
                Is.TypeOf(typeof(LockingCacheDecorator <string, DoubleCheckedLockingContainer <LazyLockingCachingAdapter <string, object> .Wrapper> >)));
            var innerCache2 = PrivateInvoke.GetNonPublicField(innerCache1, "_innerCache");

            Assert.That(
                innerCache2,
                Is.TypeOf(
                    typeof(InvalidationTokenBasedCacheDecorator <string, DoubleCheckedLockingContainer <LazyLockingCachingAdapter <string, object> .Wrapper> >)));
            Assert.That(
                ((InvalidationTokenBasedCacheDecorator <string, DoubleCheckedLockingContainer <LazyLockingCachingAdapter <string, object> .Wrapper> >)
                 innerCache2).InvalidationToken,
                Is.SameAs(cacheInvalidationToken));
            var innerCache3 = PrivateInvoke.GetNonPublicField(innerCache2, "_innerCache");

            Assert.That(
                innerCache3,
                Is.TypeOf(typeof(Cache <string, DoubleCheckedLockingContainer <LazyLockingCachingAdapter <string, object> .Wrapper> >)));
            var underlyingDataStore = PrivateInvoke.GetNonPublicField(innerCache3, "_dataStore");

            Assert.That(
                underlyingDataStore,
                Is.TypeOf(typeof(SimpleDataStore <string, DoubleCheckedLockingContainer <LazyLockingCachingAdapter <string, object> .Wrapper> >)));
            Assert.That(
                ((SimpleDataStore <string, DoubleCheckedLockingContainer <LazyLockingCachingAdapter <string, object> .Wrapper> >)underlyingDataStore).Comparer,
                Is.SameAs(_comparer));
        }
コード例 #2
0
        public void IsCurrent_WithCurrentRevision_ReturnsTrue()
        {
            var token = InvalidationToken.CreatWithLocking();

            var revision = token.GetCurrent();

            Assert.That(token.IsCurrent(revision), Is.True);
        }
コード例 #3
0
        public void IsCurrent_WithRevisionFromDefaultConstructor_ThrowsArgumentException()
        {
            var token = InvalidationToken.CreatWithLocking();

            Assert.That(
                () => token.IsCurrent(new InvalidationToken.Revision()),
                Throws.ArgumentException.With.Message.EqualTo(
                    "The Revision used for the comparision was either created via the default constructor or the associated CacheInvalidationToken has already been garbage collected.\r\n"
                    + "Parameter name: revision"));
        }
コード例 #4
0
        public void IsCurrent_WithRevisionFromDifferentToken_ThrowsArgumentException()
        {
            var token1 = InvalidationToken.CreatWithLocking();
            var token2 = InvalidationToken.CreatWithLocking();

            Assert.That(
                () => token2.IsCurrent(token1.GetCurrent()),
                Throws.ArgumentException.With.Message.EqualTo(
                    "The Revision used for the comparision was not created by the current CacheInvalidationToken.\r\nParameter name: revision"));
        }
コード例 #5
0
        public void IsCurrent_WithInvalidatedRevision_ReturnsFalse()
        {
            var token = InvalidationToken.CreatWithLocking();

            var revision = token.GetCurrent();

            token.Invalidate();

            Assert.That(token.IsCurrent(revision), Is.False);
        }
コード例 #6
0
        public void CreateWithLocking_CacheInvalidationTokenOverload()
        {
            var cacheInvalidationToken = InvalidationToken.CreatWithLocking();
            var result = CacheFactory.CreateWithLocking <string, int> (cacheInvalidationToken);

            Assert.That(result, Is.TypeOf(typeof(LockingCacheDecorator <string, int>)));
            var innerCache1 = PrivateInvoke.GetNonPublicField(result, "_innerCache");

            Assert.That(innerCache1, Is.TypeOf(typeof(InvalidationTokenBasedCacheDecorator <string, int>)));
            Assert.That(((InvalidationTokenBasedCacheDecorator <string, int>)innerCache1).InvalidationToken, Is.SameAs(cacheInvalidationToken));
            var innerCache2 = PrivateInvoke.GetNonPublicField(innerCache1, "_innerCache");

            Assert.That(innerCache2, Is.TypeOf(typeof(Cache <string, int>)));
        }
コード例 #7
0
        public void GetCurrent_FromDifferentCacheInvalidationTokens_ReturnsDifferentRevisions()
        {
            var token1 = InvalidationToken.CreatWithLocking();
            var token2 = InvalidationToken.CreatWithLocking();

            if (token1.GetHashCode() == token2.GetHashCode())
            {
                Assert.Ignore(
                    "GetHashCode() happened to have returned the same value for different CacheInvalidationToken instances. "
                    + "This means the same seed value has been used and the tokens should not be used for comparission.");
            }

            Assert.That(token1.GetCurrent(), Is.Not.EqualTo(token2.GetCurrent()));
        }
コード例 #8
0
        public void Serialization()
        {
            var token    = InvalidationToken.CreatWithLocking();
            var revision = token.GetCurrent();

            var deserializedObjects  = Serializer.SerializeAndDeserialize(new object[] { token, revision });
            var deserializedToken    = (InvalidationToken)deserializedObjects[0];
            var deserializedRevision = (InvalidationToken.Revision)deserializedObjects[1];

            Assert.That(deserializedToken.IsCurrent(deserializedRevision), Is.True);
#if DEBUG
            Assert.That(
                () => token.IsCurrent(deserializedRevision),
                Throws.ArgumentException.With.Message.EqualTo(
                    "The Revision used for the comparision was not created by the current CacheInvalidationToken.\r\nParameter name: revision"));
#endif
        }
コード例 #9
0
        public void GetCurrent_FromSameCacheInvalidationToken_ReturnsSameRevisionTwice()
        {
            var token = InvalidationToken.CreatWithLocking();

            Assert.That(token.GetCurrent(), Is.EqualTo(token.GetCurrent()));
        }