Exemple #1
0
        public void Test_OnFieldChange_NullFieldTypes()
        {
            CacheInvalidator <int, string> cacheInvalidator;

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

            Assert.That(() => cacheInvalidator.OnFieldChange(null),
                        Throws.TypeOf <ArgumentNullException>().And.Property("ParamName").EqualTo("fieldTypes"));
        }
Exemple #2
0
        public void Test_OnFieldChange()
        {
            CacheInvalidator <int, string> cacheInvalidator;
            ICache <int, string>           cache;

            long[]            testFieldTypes;
            const int         numFieldTypes = 10;
            Func <long, bool> fieldTypesToRemove;

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

            fieldTypesToRemove = e => e % 2 == 0; // All even numbered relationship types.
            testFieldTypes     = Enumerable.Range(0, numFieldTypes)
                                 .Where(i => fieldTypesToRemove(i))
                                 .Select(i => (long)i)
                                 .ToArray();

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

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

            cacheInvalidator.OnFieldChange(testFieldTypes);

            Assert.That(cache.Where(ce => fieldTypesToRemove(ce.Key)), Is.Empty);
        }