public void GetPropertyPathReturnsNullIfSubjectIsNoObject() { var str = "Hello world"; Assert.Null(ObjectAccess.ObjectPropertyByPath(str, "property2")); Assert.Null(ObjectAccess.ObjectPropertyByPath(str, "0")); }
public void GetPropertyPathCanGetPropertiesOfAnObject() { Assert.Equal("inner value", ObjectAccess.ObjectPropertyByPath(dummyObject2, "nestedClass.innerValue")); Assert.Equal("value 1", ObjectAccess.ObjectPropertyByPath(dummyObject2, "nestedDictionary.key1")); Assert.Equal("value1", ObjectAccess.ObjectPropertyByPath(dummyObject2, "nestedDictionary.1.0")); Assert.Equal("baz", ObjectAccess.ObjectPropertyByPath(dummyObject2, "nestedList.2")); Assert.Equal("ab", ObjectAccess.ObjectPropertyByPath(dummyObject2, "nestedArray.0")); }
public void GetPropertyCanAccessElementsOfAList() { var arr = new List <string>() { "foo", "bar", "baz" }; Assert.Equal("bar", ObjectAccess.GetProperty(arr, "1")); }
public void GetPropertyThrowsExceptionIfListIsOutOfBounds() { var arr = new List <string>() { "foo", "bar", "baz" }; Assert.Throws <PropertyNotAccessibleException>(() => ObjectAccess.GetProperty(arr, "4")); }
public void GetProeprtyPathReturnsNullIfSubjectOnPathIsNoObject() { var subject = new Dictionary <string, object>() { { "foo", "Hello World" } }; Assert.Null(ObjectAccess.ObjectPropertyByPath(subject, "foo.bar")); }
public void GetPropertyCanAccessPropertiesOfADictObject() { var dict = new Dictionary <string, object>(); dict["key"] = "value"; var result = ObjectAccess.GetProperty(dict, "key"); Assert.Equal("value", result); }
public void GetPropertyCallsGettersBeforeAccessingFields() { var dict = new Dictionary <string, object>(); dict["Count"] = "value"; var result = ObjectAccess.GetProperty(dict, "Count"); Assert.Equal(dict.Count, result); }
public void GetPropertyTriesToCallABooleanHasGetterMethodIfItExists() { var property = ObjectAccess.GetProperty(dummyObject, "anotherBooleanProperty"); Assert.Equal(false, property); dummyObject.SetAnotherBooleanProperty(true); property = ObjectAccess.GetProperty(dummyObject, "anotherBooleanProperty"); Assert.Equal(true, property); }
/// <summary> /// Get all items' "position" property and index the item keys accordingly. From that index the sorted keys will be composed later. /// </summary> protected void IndexKeys() { foreach (var kvp in this.KeyAlias) { var sKey = kvp.Key; var oKey = kvp.Value; var value = this.Subject[sKey]; if (value == null) { continue; } var positionValue = ObjectAccess.ObjectPropertyByPath(value, PositionalPropertyPath); var position = positionValue == null ? null : positionValue.ToString(); if (position != null && position.StartsWith("start")) { if (IndexStartKey(sKey, position)) { continue; } } else if (position != null && position.StartsWith("end")) { if (IndexEndKey(sKey, position)) { continue; } } else if (position != null && position.StartsWith("after")) { if (IndexAfterKey(sKey, position)) { continue; } } else if (position != null && position.StartsWith("before")) { if (IndexBeforeKey(sKey, position)) { continue; } } else { IndexMiddleKey(sKey, position, oKey); continue; } // invalid keyword-key IndexMiddleKey(sKey, null, oKey); } }
public void GetPropertyTriesToCallABooleanIsGetterMethodIfExists() { var property = ObjectAccess.GetProperty(dummyObject, "booleanProperty"); Assert.Equal("method called True", property); }
public void GetPropertyReturnsThrowsExceptionIfArrayKeyDoesNotExist() { Assert.Throws <PropertyNotAccessibleException>(() => ObjectAccess.GetProperty(new Dictionary <string, object>(), "notExistingProperty")); }
public void GetPropertyReturnsPropertyNotAccessibleExcpeitonIfPropertyDoesNotExist() { Assert.Throws <PropertyNotAccessibleException>(() => ObjectAccess.GetProperty(dummyObject, "notExistingProperty")); }
public void GetPropertyReturnsPropertyNotAccessibleExcpeitonForNotExistingPropertyIfForceDirectAccessIsTrue() { Assert.Throws <PropertyNotAccessibleException>(() => ObjectAccess.GetProperty(dummyObject, "notExistingProperty", true)); }
public void GetPropertyReturnsExpectedValueForUnexposedPropertyIfForceDirectAccessIsTrue() { var property = ObjectAccess.GetProperty(dummyObject, "unexposedProperty", true); Assert.Equal("unexposed", property); }
public void GetPropertyReturnsExpectedValueForPublicProperty() { var property = ObjectAccess.GetProperty(dummyObject, "publicProperty2"); Assert.Equal(42, property); }
public void GetPropertyReturnsExpectedValueForGetterProperty() { var property = ObjectAccess.GetProperty(dummyObject, "property"); Assert.Equal("string1", property); }
public void GetPropertyThrowsExceptionIfDictDoesNotcontainKey() { var dict = new Dictionary <string, object>(); Assert.Throws <PropertyNotAccessibleException>(() => ObjectAccess.GetProperty(dict, "notExistingKey")); }
public void GetPropertyPathReturnsNullForNonExistingPropertyPath() { Assert.Null(ObjectAccess.ObjectPropertyByPath(dummyObject2, "nestedClass.foo")); }
public void GetPropertyCanAccessElementsOfAnArray() { var arr = new string[] { "foo", "bar", "baz" }; Assert.Equal("bar", ObjectAccess.GetProperty(arr, "1")); }