Exemple #1
0
        public void HashKeysAndValues()
        {
            var hash = new Hashtable()
            {
                { "one", "uno" }, { "two", "dos" }
            };

            //Warning: Unfamiliar syntax ahead. Because the hashtable keys
            //only return an ICollection, there isn't a good way to ask it
            //if it matches, or contains values. So we are using a trick
            //from LINQ to cast it over. Note that the casting is not important
            //for this Koan - it's the value of the keys that is interesting

            var expectedKeys = new List <string>()
            {
                "one", "two"
            };

            expectedKeys.Sort();
            var actualKeys = hash.Keys.Cast <string>().ToList();

            actualKeys.Sort();

            CollectionAssert.AreEqual(expectedKeys, actualKeys);

            var expectedValues = new List <string>()
            {
                FILL_ME_IN.ToString(), FILL_ME_IN.ToString()
            };

            expectedValues.Sort();
            var actualValues = hash.Values.Cast <string>().ToList();

            actualValues.Sort();

            CollectionAssert.AreEqual(expectedValues, actualValues);
        }