public void CanAccessPropertiesValues() { var dict = new ReflectionBasedDictionaryAdapter(new Customer(1, "name")); Assert.AreEqual(1, dict["id"]); Assert.AreEqual("name", dict["name"]); }
public void ShouldNotAccessInexistingProperties() { ReflectionBasedDictionaryAdapter dict = new ReflectionBasedDictionaryAdapter(new Customer(1, "name")); Assert.IsFalse(dict.Contains("Age"), "Age property found when it should not be"); Assert.IsFalse(dict.Contains("Address"), "Address property found when it should not be"); }
public void CanAccessExistingPropertiesInACaseInsensitiveFashion() { var dict = new ReflectionBasedDictionaryAdapter(new Customer(1, "name")); Assert.IsTrue(dict.Contains("id")); Assert.IsTrue(dict.Contains("ID")); Assert.IsTrue(dict.Contains("Id")); Assert.IsTrue(dict.Contains("name")); Assert.IsTrue(dict.Contains("Name")); Assert.IsTrue(dict.Contains("NAME")); }
public void ShouldNotAccessWriteOnlyProperties() { try { ReflectionBasedDictionaryAdapter dict = new ReflectionBasedDictionaryAdapter(new Customer(1, "name", true)); Assert.IsTrue((bool) dict["IsWriteOnly"]); } catch(ArgumentException) { Assert.Fail("Attempted to read a write-only property"); } }
public void EnumeratorIteration() { var dict = new ReflectionBasedDictionaryAdapter(new {foo = 1, name = "jonh", age = 25}); Assert.AreEqual(3, dict.Count); var enumerator = (IDictionaryEnumerator) dict.GetEnumerator(); while (enumerator.MoveNext()) { Assert.IsNotNull(enumerator.Key); Assert.IsNotNull(enumerator.Value); } }
public void InexistingPropertiesReturnsNull() { var dict = new ReflectionBasedDictionaryAdapter(new Customer(1, "name")); Assert.IsNull(dict["age"]); }
public void Using_anonymous_types_works_without_exception() { var target = new { foo = 1, name = "john", age = 25 }; Assert.IsFalse(target.GetType().GetTypeInfo().IsPublic); var dict = new ReflectionBasedDictionaryAdapter(target); Assert.AreEqual(3, dict.Count); Assert.AreEqual(1, dict["foo"]); Assert.AreEqual("john", dict["name"]); Assert.AreEqual(25, dict["age"]); }