public void TestRemove()
        {
            var d = new DynamicDictionary();

            d.Add("key", "value");

            Assert.IsTrue(d.Remove("key"), "Did not remove key: \"key\"");
        }
        public void DynamicDictionary_EventsTests()
        {
            DynamicDictionary d = new DynamicDictionary();

            int countAdd     = 0;
            int countRemove  = 0;
            int countChanged = 0;
            int countClear   = 0;
            int countOther   = 0;

            d.OnChange += (sender, e) =>
            {
                switch (e.EventType)
                {
                case DynamicDictionaryChangedType.AddedValue:
                    countAdd++;
                    break;

                case DynamicDictionaryChangedType.RemovedValue:
                    countRemove++;
                    break;

                case DynamicDictionaryChangedType.ChangedValue:
                    countChanged++;
                    break;

                case DynamicDictionaryChangedType.Clear:
                    countClear++;
                    break;

                default:
                    countOther++;
                    break;
                }
            };

            d["1"] = "Main";
            Assert.AreEqual(1, countAdd);

            d["1"] = "Main";
            Assert.AreEqual(0, countChanged);

            d["2"] = "New";
            Assert.AreEqual(2, countAdd);

            d["2"] = "Test";
            Assert.AreEqual(1, countChanged);

            d.Add("3", "Name");
            Assert.AreEqual(3, countAdd);

            d.Remove("3");
            Assert.AreEqual(1, countRemove);

            d.Clear();
            Assert.AreEqual(1, countClear);
            Assert.AreEqual(0, countOther);
        }
        public void TestRemoveKeyValuePair()
        {
            var d = new DynamicDictionary();

            d.Add("key", "value");

            Assert.IsTrue(d.Remove(new KeyValuePair <string, object>("key", "value")));

            Assert.AreEqual(0, d.Count);
        }
예제 #4
0
        public virtual BangoCommand GetSearchCommand(SearchScenario scenario, DbConnect con, BangoCommand cmd, DynamicDictionary data_param, string selectClause, string orderByClause, int page = -1, int pageSize = 20, bool count = false, string tableAlias = null, string scenarioOthers = null)
        {
            TableDetailAttribute tableDetail = _model.GetTableDetail();
            //clear the params whic are empty or null
            List <string> keys = new List <string>(data_param.KeyList.Cast <String>());

            foreach (string key in keys)
            {
                object value = data_param.GetValue(key);
                if (value == null || data_param.GetValueAsString(key).Length == 0)
                {
                    data_param.Remove(key);
                }
            }

            //BangoCommand cmd = GetSearchCommandTemplate(selectClause, count, tableAlias);
            //cmd.Sql.AppendLine("FROM " + model.GetTableName());
            IDbExpression dbExp = App.Container.GetInstance <IDbExpression>();

            if (data_param.GetCount() == 0)
            {
                return(cmd);
            }

            string append = DbServiceUtility.GetTableAliasForColumn(tableAlias);

            if (!(scenario == SearchScenario.TreeNode && count == false))
            {
                //check & adding delete flag check sql
                DbServiceUtility.BindDeleteParameter(cmd, _model, tableAlias);

                if (CheckClientID)
                {
                    DbServiceUtility.BindClientIdParameter(cmd, _model, tableAlias, DisplayMasterDataFromSystem);
                }

                //add remaining default search criteria

                cmd = BeforeBindingParameter(scenario, con, cmd, data_param, count, tableAlias);
                cmd = DbServiceUtility.BindParameters(cmd, _model, data_param, tableAlias);
                cmd = AfterBindingParameter(scenario, con, cmd, data_param, count, tableAlias);

                //check & adding order by clause
                if (count == false)
                {
                    cmd = BeforeBindingOrderBy(scenario, con, cmd, data_param, count, tableAlias);
                    cmd = DbServiceUtility.BindOrderBy(cmd, orderByClause);
                    cmd = AfterBindingOrderBy(scenario, con, cmd, data_param, count, tableAlias);
                    cmd = DbServiceUtility.BindPagination(cmd, page, pageSize);
                }
            }
            return(cmd);
        }
예제 #5
0
        public void Should_return_false_when_string_overload_of_remove_method_cannot_match_key()
        {
            var input = new DynamicDictionary();

            input["test"] = 10;

            // When
            var result = input.Remove("test1");

            // Then
            result.ShouldBeFalse();
        }
예제 #6
0
        public void Should_return_false_when_keyvaluepair_overload_of_remove_method_cannot_match_key()
        {
            var input = new DynamicDictionary();

            input["test"] = 10;

            // When
            var result = input.Remove(new KeyValuePair <string, dynamic>("test1", 10));

            // Then
            result.ShouldBeFalse();
        }
예제 #7
0
        public void Should_remove_natural_key()
        {
            // Given
            var input = new DynamicDictionary();

            input.Add("a-b-c", "hello");

            //when
            input.Remove("a-b-c");

            //then
            input.ContainsKey("abc").ShouldBeFalse();
        }
예제 #8
0
        public void Should_remove_item_when_string_overload_of_remove_method_is_invoked()
        {
            // Given
            var input = new DynamicDictionary();

            input["test"] = 10;

            // When
            input.Remove("test");

            // Then
            input.ContainsKey("test").ShouldBeFalse();
        }
예제 #9
0
        public void Should_remove_item_when_keyvaluepair_overload_of_remove_method_is_invoked()
        {
            // Given
            var input = new DynamicDictionary();

            input["test"] = 10;

            // When
            input.Remove(new KeyValuePair <string, dynamic>("test", 10));

            // Then
            input.ContainsKey("test").ShouldBeFalse();
        }
        public void TestCount()
        {
            var d = new DynamicDictionary();

            Assert.AreEqual(0, d.Count);

            d.Add("key", "value");

            Assert.AreEqual(1, d.Count);

            d.Remove("key");

            Assert.AreEqual(0, d.Count);
        }
예제 #11
0
파일: Demo.cs 프로젝트: MikhaskoS/Patterns
        internal static void Test()
        {
            // Динамический словарь.
            dynamic person = new DynamicDictionary();

            // Динамические свойства
            person.FirstName = "Ellen";
            person.LastName  = "Adams";

            person.ToString();

            // TryInvokeMember делает доступными методы словаря
            person.Remove("firstname");
            person.ToString();

            person.Clear();   // TryInvokeMember
        }
예제 #12
0
        protected override DynamicDictionary Sort(DynamicDictionary proxyDictionary)
        {
            var newProxyDictionary = new DynamicDictionary();
            var sortedList         = (from entry in SortKeys
                                      orderby entry.Value ascending
                                      select entry).ToDictionary(c => c.Key, t => t.Value);

            foreach (var item in sortedList.Keys)
            {
                var checkItem = proxyDictionary.TryGetValue(item, out var value);
                if (checkItem)
                {
                    newProxyDictionary.Add(item, value);
                    proxyDictionary.Remove(item);
                }
            }

            foreach (var item in proxyDictionary)
            {
                newProxyDictionary.Add(item.Key, item.Value);
            }

            return(newProxyDictionary);
        }
예제 #13
0
        public virtual bool Insert(DbConnect con, DynamicDictionary data)
        {
            //create empty object
            TModel empty = new TModel();
            ChangeHistoryHelper <TModel> chngHlpr = null;

            chngHlpr = new ChangeHistoryHelper <TModel>(AuditActivityTypes.INSERT);
            PropertyInfo key = Models.ModelService.GetKeyPropertyInfo(empty);

            if (data.ContainsKey(key.Name))
            {
                data.Remove(key.Name);
            }
            //if CREATED_BY, CREATED_on field exists then update those fields
            PropertyInfo by = empty.GetType().GetProperty("created_by");

            if (by != null)
            {
                data.SetValue("created_by", SessionData.user_id);
            }
            PropertyInfo on = empty.GetType().GetProperty("created_on");

            if (on != null)
            {
                data.SetValue("created_on", DateTime.Now);
            }
            if (CheckClientID)
            {
                PropertyInfo client_id = empty.GetType().GetProperty("client_id");
                if (client_id != null)
                {
                    if (!data.ContainsKey("client_id"))
                    {
                        data.SetValue("client_id", SessionData.client_id);
                    }
                }
            }

            chngHlpr.CheckChangeChanges(new TModel(), data);
            ITable <TModel, int?> tbl = con.GetModelTable <TModel>();
            int?id = null;

            try
            {
                id = tbl.Insert(chngHlpr.Diff);
                //set the primary key in the object

                if (key != null)
                {
                    data.SetValue(key.Name, id);
                }

                if (TrackChanges)
                {
                    // chngHlpr.Changes.pkey_value = Convert.ToString(id);
                    //save the changes
                    chngHlpr.LogChanges(con);
                }
            }
            catch (Npgsql.NpgsqlException ex)
            {
                LogTrace.WriteErrorLog(ex.ToString());
                LogTrace.WriteDebugLog(string.Format("sql which gave exception:\r{0}", ex.Routine));
                throw ex;
            }
            if (id > 0)
            {
                return(true);
            }
            return(false);
        }
        public void Should_return_true_when_string_overload_of_remove_method_can_match_key()
        {
            var input = new DynamicDictionary();
            input["test"] = 10;

            // When
            var result = input.Remove("test");

            // Then
            result.ShouldBeTrue();
        }
        public void Should_return_true_when_keyvaluepair_overload_of_remove_method_can_match_key()
        {
            var input = new DynamicDictionary();
            input["test"] = 10;

            // When
            var result = input.Remove(new KeyValuePair<string, dynamic>("test", 10));

            // Then
            result.ShouldBeTrue();
        }
        public void Should_remove_natural_key()
        {
            // Given
            var input = new DynamicDictionary();
            input.Add("a-b-c", "hello");

            //when
            input.Remove("a-b-c");

            //then
            input.ContainsKey("abc").ShouldBeFalse();
        }
        public void Should_remove_item_when_string_overload_of_remove_method_is_invoked()
        {
            // Given
            var input = new DynamicDictionary();
            input["test"] = 10;

            // When
            input.Remove("test");

            // Then
            input.ContainsKey("test").ShouldBeFalse();
        }
        public void Should_remove_item_when_keyvaluepair_overload_of_remove_method_is_invoked()
        {
            // Given
            var input = new DynamicDictionary();
            input["test"] = 10;

            // When
            input.Remove(new KeyValuePair<string, dynamic>("test", 10));

            // Then
            input.ContainsKey("test").ShouldBeFalse();
        }
        public void TestRemoveKeyValuePair()
        {
            var d = new DynamicDictionary();

            d.Add("key", "value");

            Assert.IsTrue(d.Remove(new KeyValuePair<string, object>("key", "value")));

            Assert.AreEqual(0, d.Count);
        }
        public void TestCount()
        {
            var d = new DynamicDictionary();

            Assert.AreEqual(0, d.Count);

            d.Add("key", "value");

            Assert.AreEqual(1, d.Count);

            d.Remove("key");

            Assert.AreEqual(0, d.Count);
        }
        public void TestRemove()
        {
            var d = new DynamicDictionary();

            d.Add("key", "value");

            Assert.IsTrue(d.Remove("key"), "Did not remove key: \"key\"");
        }