public async Task TestReplaceAndRemove() { var key1 = "key1"; var value1 = "value1"; var fallback1 = "fallback1"; var s1 = new InMemoryKeyValueStore(); var s2 = NewFileBasedKeyValueStore("TestReplaceAndRemoveDir").WithFallbackStore(s1); var s3 = new InMemoryKeyValueStore().WithFallbackStore(s2); await s1.Set(key1, value1); // Test that replace with same value via s3 returns the old value (which is also value1): Assert.Equal(value1, await s3.Set(key1, value1)); // s3 will ask s2 which will ask s1 so the value will be returned correctly: Assert.Equal(value1, await s3.Get(key1, fallback1)); Assert.Single(await s3.GetAllKeys()); Assert.True(await s3.Remove(key1)); // Setting it again will return null since it was removed from all stores: Assert.Null(await s3.Set(key1, value1)); Assert.True(await s1.Remove(key1)); // Remove it only from s1 Assert.Equal(value1, await s3.Get(key1, fallback1)); // Still cached in s3 and s2 // s1 had the key already removed, so the combined remove result will be false: Assert.False(await s3.Remove(key1)); }
public void RemoveWithHash_ExistingKeyValue_RemoveSuccessful() { // Arrange _inMemoryStore.InMemoryStore.TryAdd("existing-key", new HashedValue <object> { Value = "existing-value", Hash = "existing-hash" }); // Act var removeResult = _inMemoryStore.Remove("existing-key", "existing-hash"); // Assert removeResult.Should().Be(true); _inMemoryStore.InMemoryStore.Keys.Should().NotContain(k => k == "existing-key"); }