Exemplo n.º 1
0
        public void Attempt_to_set_property_using_null_reference()
        {
            PropertyTestClass testObject = null;
            const int         length     = 7;

            Assert.IsFalse(testObject.TrySetProperty("Length", length));
        }
Exemplo n.º 2
0
        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");
        }
Exemplo n.º 3
0
 public void Get_existing_property_with_wrong_type()
 {
     PropertyTestClass testObject = new PropertyTestClass();
     string length;
     Assert.IsFalse(testObject.TryGetProperty("Length", out length));
     Assert.IsNull(length);
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 public void Attempt_to_get_nonexistent_property()
 {
     PropertyTestClass testObject = new PropertyTestClass();
     int length;
     Assert.IsFalse(testObject.TryGetProperty("bar", out length));
     Assert.AreEqual(0, length);
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        public void Attempt_to_get_nonexistent_property()
        {
            PropertyTestClass testObject = new PropertyTestClass();
            int length;

            Assert.IsFalse(testObject.TryGetProperty("bar", out length));
            Assert.AreEqual(0, length);
        }
Exemplo n.º 12
0
        public void Get_existing_property_with_wrong_type()
        {
            PropertyTestClass testObject = new PropertyTestClass();
            string            length;

            Assert.IsFalse(testObject.TryGetProperty("Length", out length));
            Assert.IsNull(length);
        }
Exemplo n.º 13
0
        public void GetPropertyValue()
        {
            PropertyTestClass propertyTestClass = new PropertyTestClass();

            propertyTestClass.ReadWriteProperty = 2;

            Assert.AreEqual(2, ExpressionHelper.GetPropertyValue(propertyTestClass, "ReadWriteProperty"));
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        public void SetStringPropertyValueToNull()
        {
            PropertyTestClass propertyTestClass = new PropertyTestClass();

            propertyTestClass.StringProperty = "Test";

            ReflectionHelper.SetPropertyValue(propertyTestClass, "StringProperty", null);

            Assert.AreEqual(null, propertyTestClass.StringProperty);
        }
Exemplo n.º 18
0
        public void SetPropertyValue()
        {
            PropertyTestClass propertyTestClass = new PropertyTestClass();

            propertyTestClass.ReadWriteProperty = 1;

            ExpressionHelper.SetPropertyValue(propertyTestClass, "ReadWriteProperty", 2);

            Assert.AreEqual(2, propertyTestClass.ReadWriteProperty);
        }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
        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)));
        }
Exemplo n.º 21
0
        public void GetPropertyValueThrowExceptionWhenNoGetMethod()
        {
            PropertyTestClass propertyTestClass = new PropertyTestClass();

            ExpressionHelper.GetPropertyValue(propertyTestClass, "WriteOnlyProperty");
        }
Exemplo n.º 22
0
        public void SetPropertyValueThrowExceptionWhenNoSetMethod()
        {
            PropertyTestClass propertyTestClass = new PropertyTestClass();

            ExpressionHelper.SetPropertyValue(propertyTestClass, "ReadOnlyProperty", 1);
        }
Exemplo n.º 23
0
        public void SetPropertyValueThrowsExceptionWhenNonImplicitlyConvertableValueIsSet()
        {
            PropertyTestClass propertyTestClass = new PropertyTestClass();

            ExpressionHelper.SetPropertyValue(propertyTestClass, "WriteOnlyProperty", 1F);
        }