Exemplo n.º 1
0
        public void Test_OnRelationshipChange()
        {
            CacheInvalidator <int, string> cacheInvalidator;
            ICache <int, string>           cache;

            EntityRef[]       testRelationshipTypes;
            const int         numRelationshipTypes = 10;
            Func <long, bool> relationshipTypesToRemove;

            cache = new DictionaryCache <int, string>();
            for (int i = 0; i < numRelationshipTypes; i++)
            {
                cache.Add(i, i.ToString());
            }

            relationshipTypesToRemove = e => e % 2 == 0; // All even numbered relationship types.
            testRelationshipTypes     = Enumerable.Range(0, numRelationshipTypes)
                                        .Where(i => relationshipTypesToRemove(i))
                                        .Select(i => new EntityRef(i)).ToArray();

            cacheInvalidator = new CacheInvalidator <int, string>(cache, "a");

            for (int i = 0; i < numRelationshipTypes; i++)
            {
                using (CacheContext cacheContext = new CacheContext())
                {
                    cacheContext.RelationshipTypes.Add(i);
                    cacheInvalidator.AddInvalidations(cacheContext, i);
                }
            }

            cacheInvalidator.OnRelationshipChange(testRelationshipTypes);

            Assert.That(cache.Where(ce => relationshipTypesToRemove(ce.Key)), Is.Empty);
        }
Exemplo n.º 2
0
        public void Test_OnRelationshipChange_RelationshipTypesContainsNull()
        {
            CacheInvalidator <string, string> cacheInvalidator;

            cacheInvalidator = new CacheInvalidator <string, string>(new DictionaryCache <string, string>(), "a");

            Assert.That(() => cacheInvalidator.OnRelationshipChange(new EntityRef[] { null }),
                        Throws.ArgumentException.And.Property("ParamName").EqualTo("relationshipTypes"));
        }
Exemplo n.º 3
0
        public void Test_OnRelationshipChange_NullRelationshipTypes()
        {
            CacheInvalidator <string, string> cacheInvalidator;

            cacheInvalidator = new CacheInvalidator <string, string>(new DictionaryCache <string, string>(), "a");

            Assert.That(() => cacheInvalidator.OnRelationshipChange(null),
                        Throws.TypeOf <ArgumentNullException>().And.Property("ParamName").EqualTo("relationshipTypes"));
        }