Beispiel #1
0
        public void TestAutoCastPropSetter_ULongNullable()
        {
            const string propName = "AULongNullable";
            var          obj      = new TesterClass();

            ObjectExtensions.SetPropertyValue(propName, obj, (short)1);
            Assert.AreEqual((ulong)1, obj.AULongNullable);
            ObjectExtensions.SetPropertyValue(propName, obj, 1);
            Assert.AreEqual((ulong)1, obj.AULongNullable);
            ObjectExtensions.SetPropertyValue(propName, obj, (long)1);
            Assert.AreEqual((ulong)1, obj.AULongNullable);
            ObjectExtensions.SetPropertyValue(propName, obj, (double)1);
            Assert.AreEqual((ulong)1, obj.AULongNullable);
            ObjectExtensions.SetPropertyValue(propName, obj, (float)1);
            Assert.AreEqual((ulong)1, obj.AULongNullable);
            ObjectExtensions.SetPropertyValue(propName, obj, (decimal)1);
            Assert.AreEqual((ulong)1, obj.AULongNullable);
            ObjectExtensions.SetPropertyValue(propName, obj, (sbyte)1);
            Assert.AreEqual((ulong)1, obj.AULongNullable);
            ObjectExtensions.SetPropertyValue(propName, obj, (byte)1);
            Assert.AreEqual((ulong)1, obj.AULongNullable);
            ObjectExtensions.SetPropertyValue(propName, obj, (ushort)1);
            Assert.AreEqual((ulong)1, obj.AULongNullable);
            ObjectExtensions.SetPropertyValue(propName, obj, (uint)1);
            Assert.AreEqual((ulong)1, obj.AULongNullable);
            ObjectExtensions.SetPropertyValue(propName, obj, (ulong)1);
            Assert.AreEqual((ulong)1, obj.AULongNullable);
            ObjectExtensions.SetPropertyValue(propName, obj, true);
            Assert.AreEqual((ulong)1, obj.AULongNullable);
            ObjectExtensions.SetPropertyValue(propName, obj, "1");
            Assert.AreEqual((ulong)1, obj.AULongNullable);
            ObjectExtensions.SetPropertyValue(propName, obj, '1');
            Assert.AreEqual((ulong)1, obj.AULongNullable);
        }
Beispiel #2
0
        public void TestArgsCheckSettingProperty()
        {
            var obj = new TesterClass();

            Assert.ThrowsException <ArgumentNullException>(() => obj.SetPropertyValue("NotExists", null));
            Assert.ThrowsException <ArgumentNullException>(() => (null as TesterClass).SetPropertyValue("AInt", 1));
        }
Beispiel #3
0
        public void TestAutoCastPropSetter_ULong()
        {
            const string propName = "AULong";
            var          obj      = new TesterClass();

            ObjectExtensions.SetPropertyValue(propName, obj, (short)1);
            Assert.AreEqual((ulong)1, obj.AULong);
            ObjectExtensions.SetPropertyValue(propName, obj, 1);
            Assert.AreEqual((ulong)1, obj.AULong);
            ObjectExtensions.SetPropertyValue(propName, obj, (long)1);
            Assert.AreEqual((ulong)1, obj.AULong);
            ObjectExtensions.SetPropertyValue(propName, obj, (double)1);
            Assert.AreEqual((ulong)1, obj.AULong);
            ObjectExtensions.SetPropertyValue(propName, obj, (float)1);
            Assert.AreEqual((ulong)1, obj.AULong);
            ObjectExtensions.SetPropertyValue(propName, obj, (decimal)1);
            Assert.ThrowsException <OverflowException>(() => ObjectExtensions.SetPropertyValue(propName, obj, (decimal)1 + ulong.MaxValue));
            Assert.AreEqual((ulong)1, obj.AULong);
            ObjectExtensions.SetPropertyValue(propName, obj, (sbyte)1);
            Assert.AreEqual((ulong)1, obj.AULong);
            ObjectExtensions.SetPropertyValue(propName, obj, (byte)1);
            Assert.AreEqual((ulong)1, obj.AULong);
            ObjectExtensions.SetPropertyValue(propName, obj, (ushort)1);
            Assert.AreEqual((ulong)1, obj.AULong);
            ObjectExtensions.SetPropertyValue(propName, obj, (uint)1);
            Assert.AreEqual((ulong)1, obj.AULong);
            ObjectExtensions.SetPropertyValue(propName, obj, (ulong)1);
            Assert.AreEqual((ulong)1, obj.AULong);
            ObjectExtensions.SetPropertyValue(propName, obj, true);
            Assert.AreEqual((ulong)1, obj.AULong);
            ObjectExtensions.SetPropertyValue(propName, obj, "1");
            Assert.AreEqual((ulong)1, obj.AULong);
            ObjectExtensions.SetPropertyValue(propName, obj, '1');
            Assert.AreEqual((ulong)1, obj.AULong);
        }