Beispiel #1
0
        public void TestAllFieldsGoBackToNull()
        {
            var dict = new System.Collections.Generic.Dictionary <string, object>();

            dict.Add("NullableInt", 1);
            dict.Add("NullableBoolean", true);
            dict.Add("NullableDouble", (double)10);
            dict.Add("NullableByte", (byte)1);
            dict.Add("NullableShort", (short)1);
            dict.Add("NullableLong", (long)1);
            dict.Add("NullableSingle", (Single)1);
            dict.Add("NullableDecimal", (byte)1);
            dict.Add("NullableChar", (char)';');
            dict.Add("NullableGuid", Guid.NewGuid());
            dict.Add("NullableDateTime", DateTime.Now);
            bool passed = true;
            var  obj    = new NullableTestClass();

            foreach (System.Collections.Generic.KeyValuePair <string, object> item in dict)
            {
                TestSetOfValue(item.Key, item.Value, obj);
                if (!TestSetOfValue(item.Key, null, obj))
                {
                    passed = false;
                }
            }
            Assert.IsTrue(passed);
        }
Beispiel #2
0
        public void TestBooleanForNull()
        {
            var obj = new NullableTestClass();

            obj.NullableBoolean = true;
            Assert.IsTrue(TestSetOfValue("NullableBoolean", null));
        }
Beispiel #3
0
        public void TestDoubleForNull()
        {
            var obj = new NullableTestClass();

            obj.NullableDouble = 1;
            Assert.IsTrue(TestSetOfValue("NullableDouble", null));
        }
Beispiel #4
0
        public void TestIntForNull()
        {
            var obj = new NullableTestClass();

            obj.NullableInt = 4;
            Assert.IsTrue(TestSetOfValue("NullableInt", null));
        }
Beispiel #5
0
 public static bool TestSetOfValue(string property, object value, NullableTestClass obj = null)
 {
     obj = obj ?? new NullableTestClass();
     var setMethod = Compiler.SetMethod(obj);
     var getMethod = Compiler.GetMethod(obj);
     setMethod(obj, property, value);
     var currentValue = getMethod(obj, property);
     if(currentValue == null && value == null) {
         return true;
     }
     return currentValue.ToString() == value.ToString();
 }
Beispiel #6
0
        public static bool TestSetOfValue(string property, object value, NullableTestClass obj = null)
        {
            obj = obj ?? new NullableTestClass();
            var setMethod = Compiler.SetMethod(obj);
            var getMethod = Compiler.GetMethod(obj);

            setMethod(obj, property, value);
            var currentValue = getMethod(obj, property);

            if (currentValue == null && value == null)
            {
                return(true);
            }
            return(currentValue.ToString() == value.ToString());
        }
Beispiel #7
0
 public void TestAllFields()
 {
     var dict = new System.Collections.Generic.Dictionary<string, object>();
     dict.Add("NullableInt", 1);
     dict.Add("NullableBoolean", true);
     dict.Add("NullableDouble", (double)10);
     dict.Add("NullableByte", (byte)1);
     dict.Add("NullableShort", (short)1);
     dict.Add("NullableLong", (long)1);
     dict.Add("NullableSingle", (Single)1);
     dict.Add("NullableDecimal", (byte)1);
     dict.Add("NullableChar", (char)';');
     dict.Add("NullableGuid", Guid.NewGuid());
     dict.Add("NullableDateTime", DateTime.Now);
     bool passed = true;
     var obj = new NullableTestClass();
     foreach (System.Collections.Generic.KeyValuePair<string, object> item in dict) {
         if (!TestSetOfValue(item.Key, item.Value, obj)) {
             passed = false;
         }
     }
     Assert.IsTrue(passed);
 }
Beispiel #8
0
 public void TestIntForNull()
 {
     var obj = new NullableTestClass();
     obj.NullableInt = 4;
     Assert.IsTrue(TestSetOfValue("NullableInt", null));
 }
Beispiel #9
0
 public void TestDoubleForNull()
 {
     var obj = new NullableTestClass();
     obj.NullableDouble = 1;
     Assert.IsTrue(TestSetOfValue("NullableDouble", null));
 }
Beispiel #10
0
 public void TestBooleanForNull()
 {
     var obj = new NullableTestClass();
     obj.NullableBoolean = true;
     Assert.IsTrue(TestSetOfValue("NullableBoolean", null));
 }