public void Modify() { const int COUNT = 1000000; var cache = new EntityCache { BucketCount = COUNT / 7 }; Assert.AreEqual(0, cache.Count); for (int i = 0; i < COUNT; i++) { cache.Add(new EntityBase { ID = ObjectId.GenerateNewId() }); } Assert.AreEqual(COUNT, cache.Count); var entity1 = new EntityBase { ID = new ObjectId("5f32355b2fb32d25b863350f") }; cache.Add(entity1); Assert.AreEqual(COUNT + 1, cache.Count); Assert.AreEqual(entity1, cache.Remove(entity1.ID)); Assert.AreEqual(COUNT, cache.Count); Assert.AreEqual(null, cache.Replace(entity1));// 之前不存在,不能替换 Assert.AreEqual(null, cache.AddOrReplace(entity1)); Assert.AreEqual(entity1, cache.AddOrReplace(entity1)); Assert.AreEqual(entity1, cache.Replace(entity1)); Assert.AreEqual(COUNT + 1, cache.Count); Assert.AreEqual(entity1, cache.Get(entity1.ID)); }