System.Collections.Tests.SortedListTests.Clone_IsShallowCopy C# (CSharp) Method

Clone_IsShallowCopy() private method

private Clone_IsShallowCopy ( ) : void
return void
        public static void Clone_IsShallowCopy()
        {
            var sortList = new SortedList();
            for (int i = 0; i < 10; i++)
            {
                sortList.Add(i, new Foo());
            }

            SortedList sortListClone = (SortedList)sortList.Clone();

            string stringValue = "Hello World";
            for (int i = 0; i < 10; i++)
            {
                Assert.Equal(stringValue, ((Foo)sortListClone[i]).StringValue);
            }

            // Now we remove an object from the original list, but this should still be present in the clone
            sortList.RemoveAt(9);
            Assert.Equal(stringValue, ((Foo)sortListClone[9]).StringValue);

            stringValue = "Good Bye";
            ((Foo)sortList[0]).StringValue = stringValue;
            Assert.Equal(stringValue, ((Foo)sortList[0]).StringValue);
            Assert.Equal(stringValue, ((Foo)sortListClone[0]).StringValue);

            // If we change the object, of course, the previous should not happen
            sortListClone[0] = new Foo();

            Assert.Equal(stringValue, ((Foo)sortList[0]).StringValue);

            stringValue = "Hello World";
            Assert.Equal(stringValue, ((Foo)sortListClone[0]).StringValue);
        }
SortedListTests