コード例 #1
0
        public void TestGetValueOrDefault()
        {
            // Ensure that requesting an invalid key with no default specified returns the default
            // value for that type.
            Assert.AreEqual(0L, CollectionUtilities.GetValueOrDefault(dictionary, invalidKey));

            long validValue = dictionary[validKey];

            // Ensure requesting a valid key returns the expected value.
            Assert.AreEqual(validValue, CollectionUtilities.GetValueOrDefault(dictionary, validKey));

            // Ensure requesting an invalid key with a default specified returns the specified default.
            Assert.AreEqual(validValue,
                            CollectionUtilities.GetValueOrDefault(dictionary, invalidKey, validValue));
        }