Ejemplo n.º 1
0
        private static void CommonPListOperations(IPList <string, string> pList)
        {
            Assert.Equal("value1", pList["prop1"]);
            var ex = Assert.Throws <PropertyNotFoundException <string> >(() => pList["propx"]);

            Assert.Equal("propx", ex.PropertyKey);
            Assert.True(pList.TryGetValue("prop1", out _));
            Assert.False(pList.TryGetValue("propx", out _));
            Assert.True(pList.ContainsKey("prop1"));
            Assert.False(pList.ContainsKey("dummy"));
            Assert.True(pList.Contains(new KeyValuePair <string, string>("prop1", "value1")));
            Assert.False(pList.Contains(new KeyValuePair <string, string>("prop1", "dummyValue")));

            pList.Add(new KeyValuePair <string, string>("propy", "valuey"));
            Assert.Equal("valuey", pList["propy"]);

            pList.Remove("propy");
            ex = Assert.Throws <PropertyNotFoundException <string> >(() => pList["propy"]);
            Assert.Equal("propy", ex.PropertyKey);

            pList["propz"] = "valuez";
            Assert.Equal("valuez", pList["propz"]);
            pList["propz"] = "valuezz";
            Assert.Equal("valuezz", pList["propz"]);

            pList.Remove(new KeyValuePair <string, string>("propz", "foo"));
            ex = Assert.Throws <PropertyNotFoundException <string> >(() => pList["propz"]);
            Assert.Equal("propz", ex.PropertyKey);

            pList["nullProp"] = null;
            Assert.Null(pList["nullProp"]);

            Assert.Equal(6, pList.Count);
            Assert.All(pList.Keys, s => Assert.Contains(s, new [] { "prop1", "prop2", "prop3", "prop4", "prop5", "nullProp" }));
            Assert.All(pList.Values, s => Assert.Contains(s, new[] { "value1", "value2", "value3", "value4", "value5", null }));
        }