Example #1
0
        public void GetNotExistPropWillReturnNull()
        {
            var val  = new { A = 3 };
            var prop = CommonMacros.GetProp(val, "A.A");

            Assert.Null(prop);
        }
Example #2
0
        public void GetSimplePropOk()
        {
            var val  = new { A = 3 };
            var prop = CommonMacros.GetProp(val, "A");

            Assert.NotNull(prop);
        }
Example #3
0
        public void CanGetNextedObjectValue()
        {
            var val    = new { A = new { B = 4 } };
            var getted = CommonMacros.GetPropValue(val, "A.B");

            Assert.Equal(4, getted);
        }
Example #4
0
        public void GetNestedPropOk()
        {
            var val  = new { A = new { A = 3 } };
            var prop = CommonMacros.GetProp(val, "A.A");

            Assert.NotNull(prop);
        }
Example #5
0
        public void InputNullWillBeEmpty()
        {
            string val    = null;
            var    actual = CommonMacros.Val(SdmapCompilerContext.CreateEmpty(), "", val, null);

            Assert.True(actual.IsSuccess);
            Assert.Equal(string.Empty, actual.Value);
        }
Example #6
0
        public void HelloWorld()
        {
            var val    = "Hello World";
            var actual = CommonMacros.Val(SdmapCompilerContext.CreateEmpty(), "", val, null);

            Assert.True(actual.IsSuccess);
            Assert.Equal(val, actual.Value);
        }
Example #7
0
        public void NotExistPropShouldFail()
        {
            var val = CommonMacros.Iif(SdmapCompilerContext.CreateEmpty(),
                                       "",
                                       new { A = new bool?() },
                                       new object[] { "B", "true", "false" });

            Assert.False(val.IsSuccess);
        }
Example #8
0
        public void ValueIsNotEmpty()
        {
            var val = CommonMacros.IsNotEmpty(SdmapCompilerContext.CreateEmpty(),
                                              "",
                                              new { A = DateTime.Now },
                                              new object[] { "A", "Ok" });

            Assert.True(val.IsSuccess);
            Assert.Equal("Ok", val.Value);
        }
Example #9
0
        public void EmptyNullShouldTreatFalsy()
        {
            var val = CommonMacros.Iif(SdmapCompilerContext.CreateEmpty(),
                                       "",
                                       new { A = new bool?() },
                                       new object[] { "A", "true", "false" });

            Assert.True(val.IsSuccess);
            Assert.Equal("false", val.Value);
        }
Example #10
0
        public void Smoke()
        {
            var val = CommonMacros.Iif(SdmapCompilerContext.CreateEmpty(),
                                       "",
                                       new { A = true },
                                       new object[] { "A", "true", "false" });

            Assert.True(val.IsSuccess);
            Assert.Equal("true", val.Value);
        }
Example #11
0
        public static bool PropertyExistsAndEvalToTrue(object obj, string propName)
        {
            var val = CommonMacros.GetPropValue(obj, propName);

            if (val is bool)
            {
                return((bool)val);
            }
            if (val is bool?)
            {
                return(((bool?)val).GetValueOrDefault());
            }

            return(false);
        }
Example #12
0
 public static bool IsEmpty(object obj)
 {
     if (obj == null)
     {
         return(true);
     }
     if (obj is string)
     {
         return(string.IsNullOrEmpty((string)obj));
     }
     if (obj is IEnumerable)
     {
         return(CommonMacros.ArrayEmpty(obj));
     }
     return(false);
 }
Example #13
0
 private Result <string> CallIsNotLike(object self,
                                       string prop, string regex, string result)
 {
     return(CommonMacros.IsNotLike(SdmapCompilerContext.CreateEmpty(),
                                   "", self, new object[] { prop, regex, result }));
 }
Example #14
0
 private Result <string> CallIterate(object self, string joiner, string text)
 {
     return(CommonMacros.Iterate(SdmapCompilerContext.CreateEmpty(),
                                 "", self, new object[] { joiner, text }));
 }
Example #15
0
 public static object LoadProp(object obj, string propName)
 {
     return(CommonMacros.GetPropValue(obj, propName));
 }
Example #16
0
 public void NumberEqualsNumber()
 {
     Assert.True(CommonMacros.IsEqual(3.14m, 3.14));
 }
Example #17
0
        public void DateEqualsDate()
        {
            var date = new DateTime(2016, 1, 1);

            Assert.True(CommonMacros.IsEqual(date, DateUtil.Parse("2016/1/1").Value));
        }
Example #18
0
 public void BoolEqualBool()
 {
     Assert.True(CommonMacros.IsEqual(true, true));
 }
Example #19
0
        public void CanDetectNotEmptyArray()
        {
            var arr = Enumerable.Range(1, 10);

            Assert.False(CommonMacros.ArrayEmpty(arr));
        }
Example #20
0
 private Result <string> CallEach(object self,
                                  string prop, string joiner, string text)
 {
     return(CommonMacros.Each(SdmapCompilerContext.CreateEmpty(),
                              "", self, new object[] { prop, joiner, text }));
 }
Example #21
0
 public void GetNotExistPropWillNotThrow()
 {
     var val  = new { A = 3 };
     var prop = CommonMacros.GetProp(val, "B.C.D");
 }
Example #22
0
 private Result <string> CallHasProp(object self, string prop, string result)
 {
     return(CommonMacros.HasProp(SdmapCompilerContext.CreateEmpty(), "", self, new[] { prop, result }));
 }