public void Attempt_to_set_property_using_null_reference() { PropertyTestClass testObject = null; const int length = 7; Assert.IsFalse(testObject.TrySetProperty("Length", length)); }
public void CheckProperty() { var p = new PropertySet(); var subP = new PropertySet(); var key = "Sub Property"; subP.Add(key, "Success"); var valueP = new PropertyTestClass() { name = "TestClass", value = 5, porpertySet = subP }; p.Add("Property", valueP); var json = JsonUtil.ToJson(new ReadOnlyPropertySet(p)); var checkP = JsonUtil.ToObject <PropertySet>(json); var checkValueP = checkP["Property"] as PropertyTestClass; Assert.IsNotNull(checkValueP); Assert.AreEqual(valueP.name, checkValueP.name); Assert.AreEqual(valueP.value, checkValueP.value); Assert.IsNotNull(checkValueP.porpertySet); var checkValue = checkValueP.porpertySet[key]; Assert.IsNotNull(checkValue); Assert.AreEqual(checkValue, "Success"); }
public void Get_existing_property_with_wrong_type() { PropertyTestClass testObject = new PropertyTestClass(); string length; Assert.IsFalse(testObject.TryGetProperty("Length", out length)); Assert.IsNull(length); }
public void Set_existing_property_with_expected_type() { PropertyTestClass testObject = new PropertyTestClass(); const int length = 7; Assert.IsTrue(testObject.TrySetProperty("Length", length)); Assert.AreEqual(length, testObject.Length); }
public void Attempt_to_get_nonexistent_property() { PropertyTestClass testObject = new PropertyTestClass(); int length; Assert.IsFalse(testObject.TryGetProperty("bar", out length)); Assert.AreEqual(0, length); }
public void Set_existing_property_with_wrong_type() { PropertyTestClass testObject = new PropertyTestClass(); const string length = "foo"; Assert.IsFalse(testObject.TrySetProperty("Length", length)); Assert.AreEqual(0, testObject.Length); }
public void Attempt_to_set_nonexistent_property() { PropertyTestClass testObject = new PropertyTestClass(); const int length = 7; Assert.IsFalse(testObject.TrySetProperty("bar", length)); Assert.AreEqual(0, testObject.Length); }
public void Get_existing_property_with_expected_type() { PropertyTestClass testObject = new PropertyTestClass(); int length; Assert.IsTrue(testObject.TryGetProperty("Length", out length)); Assert.AreEqual(testObject.Length, length); }
public void Set_existing_property_with_wrong_type() { PropertyTestClass testObject = new PropertyTestClass(); const string length = "foo"; Assert.IsFalse(testObject.TrySetProperty("Length", length)); Assert.AreEqual(0, testObject.Length); }
public void Set_existing_property_with_expected_type() { PropertyTestClass testObject = new PropertyTestClass(); const int length = 7; Assert.IsTrue(testObject.TrySetProperty("Length", length)); Assert.AreEqual(length, testObject.Length); }
public void Attempt_to_get_nonexistent_property() { PropertyTestClass testObject = new PropertyTestClass(); int length; Assert.IsFalse(testObject.TryGetProperty("bar", out length)); Assert.AreEqual(0, length); }
public void Get_existing_property_with_wrong_type() { PropertyTestClass testObject = new PropertyTestClass(); string length; Assert.IsFalse(testObject.TryGetProperty("Length", out length)); Assert.IsNull(length); }
public void GetPropertyValue() { PropertyTestClass propertyTestClass = new PropertyTestClass(); propertyTestClass.ReadWriteProperty = 2; Assert.AreEqual(2, ExpressionHelper.GetPropertyValue(propertyTestClass, "ReadWriteProperty")); }
public void Attempt_to_set_nonexistent_property() { PropertyTestClass testObject = new PropertyTestClass(); const int length = 7; Assert.IsFalse(testObject.TrySetProperty("bar", length)); Assert.AreEqual(0, testObject.Length); }
public void Attempt_to_get_property_using_null_reference() { PropertyTestClass testObject = null; int length; Assert.IsFalse(testObject.TryGetProperty("Length", out length)); Assert.AreEqual(0, length); }
public void Get_existing_property_with_expected_type() { PropertyTestClass testObject = new PropertyTestClass(); int length; Assert.IsTrue(testObject.TryGetProperty("Length", out length)); Assert.AreEqual(testObject.Length, length); }
public void SetStringPropertyValueToNull() { PropertyTestClass propertyTestClass = new PropertyTestClass(); propertyTestClass.StringProperty = "Test"; ReflectionHelper.SetPropertyValue(propertyTestClass, "StringProperty", null); Assert.AreEqual(null, propertyTestClass.StringProperty); }
public void SetPropertyValue() { PropertyTestClass propertyTestClass = new PropertyTestClass(); propertyTestClass.ReadWriteProperty = 1; ExpressionHelper.SetPropertyValue(propertyTestClass, "ReadWriteProperty", 2); Assert.AreEqual(2, propertyTestClass.ReadWriteProperty); }
public void CreatePropertyAccessItemWriteOnlyProperty() { ReflectionHelper.PropertyAccessItem propertyAccessItem = ReflectionHelper.CreatePropertyAccessItem(typeof(PropertyTestClass), typeof(PropertyTestClass).GetProperty("WriteOnlyProperty")); Assert.AreEqual(false, propertyAccessItem.CanRead); Assert.AreEqual(true, propertyAccessItem.CanWrite); Assert.IsNull(propertyAccessItem.Getter); Assert.NotNull(propertyAccessItem.Setter); PropertyTestClass propertyTestClass = new PropertyTestClass(); propertyAccessItem.Setter(propertyTestClass, 2); Assert.AreEqual(2, propertyTestClass.ReadWriteProperty); }
public void Should_Serialize_Properties() { var mapping = ObjectSerializationMapper.Create() .FromType <PropertyTestClass>() .PublicProperties() .Map(); var serializationOps = ObjectSerializerCompiler.CompileSerializationOps(mapping).ToList().AsReadOnly(); var context = ObjectSerializerInterpreter.InterpretObjectSerializationNullContext( typeof(PropertyTestClass), serializationOps, ObjectSerializerProgram.GetOpValueSerializerTypes(serializationOps).ToList().AsReadOnly() ); var serializeDelegate = ObjectSerializerInterpreter.InterpretDynamicSerializeDelegate( context, typeof(PropertyTestClass), serializationOps ); var testObject = new PropertyTestClass() { Id = 255255, Greet = "Hello stranger!" }; var stringSerializer = new StringSerializer(); var buffer = new byte[64]; serializeDelegate(context, testObject, buffer, 0); // Null mask size in bytes. Assert.Equal(1, MemoryMapper.ReadByte(buffer, 0)); // Null mask values. Assert.Equal(0, MemoryMapper.ReadByte(buffer, sizeof(byte))); Assert.Equal(testObject.Id, MemoryMapper.ReadInt(buffer, sizeof(byte) * 2)); Assert.Equal(testObject.Greet, stringSerializer.Deserialize(buffer, sizeof(byte) * 2 + sizeof(int))); }
public void GetPropertyValueThrowExceptionWhenNoGetMethod() { PropertyTestClass propertyTestClass = new PropertyTestClass(); ExpressionHelper.GetPropertyValue(propertyTestClass, "WriteOnlyProperty"); }
public void SetPropertyValueThrowExceptionWhenNoSetMethod() { PropertyTestClass propertyTestClass = new PropertyTestClass(); ExpressionHelper.SetPropertyValue(propertyTestClass, "ReadOnlyProperty", 1); }
public void SetPropertyValueThrowsExceptionWhenNonImplicitlyConvertableValueIsSet() { PropertyTestClass propertyTestClass = new PropertyTestClass(); ExpressionHelper.SetPropertyValue(propertyTestClass, "WriteOnlyProperty", 1F); }