public void ObjectWrapperSetPropertyValue_Class() { var testObject = new PublicValueTypeTestClass(); var objectWrapper = new ObjectWrapper(testObject); objectWrapper.SetPropertyValue(nameof(PublicValueTypeTestClass.PublicPropertyGetSet), 12); Assert.AreEqual(12, testObject.PublicPropertyGetSet); objectWrapper.SetPropertyValue(nameof(PublicValueTypeTestClass.PublicVirtualPropertyGetSet), 24); Assert.AreEqual(24, testObject.PublicVirtualPropertyGetSet); objectWrapper.SetPropertyValue(nameof(PublicValueTypeTestClass.PublicPropertyGetPrivateSet), 48); Assert.AreEqual(48, testObject.PublicPropertyGetPrivateSet); objectWrapper.SetPropertyValue(nameof(PublicValueTypeTestClass.PublicPropertyPrivateGetSet), 96); Assert.AreEqual(96, testObject._publicField); // => Setter set the public field value (for check) objectWrapper.SetPropertyValue(nameof(PublicValueTypeTestClass.PublicPropertySet), 192); Assert.AreEqual(192, testObject._publicField); // => Setter set the public field value (for check) // Object wrapper does not provide access to not public members objectWrapper.SetPropertyValue(nameof(PublicValueTypeTestClass.InternalPropertyGetSet), 384); Assert.AreEqual(0, testObject._internalField); objectWrapper.SetPropertyValue("ProtectedPropertyGetSet", 728); Assert.AreEqual(0, testObject.GetProtectedFieldValue()); objectWrapper.SetPropertyValue("PrivatePropertyGetSet", 1536); Assert.AreEqual(0, testObject.GetPrivateFieldValue()); }
public void ObjectWrapperSetFieldValue_Class() { var testObject = new PublicValueTypeTestClass(); var objectWrapper = new ObjectWrapper(testObject); objectWrapper.SetFieldValue(nameof(PublicValueTypeTestClass._publicField), 12); Assert.AreEqual(12, testObject._publicField); // Object wrapper does not provide access to not public members objectWrapper.SetFieldValue(nameof(PublicValueTypeTestClass._internalField), 24); Assert.AreEqual(0, testObject._internalField); objectWrapper.SetFieldValue("_protectedField", 48); Assert.AreEqual(0, testObject.GetProtectedFieldValue()); objectWrapper.SetFieldValue("_privateField", 962); Assert.AreEqual(0, testObject.GetPrivateFieldValue()); }
public void ImmediateFieldSetValue_ValueType() { // Value type / Public var publicValueTypeTestObject = new PublicValueTypeTestClass(); var immediateField = new ImmediateField(PublicValueTypePublicFieldFieldsInfo); immediateField.SetValue(publicValueTypeTestObject, 12); Assert.AreEqual(12, publicValueTypeTestObject._publicField); immediateField = new ImmediateField(PublicValueTypeInternalFieldFieldsInfo); immediateField.SetValue(publicValueTypeTestObject, 24); Assert.AreEqual(24, publicValueTypeTestObject._internalField); immediateField = new ImmediateField(PublicValueTypeProtectedFieldFieldsInfo); immediateField.SetValue(publicValueTypeTestObject, 48); Assert.AreEqual(48, publicValueTypeTestObject.GetProtectedFieldValue()); immediateField = new ImmediateField(PublicValueTypePrivateFieldFieldsInfo); immediateField.SetValue(publicValueTypeTestObject, 96); Assert.AreEqual(96, publicValueTypeTestObject.GetPrivateFieldValue()); // Value type / Internal var internalValueTypeTestObject = new InternalValueTypeTestClass(); immediateField = new ImmediateField(InternalValueTypePublicFieldFieldsInfo); immediateField.SetValue(internalValueTypeTestObject, 192); Assert.AreEqual(192, internalValueTypeTestObject._publicField); immediateField = new ImmediateField(InternalValueTypeInternalFieldFieldsInfo); immediateField.SetValue(internalValueTypeTestObject, 384); Assert.AreEqual(384, internalValueTypeTestObject._internalField); immediateField = new ImmediateField(InternalValueTypeProtectedFieldFieldsInfo); immediateField.SetValue(internalValueTypeTestObject, 728); Assert.AreEqual(728, internalValueTypeTestObject.GetProtectedFieldValue()); immediateField = new ImmediateField(InternalValueTypePrivateFieldFieldsInfo); immediateField.SetValue(internalValueTypeTestObject, 1536); Assert.AreEqual(1536, internalValueTypeTestObject.GetPrivateFieldValue()); }