示例#1
0
        public void Dictionary_In()
        {
            var d1 = DS.Dictionary(new { a = 1, b = 2, c = 3 });

            Assert.IsTrue("a".In(d1));
            Assert.IsFalse("aaaa".In(d1));
        }
        public void SystemWebRoutingRouteValueDictionary_Dictionary()
        {
            var dic1 = DS.Dictionary(new { a = 1, b = 2, c = 3 });
            var dic2 = DS.Dictionary(new Dictionary <string, object>()
            {
                { "a", 1 }, { "b", 2 }, { "c", 3 }
            });
            dynamic dic3 = new ExpandoObject();

            dic3.a = 1;
            dic3.b = 2;
            dic3.c = 3;

            var dic4 = new System.Web.Routing.RouteValueDictionary(new { a = 1, b = 2, c = 3 });

            DS.DictionaryHelper.AssertDictionaryEqual(dic1, dic4);

            dic4 = new System.Web.Routing.RouteValueDictionary(new Dictionary <string, object>()
            {
                { "a", 1 }, { "b", 2 }, { "c", 3 }
            });
            DS.DictionaryHelper.AssertDictionaryEqual(dic1, dic4);

            dic4 = new System.Web.Routing.RouteValueDictionary(dic3);
            DS.DictionaryHelper.AssertDictionaryEqual(dic1, dic4);

            dic4 = new System.Web.Routing.RouteValueDictionary(TestDataInstanceManager.TestPersonInstance);
        }
        public static void Sample13()
        {
            var beatles = DS.Dictionary <int>(new { Paul = 1942, John = 1940, Richard = 1940, George = 1943 });
            var other   = beatles.Get("Pete", 1941); // Support a default value for non existing key

            var younger1 = beatles.Max();            // Return the entry with the greatest value
            var younger2 = beatles.Max(DS.List("Paul", "John", "Richard"));

            var older1 = beatles.Min(); // Return the entry with the smallest value
            var older2 = beatles.Min(DS.List("Paul", "Richard", "George"));

            var newMusicians = beatles.Clone();

            // Add or remove entries to a dictionary
            var stones      = DS.Dictionary <int>(new { Mick = 1943, Keith = 1943, Brian = 1942, Bill = 1936, Charlie = 1941 });
            var allTogether = beatles.Add(stones);
            var noStones    = allTogether.Remove(stones);

            // Determine if a dictionary contains a key, a dictionary or literal dictionary
            var b1 = beatles.Include(beatles);
            var b2 = beatles.Include("Paul");
            var b3 = beatles.Include(new { Paul = 1942, John = 1940 });

            // Process string template with the value of a dictionary
            var InstallVar = DS.Dictionary(new { SERVER = "foo.bar.local", USER = @"bat\jshmoe", PASSWORD = "******" });
            var batchCode  = InstallVar.PreProcess(@"msiexec.exe /i product.msi SERVER={SERVER} USER={USER} PASSWORD={PASSWORD}");

            if ("Mick".In(stones))
            {
            }
        }
        public void Min_Int()
        {
            Dictionary <string, int> dic = DS.Dictionary <int>(new { a = 1, b = 2, c = 3, d = 4 });

            Assert.AreEqual("a", dic.Min());
            Assert.AreEqual("b", dic.Min(DS.List("b", "c", "d")));
        }
        public void Max_String()
        {
            Dictionary <string, int> dic = DS.Dictionary <int>(new { a = "1", b = "2", c = "3", d = "4" });

            Assert.AreEqual("d", dic.Max(DS.List("a", "b", "c", "d")));
            Assert.AreEqual("b", dic.Max(DS.List("a", "b")));
        }
示例#6
0
        public void AreEqualProperties_Dictionary_Fail()
        {
            var o1 = new { a = 1, b = 2, c = "ok", d = true, e = DateTime.Now, f = 1.2, g = 1.2M, h = 1.2f };
            var o2 = new { a = 2, b = 2, c = "ok", d = true, e = DateTime.Now, f = 1.2, g = 1.2M, h = 1.1f };

            DS.Assert.AreEqualProperties(DS.Dictionary(o1), DS.Dictionary(o2));
        }
示例#7
0
        public void Dictionary_Identical()
        {
            var d1 = DS.Dictionary(new { a = 1, b = 2, c = 3 });

            Assert.IsTrue(DS.DictionaryHelper.Identical <string, object>(d1, d1));
            DS.DictionaryHelper.AssertDictionaryEqual(d1, d1);
        }
        public void Substract_list()
        {
            var dic1        = DS.Dictionary(new { a = 1, b = 2, c = 3, d = 4, e = 5 });
            var dic3        = dic1.Remove(DS.List("a", "c", "e"));
            var expectedDic = DS.Dictionary(new { b = 2, d = 4, });

            DS.DictionaryHelper.AssertDictionaryEqual(expectedDic, dic3);
        }
        public void Add_Int()
        {
            var dic1 = DS.Dictionary <int>(new { a = 1, b = 2 });
            var dic2 = DS.Dictionary <int>(new { c = 3, d = 4 });
            var dic3 = DS.Dictionary <int>(new { a = 1, b = 2, c = 3, d = 4 });

            DS.DictionaryHelper.AssertDictionaryEqual(dic3, dic1.Add(dic2));
        }
示例#10
0
        public void Dictionary_Identical_NegativeCase()
        {
            var d1 = DS.Dictionary(new { a = 1, b = 2, c = 3 });
            var d2 = DS.Dictionary(new { a = 1, b = 2, c = "3" });

            Assert.IsFalse(DS.DictionaryHelper.Identical(d1, d2));
            DS.DictionaryHelper.AssertDictionaryEqual(d1, d2);
        }
        public void Add_DifferentTypeOfValues_DoNotOverWrite()
        {
            var dic1 = DS.Dictionary(new { a = 1, b = "B" });
            var dic2 = DS.Dictionary(new { b = "BB", c = 3, d = 2.2 }); //b="BB" will be ignore
            var dic3 = DS.Dictionary(new { a = 1, b = "B", c = 3, d = 2.2 });

            DS.DictionaryHelper.AssertDictionaryEqual(dic3, dic1.Add(dic2, false));
        }
        public void Include_List()
        {
            var dic1 = DS.Dictionary(new { a = 1, b = 2, c = 3, d = 4, e = 5 });

            Assert.IsTrue(dic1.Include(DS.List("a", "b", "c")));
            Assert.IsTrue(dic1.Include("a", "b", "c"));
            Assert.IsFalse(dic1.Include(DS.List("a", "b", "c", "dd")));
            Assert.IsFalse(dic1.Include("a", "b", "c", "dd"));
        }
        public void Add_DifferentTypeOfValues()
        {
            var dic1 = DS.Dictionary(new { a = 1, b = "B", c = 33 }); // c=33 will be ovweritten
            var dic2 = DS.Dictionary(new { c = 3, d = 2.2 });
            var dic3 = DS.Dictionary(new { a = 1, b = "B", c = 3, d = 2.2 });
            var r    = dic1.Add(dic2);

            DS.DictionaryHelper.AssertDictionaryEqual(dic3, r);
        }
        public void Include_Dictionary()
        {
            var dic1 = DS.Dictionary(new { a = 1, b = 2, c = 3, d = 4, e = 5 });

            Assert.IsTrue(dic1.Include(dic1));
            Assert.IsTrue(dic1.Include(DS.Dictionary(new { a = 1, b = 2, })));
            Assert.IsFalse(dic1.Include(DS.Dictionary(new { a = 1, b = 2, c = 33 })));
            Assert.IsFalse(dic1.Include(DS.Dictionary(new { a = 1, b = 2, d = 3 })));
        }
        public void Substract_Dictionary()
        {
            var dic1        = DS.Dictionary(new { a = 1, b = 2, c = 3, d = 4, e = 5 });
            var dic2        = DS.Dictionary(new { a = 1, c = 3, e = 5 });
            var dic3        = dic1.Remove(dic2);
            var expectedDic = DS.Dictionary(new { b = 2, d = 4, });

            DS.DictionaryHelper.AssertDictionaryEqual(expectedDic, dic3);
        }
        void Sample4()
        {
            MyFunction(new Dictionary <string, bool>() // Regular C#
            {
                { "Debug", true },
                { "Verbose", false }
            });

            // Dynamic Sugar Syntax
            MyFunction(DS.Dictionary <bool>(new { Debug = true, Verbose = false }));
        }
示例#17
0
 public void DS_Dictionary()
 {
     Assert.AreEqual("RRabbit",
                     InitializeSettings(DS.Dictionary(
                                            new {
         UserName = "******",
         Domain   = "ToonTown",
         UserID   = 234873
     }
                                            ))
                     );
 }
        public static void Sample6_2()
        {
            var v1 = DS.List(1, 2, 3).Format();                     // 1, 2, 3
            var v2 = DS.List(1, 2, 3).Format(@"""{0}""", "; ");     // "1"; "2"; "3"

            var v3 = DS.List("a", "b", "c").Format();               // "a", "b", "c"
            var v4 = DS.List("a", "b", "c").Format(@"({0})", "; "); // ("a"); ("b"); ("c")

            var beatles = DS.Dictionary <int>(new { Paul = 1942, John = 1940, Richard = 1940, George = 1943 });
            var v5      = beatles.Format();                         // { Paul:1942, John:1940, Richard:1940, George:1943 }
            var v6      = beatles.Format(@"""{0}""=""{1}""", "; "); // { "Paul"="1942"; "John"="1940"; "Richard"="1940"; "George"="1943" }
        }
        void Sample3()
        {
            MyFunction(new Dictionary <string, object>() // Regular C#
            {
                { "Debug", true },
                { "Continent", "North America" }
            });

            // Dynamic Sugar Syntax
            MyFunction(DS.Dictionary(new { Debug = true, Continent = "North America" }));

            // In() method
            var stones = DS.Dictionary <int>(new { Mick = 1943, Keith = 1943, Brian = 1942, Bill = 1936, Charlie = 1941 });

            if ("Mick".In(stones))
            {
            }
        }
        public void Dictionary_Argument_AnonymousType_Dictionary_ExpandoObject()
        {
            var dic1 = DS.Dictionary(new { a = 1, b = 2, c = 3 });
            var dic2 = DS.Dictionary(
                new Dictionary <string, object>()
            {
                { "a", 1 }, { "b", 2 }, { "c", 3 }
            }
                );

            DS.DictionaryHelper.AssertDictionaryEqual(dic1, dic2);

            dynamic dic3 = new ExpandoObject();

            dic3.a = 1;
            dic3.b = 2;
            dic3.c = 3;
            DS.DictionaryHelper.AssertDictionaryEqual(dic1, dic3);
        }
示例#21
0
        public void DictionaryFormat_StaticMemberAndExtensionMethod()
        {
            var expected = @"{ a:1, b:2, c:3 }";

            Assert.AreEqual(expected, DS.DictionaryHelper.Format(DS.Dictionary(new { a = 1, b = 2, c = 3 })));

            IDictionary <string, object> dic = DS.Dictionary(new { a = 1, b = 2, c = 3 });

            Assert.AreEqual(expected, dic.Format());

            Dictionary <string, object> dic2 = DS.Dictionary(new { a = 1, b = 2, c = 3 });

            Assert.AreEqual(expected, dic2.Format());

            var dic3 = DS.Dictionary(new { a = 1, b = 2, c = 3 });

            Assert.AreEqual(expected, dic3.Format());

            Assert.AreEqual(expected, DS.Dictionary(new { a = 1, b = 2, c = 3 }).Format());
        }
        public void Clone()
        {
            Dictionary <string, int> dic = DS.Dictionary <int>(new { a = 1, b = 2, c = 3 });

            DS.DictionaryHelper.AssertDictionaryEqual(dic, dic.Clone());
        }
        public void PreProcess()
        {
            var dic1 = DS.Dictionary(new { a = 1, b = 2, date = new DateTime(1964, 12, 11) });

            Assert.AreEqual("a=1, b=002, date=1964-12-11", dic1.PreProcess("a={a}, b={b:000}, date={date:yyyy-MM-dd}"));
        }
示例#24
0
        public void AreEqualProperties_Dictionary()
        {
            var o = new { a = 1, b = 2, c = "ok", d = true, e = DateTime.Now, f = 1.2, g = 1.2M, h = 1.2f };

            DS.Assert.AreEqualProperties(DS.Dictionary(o), DS.Dictionary(o));
        }