コード例 #1
0
        public void DictionaryNotGetHashCodeWithArraysTest()
        {
            // setup
            string nameA  = "Timmy";
            var    itemsA = new Dictionary <string, object>
            {
                { "a", "apple" },
                { "b", new int[] { 907 } }
            };

            string nameB  = "Timmy";
            var    itemsB = new Dictionary <string, object>
            {
                { "a", "apple" },
                { "b", new int[] { 909 } }
            };

            var dictionaryContainerA = new ObjectDictionaryContainer
            {
                Name  = nameA,
                Items = itemsA
            };

            var dictionaryContainerB = new ObjectDictionaryContainer
            {
                Name  = nameB,
                Items = itemsB
            };

            // test
            var dictionaryContainerAHash = dictionaryContainerA.GetHashCode();
            var dictionaryContainerBHash = dictionaryContainerB.GetHashCode();

            // assert
            Assert.AreNotEqual(dictionaryContainerAHash, dictionaryContainerBHash);
        }
コード例 #2
0
        public void DictionaryGetHashCodeWithDeferencingTest()
        {
            // setup
            string nameA  = "Timmy";
            var    itemsA = new Dictionary <string, object>
            {
                { "a", "apple" },
                { "b", 32 }
            };

            string nameB  = "Timmy";
            var    itemsB = new Dictionary <string, object>
            {
                { "a", "apple" },
                { "b", 32 }
            };

            var dictionaryContainerA = new ObjectDictionaryContainer
            {
                Name  = nameA,
                Items = itemsA
            };

            var dictionaryContainerB = new ObjectDictionaryContainer
            {
                Name  = nameB,
                Items = itemsB
            };

            // test
            var dictionaryContainerAHash = dictionaryContainerA.GetHashCode();
            var dictionaryContainerBHash = dictionaryContainerB.GetHashCode();

            // assert
            Assert.AreEqual(dictionaryContainerAHash, dictionaryContainerBHash);
        }