/// <summary> Runs typical requests on the passed store </summary> private static async Task TestIKeyValueStoreImplementation(IKeyValueStore store) { string myKey1 = "myKey1"; var myValue1 = "myValue1"; string myKey2 = "myKey2"; var myValue2 = "myValue2"; var myFallbackValue1 = "myFallbackValue1"; // Cleanup before actual test starts: await store.Remove(myKey1); await store.Remove(myKey2); // test Set and Get of values: Assert.False(await store.ContainsKey(myKey1)); Assert.AreEqual(myFallbackValue1, await store.Get(myKey1, myFallbackValue1)); await store.Set(myKey1, myValue1); Assert.AreEqual(myValue1, await store.Get <string>(myKey1, null)); Assert.True(await store.ContainsKey(myKey1)); // Test replacing values: var oldVal = await store.Set(myKey1, myValue2); Assert.AreEqual(myValue1, oldVal); Assert.AreEqual(myValue2, await store.Get <string>(myKey1, null)); // Test add and remove of a second key: Assert.False(await store.ContainsKey(myKey2)); await store.Set(myKey2, myValue2); Assert.True(await store.ContainsKey(myKey2)); await store.Remove(myKey2); Assert.False(await store.ContainsKey(myKey2)); }
public async Task <JToken> GetDiffToPersisted(string id, params object[] objectsToCheck) { if (!await regressionStore.ContainsKey(id)) { await SaveToRegressionStore(id, objectsToCheck); return(null); } else { var jsonString = await regressionStore.Get <string>(id, null); var oldJson = JToken.Parse(jsonString); var newJson = JToken.Parse(JsonWriter.GetWriter(objectsToCheck).Write(objectsToCheck)); var diff = new JsonDiffPatch().Diff(oldJson, newJson); return(diff); } }
/// <summary> Runs typical requests on the passed store </summary> private static async Task TestIKeyValueStoreImplementation(IKeyValueStore store) { string myKey1 = "myKey1"; var myValue1 = "myValue1"; string myKey2 = "myKey2"; var myValue2 = "myValue2"; var myFallbackValue1 = "myFallbackValue1"; // test Set and Get of values: Assert.False(await store.ContainsKey(myKey1)); Assert.Equal(myFallbackValue1, await store.Get(myKey1, myFallbackValue1)); await store.Set(myKey1, myValue1); Assert.Equal(myValue1, await store.Get <string>(myKey1, null)); Assert.True(await store.ContainsKey(myKey1)); // Test replacing values: var oldVal = await store.Set(myKey1, myValue2); Assert.Equal(myValue1, oldVal); Assert.Equal(myValue2, await store.Get <string>(myKey1, null)); // Test add and remove of a second key: Assert.False(await store.ContainsKey(myKey2)); await store.Set(myKey2, myValue2); Assert.True(await store.ContainsKey(myKey2)); var keys = await store.GetAllKeys(); Assert.Equal(2, keys.Count()); Assert.True(await store.Remove(myKey2)); Assert.False(await store.ContainsKey(myKey2)); // Test RemoveAll: Assert.True(await store.ContainsKey(myKey1)); await store.RemoveAll(); Assert.False(await store.ContainsKey(myKey1)); }
public Task <bool> Contains(T item) { return(db.ContainsKey(item.GetId())); }
public async Task <bool> ContainsKey(string key) { return(await WrapWithTry(() => { return wrappedStore.ContainsKey(key); }, false)); }