Exemple #1
0
        public void TestNullUtils()
        {
            var     a = (decimal?)3.0; //1
            var     b = "3";
            var     c = (float?)null;  //3
            var     d = (int?)null;
            var     e = new Test123(); //5
            Test123 f = null;

            var a1 = NullUtils.IsNullThen(a, val => val.Value + 1, 30);
            var a2 = NullUtils.IsNullThen(b, val => val + "1", "30");
            var a3 = NullUtils.IsNullThen(c, val => val.Value + 1, 30);
            var a4 = NullUtils.IsNullThen(d, val => val.Value + 1, 30);
            var a5 = NullUtils.IsNullThen(e, val => new Test123 {
                Col1 = 11
            }, new Test123 {
                Col1 = 30
            });
            var a6 = NullUtils.IsNullThen(f, val => new Test123 {
                Col1 = 11
            }, new Test123 {
                Col1 = 30
            });

            Assert.AreEqual(a1.Value, 4);
            Assert.AreEqual(a2, "31");
            Assert.AreEqual(a3.Value, 30);
            Assert.AreEqual(a4.Value, 30);
            Assert.AreEqual(a5.Col1, 11);
            Assert.AreEqual(a6.Col1, 30);
        }