Exemple #1
0
        public void TestDataBindingArray()
        {
            var collectionInfo = CollectionInfo.ForType(typeof(string[]));
            var strings        = new[] { "One", "Two", "Three" };

            CollectionAssert.AreEqual(Enumerable.Range(0, 3).ToArray(), collectionInfo.GetKeys(strings).Cast <int>().ToArray());
            CollectionAssert.AreEqual(strings, collectionInfo.GetItems(strings).Cast <string>().ToArray());
            foreach (var key in collectionInfo.GetKeys(strings))
            {
                Assert.AreEqual(strings[(int)key], collectionInfo.GetItemFromKey(strings, key));
            }
            Assert.IsNull(collectionInfo.GetItemFromKey(strings, -1));
            Assert.IsNull(collectionInfo.GetItemFromKey(strings, 3));
            Assert.IsNull(collectionInfo.GetItemFromKey(null, 0));
        }
Exemple #2
0
        public void TestDataBindingDictionary()
        {
            var dict = new Dictionary <string, double>
            {
                { "zero", 3 },
                { "one", 3.1 },
                { "two", 3.14 }
            };
            var collectionInfo = CollectionInfo.ForType(dict.GetType());

            CollectionAssert.AreEqual(dict.Keys, collectionInfo.GetKeys(dict).Cast <string>().ToArray());
            CollectionAssert.AreEqual(dict, collectionInfo.GetItems(dict).Cast <KeyValuePair <string, double> >().ToArray());
            foreach (var key in collectionInfo.GetKeys(dict))
            {
                var kvp = (KeyValuePair <string, double>)collectionInfo.GetItemFromKey(dict, key);
                Assert.AreEqual(key, kvp.Key);
                Assert.AreEqual(dict[(string)key], kvp.Value);
            }
        }