示例#1
0
        public void Add_And_Get_Items()
        {
            const string var1Name = "var1name";
            const string var2Name = "var2name";
            const string var3Name = "var3name";

            var var1 = new IntVariable(1234);
            var var2 = new StringVariable("theValue");
            var var3 = new BoolVariable(true);

            var vg = new VariablesGroup
            {
                { var1Name, var1 },
                new KeyValuePair <string, IVariable>(var2Name, var2)
            };

            vg[var3Name] = var3;

            Assert.That(vg.Count, Is.EqualTo(3));
            Assert.That((int)vg[var1Name].GetValue() !, Is.EqualTo(1234));
            Assert.That((string)vg[var2Name].GetValue() !, Is.EqualTo("theValue"));
            Assert.That(vg.Keys.Count, Is.EqualTo(3));
            Assert.That(vg.ContainsKey(var1Name));
            Assert.That(vg.Values.Count, Is.EqualTo(3));
            Assert.That(vg.Values.Contains(var1));
            Assert.That(vg.Values.Contains(var2));
            Assert.That(vg.Values.Contains(var3));
            Assert.That(vg.ContainsKey(var2Name));
            Assert.That(vg.TryGetValue(var1Name + "False", out _), Is.False);
        }
示例#2
0
        public void Copy_To_Array()
        {
            var vg   = new VariablesGroup();
            var kvp1 = new KeyValuePair <string, IVariable>("theKey1", new IntVariable(135));
            var kvp2 = new KeyValuePair <string, IVariable>("theKey2", new IntVariable(987));

            vg.Add(kvp1);
            vg.Add(kvp2);

            var array = new KeyValuePair <string, IVariable> [vg.Count];

            vg.CopyTo(array, 0);

            Assert.That(vg.Count, Is.EqualTo(array.Length));
            for (var i = 0; i < array.Length; i++)
            {
                Assert.That(vg.ContainsKey(array[i].Key));
            }
        }