コード例 #1
0
ファイル: DataFlowTests.cs プロジェクト: beyaz/DataFlow
        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");
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
ファイル: DataFlowTests.cs プロジェクト: beyaz/DataFlow
        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");
        }
コード例 #4
0
ファイル: DataFlowTests.cs プロジェクト: beyaz/DataFlow
        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");
        }
コード例 #5
0
        /// <summary>
        ///     Called when [inserted].
        /// </summary>
        void OnInserted <T>(DataKey <T> dataKey)
        {
            var eventName = GetInsertEventName(dataKey);

            eventBus.Publish(eventName);
        }
コード例 #6
0
 /// <summary>
 ///     Called when [remove].
 /// </summary>
 public void OnRemove <T>(DataKey <T> dataKey, Action action)
 {
     eventBus.Subscribe(GetRemoveEventName(dataKey), action);
 }
コード例 #7
0
 /// <summary>
 ///     Called when [update].
 /// </summary>
 public void OnUpdate <T>(DataKey <T> dataKey, Action action)
 {
     eventBus.Subscribe(GetUpdateEventName(dataKey), action);
 }
コード例 #8
0
 /// <summary>
 ///     Called when [insert].
 /// </summary>
 public void OnInsert <T>(DataKey <T> dataKey, Action action)
 {
     eventBus.Subscribe(GetInsertEventName(dataKey), action);
 }
コード例 #9
0
 /// <summary>
 ///     Gets the name of the remove event.
 /// </summary>
 string GetRemoveEventName <T>(DataKey <T> dataKey)
 {
     return("Remove->" + dataKey.Id);
 }
コード例 #10
0
 /// <summary>
 ///     Gets the name of the update event.
 /// </summary>
 string GetUpdateEventName <T>(DataKey <T> dataKey)
 {
     return("Update->" + dataKey.Id);
 }
コード例 #11
0
 /// <summary>
 ///     Gets the identifier.
 /// </summary>
 string GetId <T>(DataKey <T> dataKey)
 {
     return(GetId(dataKey.Id));
 }
コード例 #12
0
 /// <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}'"));
 }
コード例 #13
0
        /// <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));
        }
コード例 #14
0
        /// <summary>
        ///     Determines whether [contains] [the specified data key].
        /// </summary>
        public bool Contains <T>(DataKey <T> dataKey)
        {
            var id = GetId(dataKey);

            return(dictionary.ContainsKey(id));
        }
コード例 #15
0
        /// <summary>
        ///     Called when [updated].
        /// </summary>
        void OnUpdated <T>(DataKey <T> dataKey)
        {
            var eventName = GetUpdateEventName(dataKey);

            eventBus.Publish(eventName);
        }
コード例 #16
0
        /// <summary>
        ///     Called when [removed].
        /// </summary>
        void OnRemoved <T>(DataKey <T> dataKey)
        {
            var eventName = GetRemoveEventName(dataKey);

            eventBus.Publish(eventName);
        }
コード例 #17
0
 /// <summary>
 ///     Gets the name of the insert event.
 /// </summary>
 string GetInsertEventName <T>(DataKey <T> dataKey)
 {
     return("Insert->" + dataKey.Id);
 }