Пример #1
0
        public void Test_Ctor()
        {
            ICache <string, int>       cache;
            CacheMonitor <string, int> cacheMonitor;

            cache        = CacheFactory.CreateSimpleCache <string, int>("Test");
            cacheMonitor = new CacheMonitor <string, int>(cache);

            Assert.That(cacheMonitor, Has.Property("Cache").SameAs(cache));
            Assert.That(cacheMonitor, Has.Property("ItemsRemoved").Empty);
        }
Пример #2
0
        public void Test_Removal()
        {
            ICache <string, int> cache;
            const string         testKey   = "Test Key";
            const int            testValue = 1234;

            cache = CacheFactory.CreateSimpleCache <string, int>("Test");
            using (CacheMonitor <string, int> cacheMonitor = new CacheMonitor <string, int>(cache))
            {
                Assert.That(cacheMonitor.ItemsRemoved, Is.Empty, "Not empty initially");
                cache.Add(testKey, testValue);
                Assert.That(cacheMonitor.ItemsRemoved, Is.Empty, "Not empty after all");
                cache.Remove(testKey);
                Assert.That(cacheMonitor.ItemsRemoved, Is.EquivalentTo(new [] { testKey }), "Incorrect after remove");
            }
        }
        public void Invalidation_ChangeSecuresFlagsFalseToTrue(string fieldAlias)
        {
            CachingEntityMemberRequestFactory cachingEntityMemberRequestFactory;

            EntityType[] entityTypes;
            Relationship relationshipType;
            CacheInvalidator <long, EntityMemberRequest> cacheInvalidator;

            var readPerm = new [] { Permissions.Read };

            // Setup the entities and relationships
            using (var ctx = DatabaseContext.GetContext(true, preventPostSaveActionsPropagating: true))
                using (new SecurityBypassContext())
                {
                    entityTypes = new[]
                    {
                        new EntityType {
                            Name = "Entity Type 1"
                        },
                        new EntityType {
                            Name = "Entity Type 2"
                        }
                    };
                    foreach (EntityType entityType in entityTypes)
                    {
                        entityType.Save();
                    }

                    relationshipType = new Relationship
                    {
                        FromType    = entityTypes[0],
                        ToType      = entityTypes[1],
                        SecuresTo   = false,
                        SecuresFrom = false
                    };
                    relationshipType.Save();
                    ctx.CommitTransaction();
                }

            // Build EMRs for both entity types
            cachingEntityMemberRequestFactory =
                Factory.Current.Resolve <CachingEntityMemberRequestFactory>();
            cachingEntityMemberRequestFactory.BuildEntityMemberRequest(entityTypes[0], readPerm);
            cachingEntityMemberRequestFactory.BuildEntityMemberRequest(entityTypes[1], readPerm);

            cacheInvalidator =
                (CacheInvalidator <long, EntityMemberRequest>)cachingEntityMemberRequestFactory.CacheInvalidator;


            using (CacheMonitor <long, EntityMemberRequest> cacheMonitor =
                       new CacheMonitor <long, EntityMemberRequest>(cachingEntityMemberRequestFactory.Cache))
            {
                // Change the flag
                using (var ctx = DatabaseContext.GetContext(true, preventPostSaveActionsPropagating: true))
                {
                    relationshipType.SetField(fieldAlias, true);
                    relationshipType.Save();
                    ctx.CommitTransaction();
                }
                // Ensure the cache has been invalidated
                foreach (var et in entityTypes.Select(et => et.Id))
                {
                    Assert.That(cacheMonitor.ItemsRemoved,
                                Contains.Item(et),
                                "Not removed");
                }
            }
        }