public void get_value_for_property() { var dt = new { id = "23" }; Expression <Func <Test, bool> > data = t => t.Data == dt.id; Assert.Equal("23", ObjectExtend.CastAs <MemberExpression>(data.Body.CastAs <BinaryExpression>().Right).GetValue()); }
public void FactMethodName() { Expression <Func <Test, bool> > data = t => new[] { 1, 2 }.Contains(t.Id); var meth = ObjectExtend.CastAs <MethodCallExpression>(data.Body); Assert.Equal("Contains", meth.Method.Name); var param = ObjectExtend.CastAs <MemberExpression>(meth.Arguments[1]); Assert.True(param.BelongsToParameter()); var sb = new StringBuilder(); sb.Append(param.Member.Name).Append(" in ("); var list = ObjectExtend.CastAs <IEnumerable>(meth.Arguments[0].GetValue()); var en = list.GetEnumerator(); while (en.MoveNext()) { sb.Append(en.Current).Append(","); } sb.RemoveLast(); sb.Append(")"); Write(sb.ToString()); }
public void parameter_is_argument_of_method_call() { var l = new[] { "a", "b" }; Expression <Func <Test, bool> > data = t => l.Contains(t.Data); Assert.True(ObjectExtend.CastAs <MethodCallExpression>(data.Body).HasParameterArgument()); }
public void get_value_for_field() { var id = "23"; Expression <Func <Test, bool> > data = t => t.Data == id; Assert.Equal("23", ObjectExtend.CastAs <MemberExpression>(data.Body.CastAs <BinaryExpression>().Right).GetValue()); }
public void member_belongs_to_paramater_of_type() { Expression <Func <Test, bool> > data = t => t.Data == "23"; Assert.True(ObjectExtend.CastAs <MemberExpression>(data.Body.CastAs <BinaryExpression>().Left).BelongsToParameter(typeof(Test))); }
public void complex_member_belongs_to_paramater() { Expression <Func <Test, bool> > data = t => t.Child.Child.Child.Data == "23"; Assert.True(ObjectExtend.CastAs <MemberExpression>(data.Body.CastAs <BinaryExpression>().Left).BelongsToParameter()); }
public void expression_with_initializer() { Expression <Func <Test, bool> > data = t => DateTime.UtcNow > new DateTime(2, 2, 2); Assert.Equal(new DateTime(2, 2, 2), ObjectExtend.CastAs <BinaryExpression>(data.Body).Right.GetValue()); }
public void get_value_for_property_returned_by_method() { Expression <Func <Test, bool> > data = t => t.Data == this.TestId().Data; Assert.Equal("29", ObjectExtend.CastAs <BinaryExpression>(data.Body).Right.GetValue()); }
public void get_value_for_property_returning_from_method_call() { Expression <Func <Test, bool> > data = t => t.Data == this.TestId().Bla().ToString(); Assert.Equal("0", ObjectExtend.CastAs <MethodCallExpression>(data.Body.CastAs <BinaryExpression>().Right).GetValue()); }
public void get_value_for_method_call_with_argument() { Expression <Func <Test, bool> > data = t => t.Data == this.Id(2); Assert.Equal("2", ObjectExtend.CastAs <MethodCallExpression>(data.Body.CastAs <BinaryExpression>().Right).GetValue()); }
public void member_is_parameter() { Expression <Func <int, bool> > data = t => t == 23; Assert.True(ObjectExtend.CastAs <BinaryExpression>(data.Body).Left.IsParameter(typeof(int))); }