public void NonNullDictionary_Unit_CopyTo_Optimal() { IDictionary<String, String> dictionary = new Dictionary<String, String>() { { "Key1", "Value1" }, { "Key2", "Value2" }, { "Key3", "Value3" } }; ICollection<KeyValuePair<String, String>> target = new NonNullDictionary<String, String>(dictionary); KeyValuePair<String, String>[] array = new KeyValuePair<String, String>[dictionary.Count]; Int32 arrayIndex = 0; target.CopyTo(array, arrayIndex); Assert.AreEqual(dictionary.Count, array.Length); foreach (KeyValuePair<String, String> pair in array) { Assert.IsTrue(dictionary.Contains(pair)); } }
public void NonNullDictionary_Unit_CopyTo_ArrayIsTooSmall() { IDictionary<String, String> dictionary = new Dictionary<String, String>() { { "Key1", "Value1" }, { "Key2", "Value2" }, { "Key3", "Value3" } }; ICollection<KeyValuePair<String, String>> target = new NonNullDictionary<String, String>(dictionary); KeyValuePair<String, String>[] array = new KeyValuePair<String, String>[dictionary.Count - 2]; Int32 arrayIndex = 1; target.CopyTo(array, arrayIndex); }