public void Test_OnEntityChange_InvalidCause() { CacheInvalidator <string, string> cacheInvalidator; cacheInvalidator = new CacheInvalidator <string, string>(new DictionaryCache <string, string>(), "a"); Assert.That(() => cacheInvalidator.OnEntityChange(new IEntity[0], (InvalidationCause)42, null), Throws.ArgumentException.And.Property("ParamName").EqualTo("cause")); }
public void Test_OnEntityChange_NullEntities() { CacheInvalidator <string, string> cacheInvalidator; cacheInvalidator = new CacheInvalidator <string, string>(new DictionaryCache <string, string>(), "a"); Assert.That(() => cacheInvalidator.OnEntityChange(null, InvalidationCause.Save, null), Throws.TypeOf <ArgumentNullException>().And.Property("ParamName").EqualTo("entities")); }
public void Test_OnEntityChange_EntitiesContainsNull() { CacheInvalidator <string, string> cacheInvalidator; cacheInvalidator = new CacheInvalidator <string, string>(new DictionaryCache <string, string>(), "a"); Assert.That(() => cacheInvalidator.OnEntityChange(new IEntity[] { null }, InvalidationCause.Save, null), Throws.ArgumentException.And.Property("ParamName").EqualTo("entities")); }
public void Test_OnEntityChange_EntityTypes() { MockRepository mockRepository; CacheInvalidator <long, string> cacheInvalidator; ICache <long, string> cache; IEntity[] testEntities; Mock <IEntity> mockEntity; const int numEntities = 10; const long typeIdOffset = 100; mockRepository = new MockRepository(MockBehavior.Loose); testEntities = new IEntity[numEntities]; for (int i = 0; i < testEntities.Length; i++) { mockEntity = mockRepository.Create <IEntity>(); mockEntity.SetupGet(e => e.Id).Returns(i); mockEntity.SetupGet(e => e.TypeIds).Returns(new [] { typeIdOffset + 100 }); testEntities[i] = mockEntity.Object; } cache = new DictionaryCache <long, string>(); for (int i = 0; i < numEntities; i++) { cache.Add(i, i.ToString()); } cacheInvalidator = new CacheInvalidator <long, string>(cache, "a"); // Make the second and third entities depend on the type of the first. using (CacheContext cacheContext = new CacheContext()) { cacheContext.EntityTypes.Add(testEntities[0].TypeIds.First()); // Will convert to EntityRef using this ID cacheInvalidator.AddInvalidations(cacheContext, testEntities[1].Id); cacheInvalidator.AddInvalidations(cacheContext, testEntities[2].Id); } // Save the first entity (only) cacheInvalidator.OnEntityChange(new [] { testEntities[0] }, InvalidationCause.Save, null); Assert.That( cache.Select(ce => ce.Key), Is.EquivalentTo( testEntities.Select(er => er.Id) .Where(id => id != testEntities[1].Id && id != testEntities[2].Id)), "Second and third entities (only) have not been removed"); }