public void TestFindInternal() { cloneCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); var items = cloneCache.Find(new MyKey("key1").ToArray()); Enumerable.ElementAt <KeyValuePair <MyKey, MyValue> >(items, 0).Key.Should().Be(new MyKey("key1")); Enumerable.ElementAt <KeyValuePair <MyKey, MyValue> >(items, 0).Value.Should().Be(new MyValue("value1")); Enumerable.Count <KeyValuePair <MyKey, MyValue> >(items).Should().Be(1); items = cloneCache.Find(new MyKey("key2").ToArray()); Enumerable.ElementAt <KeyValuePair <MyKey, MyValue> >(items, 0).Key.Should().Be(new MyKey("key2")); Enumerable.ElementAt <KeyValuePair <MyKey, MyValue> >(items, 0).Value.Should().Be(new MyValue("value2")); Enumerable.Count <KeyValuePair <MyKey, MyValue> >(items).Should().Be(1); items = cloneCache.Find(new MyKey("key3").ToArray()); Enumerable.ElementAt <KeyValuePair <MyKey, MyValue> >(items, 0).Key.Should().Be(new MyKey("key3")); Enumerable.ElementAt <KeyValuePair <MyKey, MyValue> >(items, 0).Value.Should().Be(new MyValue("value3")); Enumerable.Count <KeyValuePair <MyKey, MyValue> >(items).Should().Be(1); items = cloneCache.Find(new MyKey("key4").ToArray()); Enumerable.Count <KeyValuePair <MyKey, MyValue> >(items).Should().Be(0); }
public void TestFindInternal() { cloneCache.Add(new MyKey("key1"), new MyValue("value1")); myDataCache.Add(new MyKey("key2"), new MyValue("value2")); myDataCache.InnerDict.Add(new MyKey("key3"), new MyValue("value3")); var items = cloneCache.Find(new MyKey("key1").ToArray()); items.ElementAt(0).Key.Should().Be(new MyKey("key1")); items.ElementAt(0).Value.Should().Be(new MyValue("value1")); items.Count().Should().Be(1); items = cloneCache.Find(new MyKey("key2").ToArray()); items.ElementAt(0).Key.Should().Be(new MyKey("key2")); items.ElementAt(0).Value.Should().Be(new MyValue("value2")); items.Count().Should().Be(1); items = cloneCache.Find(new MyKey("key3").ToArray()); items.ElementAt(0).Key.Should().Be(new MyKey("key3")); items.ElementAt(0).Value.Should().Be(new MyValue("value3")); items.Count().Should().Be(1); items = cloneCache.Find(new MyKey("key4").ToArray()); items.Count().Should().Be(0); }
public void TestCachedFind_Last() { var snapshot = Blockchain.Singleton.GetSnapshot(); var storages = snapshot.Storages; var cache = new CloneCache <StorageKey, StorageItem>(storages); storages.DeleteWhere((k, v) => k.ScriptHash == UInt160.Zero); storages.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x01 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); storages.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x01 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x02 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x02 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); CollectionAssert.AreEqual( cache.Find(new byte[21]).Select(u => u.Key.Key[1]).ToArray(), new byte[] { 0x01, 0x02 } ); storages.DeleteWhere((k, v) => k.ScriptHash == UInt160.Zero); }
public void TestCachedFind_Empty() { var snapshot = Blockchain.Singleton.GetSnapshot(); var storages = snapshot.Storages.CreateSnapshot(); var cache = new CloneCache <StorageKey, StorageItem>(storages); cache.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x02 }, Id = 0 }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x02 }, Id = 0 }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); CollectionAssert.AreEqual( cache.Find(new byte[5]).Select(u => u.Key.Key[1]).ToArray(), new byte[] { 0x02 } ); }
public void TestCachedFind_Between() { var snapshot = TestBlockchain.GetStore().GetSnapshot(); var storages = snapshot.Storages; var cache = new CloneCache <StorageKey, StorageItem>(storages); storages.DeleteWhere((k, v) => k.ScriptHash == UInt160.Zero); storages.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x01 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); storages.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x01 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); storages.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x03 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x01, 0x02 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); cache.Add ( new StorageKey() { Key = new byte[] { 0x00, 0x02 }, ScriptHash = UInt160.Zero }, new StorageItem() { IsConstant = false, Value = new byte[] { } } ); CollectionAssert.AreEqual( Enumerable.Select <KeyValuePair <StorageKey, StorageItem>, byte>(cache.Find(new byte[21]), u => u.Key.Key[1]).ToArray(), new byte[] { 0x01, 0x02, 0x03 } ); storages.DeleteWhere((k, v) => k.ScriptHash == UInt160.Zero); }