public void ShouldReturnNullIfWrongNumberOfGenericArguments() { object source = new List <string>(); IDictionary <string, object> result = UpcastDictionary.Create(source); Assert.IsNull(result, "Null should be returned for generic types with the wrong number of type arguments."); }
public void ShouldReturnArgumentIfIDictionary_string_object() { object source = new Dictionary <string, object>(); IDictionary <string, object> result = UpcastDictionary.Create(source); Assert.AreSame(source, result, "The up-cast wrapper should not be applied if already a IDictionary<string, object>."); }
public void ShouldReturnNullIfNotGenericType() { object source = String.Empty; IDictionary <string, object> result = UpcastDictionary.Create(source); Assert.IsNull(result, "Null should be returned for non-generic types."); }
public void ShouldReturnNullIfNotDictionaryType() { object source = (Converter <string, object>)(s => (object)s); IDictionary <string, object> result = UpcastDictionary.Create(source); Assert.IsNull(result, "Null should be returned for non-dictionary types."); }
public void ShouldReturnUpcastWrapperForDictionary_string_TValue() { object source = new Dictionary <string, string>(); IDictionary <string, object> result = UpcastDictionary.Create(source); Assert.IsInstanceOfType(result, typeof(UpcastDictionary <string>), "The source was not wrapped."); }
public void ShouldReturnNullIfFirstGenericTypeArgumentIsNotAString() { object source = new Dictionary <object, object>(); IDictionary <string, object> result = UpcastDictionary.Create(source); Assert.IsNull(result, "Null should be returned if the first generic type argument is not a string."); }
public void ShouldNotFindKeyIfNotInWrappedDictionary_Indexer() { var source = new Dictionary <string, int>() { { "Age", 100 } }; IDictionary <string, object> result = UpcastDictionary.Create(source); object value = result["Name"]; }
public void ShouldHandleConcreteClassInheritingFromDictionary() { var dictionary = new ConcreteDictionary() { { "Name", "Bob" } }; var result = UpcastDictionary.Create(dictionary); Assert.AreEqual(dictionary["Name"], result["Name"]); }
public void ShouldGetCount() { var source = new Dictionary <string, int>() { { "Age", 100 }, { "Weight", 45 } }; IDictionary <string, object> result = UpcastDictionary.Create(source); Assert.AreEqual(source.Count, result.Count, "The source and Upcast dictionary should have the same count."); }
public void ShouldFindPairInWrappedDictionary() { var source = new Dictionary <string, int>() { { "Age", 100 } }; IDictionary <string, object> result = UpcastDictionary.Create(source); bool contains = result.Contains(new KeyValuePair <string, object>("Age", 100)); Assert.IsTrue(contains, "The pair should have been found."); }
public void ShouldNotFindPairIfValueWrongType() { var source = new Dictionary <string, int>() { { "Age", 100 } }; IDictionary <string, object> result = UpcastDictionary.Create(source); bool contains = result.Contains(new KeyValuePair <string, object>("Age", "Blah")); Assert.IsFalse(contains, "The pair should not have been found."); }
public void ShouldFindKeyIfInWrappedDictionary_Indexer() { var source = new Dictionary <string, string>() { { "Name", "Bob" } }; IDictionary <string, object> result = UpcastDictionary.Create(source); object value = result["Name"]; Assert.AreSame(source["Name"], value, "The value in the underlying dictionary should have been returned."); }
public void ShouldNotFindKeyIfNotInWrappedDictionary() { object source = new Dictionary <string, string>() { { "Name", "Bob" } }; IDictionary <string, object> result = UpcastDictionary.Create(source); bool containsKey = result.ContainsKey("Age"); Assert.IsFalse(containsKey, "The key Age should not have been found."); }
public void ShouldFindKeyIfInWrappedDictionary_TryGetValue() { var source = new Dictionary <string, string>() { { "Name", "Bob" } }; IDictionary <string, object> result = UpcastDictionary.Create(source); bool found = result.TryGetValue("Name", out object value); Assert.IsTrue(found, "The key should have been found."); Assert.AreSame(source["Name"], value, "The value in the underlying dictionary should have been returned."); }
public void ShouldReturnValuesAsObjects() { var source = new Dictionary <string, int>() { { "Age", 100 }, { "Weight", 500 } }; IDictionary <string, object> result = UpcastDictionary.Create(source); ICollection sourceValues = source.Values; ICollection wrappedValues = result.Values.ToArray(); CollectionAssert.AreEquivalent(sourceValues, wrappedValues, "The underlying values were not returned."); }
public void ShouldNotFindKeyIfNotInWrappedDictionary_TryGetValue() { var source = new Dictionary <string, int>() { { "Age", 100 } }; IDictionary <string, object> result = UpcastDictionary.Create(source); bool found = result.TryGetValue("Name", out object value); Assert.IsFalse(found, "The key should not have been found."); Assert.IsNull(value, "The value should be null even if the actual type is a struct."); }
public void ShouldFindKeysInWrappedDictionary() { var source = new Dictionary <string, string>() { { "Name", "Bob" }, { "Age", "100" } }; IDictionary <string, object> result = UpcastDictionary.Create(source); ICollection sourceKeys = source.Keys; ICollection wrappedKeys = result.Keys.ToArray(); CollectionAssert.AreEquivalent(sourceKeys, wrappedKeys, "The same keys should have been found in both collections."); }
public void ShouldCopyPairsToArray() { var source = new Dictionary <string, int>() { { "Age", 100 }, { "Weight", 45 } }; IDictionary <string, object> result = UpcastDictionary.Create(source); var array = new KeyValuePair <string, object> [2]; result.CopyTo(array, 0); var expected = new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Age", 100), new KeyValuePair <string, object>("Weight", 45) }; CollectionAssert.AreEqual(expected, array, "The pairs were not copied."); }
public void ShouldGetEnumerator() { var source = new Dictionary <string, int>() { { "Age", 100 }, { "Weight", 45 } }; IDictionary <string, object> result = UpcastDictionary.Create(source); IEnumerator <KeyValuePair <string, object> > enumerator = result.GetEnumerator(); var values = new List <KeyValuePair <string, object> >(); while (enumerator.MoveNext()) { values.Add(enumerator.Current); } var expected = new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Age", 100), new KeyValuePair <string, object>("Weight", 45) }; CollectionAssert.AreEqual(expected, values, "The enumerator did not return the correct pairs."); }
public void ShouldReturnNullForNull() { IDictionary <string, object> result = UpcastDictionary.Create(null); Assert.IsNull(result, "Null should be returned for null."); }