public async Task receives_key() { string receivedKey = null; byte[] receivedValue = null; Action <IEnumerable <KeyValuePair <string, byte[]> > > keyReceiver = (kvs) => { foreach (var kv in kvs) { receivedKey = kv.Key; receivedValue = kv.Value; } }; var updater = Structure.Start(keyReceiver, TestOptions()); ConsulKvSimulator.PutKey("key", "value"); var assignedKv = await KeyValuesAssigned.Dequeue(); receivedKey.ShouldBe(assignedKv.Single().Key); receivedKey.ShouldBe("key"); receivedValue.ShouldBe(Encoding.UTF8.GetBytes("value")); receivedValue.ShouldBe(assignedKv.Single().Value); await updater.Stop(); }
public async Task key_is_assigned_once() { var config = new SimpleProperties(); var updater = Structure.Start(config, TestOptions()); ConsulKvSimulator.PutKey("keystring", "http"); await KeyValuesAssigned.Dequeue(); config.KeyString.ShouldBe("http"); await updater.Stop(); }
public async Task mutliple_key_changes_get_correct_value() { var config = new SimpleProperties(); ConsulKvSimulator.PutKey("keystring", "first"); ConsulKvSimulator.PutKey("keystring", "second"); var updater = Structure.Start(config, TestOptions()); var lastResult = await KeyValuesAssigned.Dequeue(); lastResult.Last().Value.ShouldBe("second"); config.KeyString.ShouldBe("second"); await updater.Stop(); }
public async Task key_is_assigned_repeatedly() { var config = new SimpleProperties(); var updater = Structure.Start(config, TestOptions()); ConsulKvSimulator.PutKey("keystring", "first"); await KeyValuesAssigned.Dequeue(); config.KeyString.ShouldBe("first"); await Task.WhenAll( ConsulKvSimulator.PutKeyWithDelay("keystring", "second", TimeSpan.FromSeconds(3)), KeyValuesAssigned.Dequeue()); config.KeyString.ShouldBe("second"); await updater.Stop(); }