Пример #1
0
        public void CreateCombinedKey_NullOrEmpty_ShouldReturnDefault()
        {
            var parser = CombineKeyParser.NewForTest();

            parser.CreateCombinedKey(null).ShouldEqual(string.Empty);
            parser.CreateCombinedKey(new Dictionary <string, object>()).ShouldEqual(string.Empty);
        }
Пример #2
0
        public void AutoGetCombinedKey_ObjectExt_ShouldOk()
        {
            var parser = CombineKeyParser.NewForTest();
            var foo    = new CombineKeyFoo();

            parser.AutoGetCombinedKey(foo, "A", "b").ShouldEqual("A=a&b=1");
        }
Пример #3
0
        public static T SetPropertiesByCombinedKey <T>(this T model, string combinedKeyName, string[] includeKeyNames, ICombineKeyParser parser = null)
        {
            if (model == null)
            {
                return(default(T));
            }

            if (includeKeyNames == null || includeKeyNames.Length == 0)
            {
                return(model);
            }

            if (string.IsNullOrWhiteSpace(combinedKeyName))
            {
                return(model);
            }

            var combineKeyValue = GetProperty(model, combinedKeyName);

            if (combineKeyValue == null)
            {
                return(model);
            }

            var combineKeyParser = parser ?? CombineKeyParser.Resolve();
            var includeKeys      = combineKeyParser.ParseCombinedKey(combineKeyValue.ToString());

            foreach (var includeKey in includeKeys)
            {
                SetProperty(model, includeKey.Key, includeKey.Value);
            }
            return(model);
        }
Пример #4
0
        public void ParseCombinedKey_NullOrEmpty_ShouldReturnDefault()
        {
            var parser = CombineKeyParser.NewForTest();

            parser.ParseCombinedKey(null).Count.ShouldEqual(0);
            parser.ParseCombinedKey("").Count.ShouldEqual(0);
            parser.ParseCombinedKey(" ").Count.ShouldEqual(0);
        }
Пример #5
0
        public void SetCombinedKeyByProperties_ObjectExt_ShouldOk()
        {
            var parser = CombineKeyParser.NewForTest();
            var bar    = new Bar();

            bar.A = "a";
            bar.B = 1;
            bar.SetCombinedKeyByProperties("MyKey", new [] { "A", "b" }, parser).MyKey.ShouldEqual("A=a&b=1");
        }
Пример #6
0
        public void SetCombinedKeyByProperties_GenericExt_ShouldOk()
        {
            var parser = CombineKeyParser.NewForTest();
            var foo    = new Foo();

            foo.A = "a";
            foo.B = 1;
            foo.SetCombinedKeyByProperties(parser).MyKey.ShouldEqual("A=a&B=1");
        }
Пример #7
0
        public void AutoSetCombinedKey_ObjectExt_ShouldOk()
        {
            var parser = CombineKeyParser.NewForTest();
            var foo    = new CombineKeyFoo();

            parser.AutoSetCombinedKey(foo, "A", "aa");
            parser.AutoSetCombinedKey(foo, "B", 11);
            foo.A.ShouldEqual("aa");
            foo.B.ShouldEqual(11);
        }
Пример #8
0
        public void AutoGetCombinedKey_DicExt_ShouldOk()
        {
            var parser = CombineKeyParser.NewForTest();
            var items  = new Dictionary <string, object>();

            items.Add("A", "a");
            items.Add("b", 1);
            items.Add("C", "c");
            parser.AutoGetCombinedKey(items, "A", "B").ShouldEqual("A=a&B=1");
        }
Пример #9
0
        public void CreateCombinedKey_AllKey_ShouldInclude()
        {
            var parser = CombineKeyParser.NewForTest();
            var dic    = new Dictionary <string, object>();

            dic.Add("A", "a");
            dic.Add("B", "");
            dic.Add("C", "c");
            parser.CreateCombinedKey(dic).ShouldEqual("A=a&B=&C=c");
        }
Пример #10
0
        public void ParseCombinedKey_AllKey_ShouldInclude()
        {
            var parser = CombineKeyParser.NewForTest();
            var dic    = parser.ParseCombinedKey("A=a&B=&c=c");

            dic.Count.ShouldEqual(3);
            dic["A"].ShouldEqual("a");
            dic["B"].ShouldEqual("");
            dic["C"].ShouldEqual("c");
            dic["c"].ShouldEqual("c");
        }
Пример #11
0
        public void SetPropertiesByCombinedKey_ObjectExt_ShouldOk()
        {
            var parser = CombineKeyParser.NewForTest();
            var foo    = new Bar();

            foo.MyKey = "A=a&b=1";
            foo.SetPropertiesByCombinedKey("MyKey", new[] { "A", "B" }, parser);

            foo.A.ShouldEqual("a");
            foo.B.ShouldEqual(1);
        }
Пример #12
0
        public void SetPropertiesByCombinedKey_GenericExt_ShouldOk()
        {
            var parser = CombineKeyParser.NewForTest();
            var foo    = new Foo();

            foo.MyKey = "A=a&b=1";
            foo.SetPropertiesByCombinedKey(parser);

            foo.A.ShouldEqual("a");
            foo.B.ShouldEqual(1);
        }
Пример #13
0
        public void AutoSetCombinedKey_DicExt_ShouldOk()
        {
            var parser = CombineKeyParser.NewForTest();
            var items  = new Dictionary <string, object>();

            items.Add("A", "a");
            items.Add("b", 1);
            items.Add("C", "c");

            parser.AutoSetCombinedKey(items, "A", "aa");
            parser.AutoSetCombinedKey(items, "B", 11);
            parser.AutoSetCombinedKey(items, "D", "d");

            items["A"].ShouldEqual("aa");
            items["b"].ShouldEqual(11);
            items["C"].ShouldEqual("c");
        }
Пример #14
0
        public static T SetCombinedKeyByProperties <T>(this T model, string combinedKeyName, string[] includeKeyNames, ICombineKeyParser parser = null)
        {
            if (model == null)
            {
                return(default(T));
            }

            if (includeKeyNames == null || includeKeyNames.Length == 0)
            {
                return(model);
            }
            if (string.IsNullOrWhiteSpace(combinedKeyName))
            {
                return(model);
            }

            var combineKeyParser = parser ?? CombineKeyParser.Resolve();
            var combinedKeyValue = combineKeyParser.AutoGetCombinedKey(model, includeKeyNames);

            SetProperty(model, combinedKeyName, combinedKeyValue);
            return(model);
        }