public void Forwarded_keys_cannot_be_modify() { var keyA = new DataKey <string>(typeof(DataFlowTests), "A"); var keyB = new DataKey <string>(typeof(DataFlowTests), "B"); var context = new DataContext(); context.Add(keyA, "A"); context.ForwardKey(keyB, keyA); context.Contains(keyA).Should().BeTrue(); context.Contains(keyB).Should().BeTrue(); context.Add(keyB, "B"); }
/// <summary> /// Removes the specified data key. /// </summary> public void Remove <T>(DataKey <T> dataKey) { DataContextEntry dataContextEntry = null; if (dictionary.TryGetValue(dataKey.Id, out dataContextEntry)) { if (dataContextEntry.Layer != LayerHelper.GetCurrentLayerId(layerNames)) { throw new DataFlowException($"Other layer variables can not be remove. CurrentLayer: {LayerHelper.GetCurrentLayerId(layerNames)}, TargetLayer: {dataContextEntry.Layer}"); } dictionary.Remove(dataKey.Id); OnRemoved(dataKey); return; } throw NoDataFoundException(dataKey); }
public void Should_fire_events_when_layer_closed() { var context = new DataContext(); var key1 = new DataKey <string>(typeof(DataFlowTests), "key1"); var key2 = new DataKey <string>(typeof(DataFlowTests), "key2"); var key3 = new DataKey <string>(typeof(DataFlowTests), "key3"); var key4 = new DataKey <string>(typeof(DataFlowTests), "key4"); var temp = ""; context.OnRemove(key1, () => temp = "key1_remoed"); context.OpenNewLayer("L1"); temp.Should().Be(string.Empty); context.Add(key1, "A"); context.Add(key2, "B"); context.CloseCurrentLayer(); temp.Should().Be("key1_remoed"); }
public void Should_get_data_when_virtual_key_used() { var context = new DataContext(); var key1 = new DataKey <string>(typeof(DataFlowTests), "key1"); var key2 = new DataKey <string>(typeof(DataFlowTests), "key2"); var key3 = new DataKey <string>(typeof(DataFlowTests), "key3"); var key4 = new DataKey <string>(typeof(DataFlowTests), "key4"); context.Add(key1, "A"); context.Add(key2, "B"); context.Contains(key3).Should().BeFalse(); context.SetupGet(key3, c => c.Get(key1) + "X" + c.Get(key2)); context.Get(key3).Should().Be("AXB"); context.ForwardKey(key4, key3); context.Get(key4).Should().Be("AXB"); }
/// <summary> /// Called when [inserted]. /// </summary> void OnInserted <T>(DataKey <T> dataKey) { var eventName = GetInsertEventName(dataKey); eventBus.Publish(eventName); }
/// <summary> /// Called when [remove]. /// </summary> public void OnRemove <T>(DataKey <T> dataKey, Action action) { eventBus.Subscribe(GetRemoveEventName(dataKey), action); }
/// <summary> /// Called when [update]. /// </summary> public void OnUpdate <T>(DataKey <T> dataKey, Action action) { eventBus.Subscribe(GetUpdateEventName(dataKey), action); }
/// <summary> /// Called when [insert]. /// </summary> public void OnInsert <T>(DataKey <T> dataKey, Action action) { eventBus.Subscribe(GetInsertEventName(dataKey), action); }
/// <summary> /// Gets the name of the remove event. /// </summary> string GetRemoveEventName <T>(DataKey <T> dataKey) { return("Remove->" + dataKey.Id); }
/// <summary> /// Gets the name of the update event. /// </summary> string GetUpdateEventName <T>(DataKey <T> dataKey) { return("Update->" + dataKey.Id); }
/// <summary> /// Gets the identifier. /// </summary> string GetId <T>(DataKey <T> dataKey) { return(GetId(dataKey.Id)); }
/// <summary> /// Noes the data found exception. /// </summary> static DataFlowException NoDataFoundException <T>(DataKey <T> dataKey) { return(new DataFlowException($"No data found in context. Data key is '{dataKey}'")); }
/// <summary> /// Setups the get. /// </summary> public void SetupGet <T>(DataKey <T> dataKey, Func <DataContext, T> getHandler) { var id = GetId(dataKey); getHandlers.Add(id, c => getHandler(c)); }
/// <summary> /// Determines whether [contains] [the specified data key]. /// </summary> public bool Contains <T>(DataKey <T> dataKey) { var id = GetId(dataKey); return(dictionary.ContainsKey(id)); }
/// <summary> /// Called when [updated]. /// </summary> void OnUpdated <T>(DataKey <T> dataKey) { var eventName = GetUpdateEventName(dataKey); eventBus.Publish(eventName); }
/// <summary> /// Called when [removed]. /// </summary> void OnRemoved <T>(DataKey <T> dataKey) { var eventName = GetRemoveEventName(dataKey); eventBus.Publish(eventName); }
/// <summary> /// Gets the name of the insert event. /// </summary> string GetInsertEventName <T>(DataKey <T> dataKey) { return("Insert->" + dataKey.Id); }