public virtual Expression MergeWithNext()
        {
            var expression = this;

            if (Next != null && Operator != null)
            {
                var result = Operator.Apply(Compile(), Next.Compile());
                expression = ExpressionConverter.Instance.FromCompileResult(result);
                if (Next != null)
                {
                    expression.Operator = Next.Operator;
                }
                else
                {
                    expression.Operator = null;
                }
                expression.Next = Next.Next;
                if (expression.Next != null)
                {
                    expression.Next.Prev = expression;
                }
                expression.Prev = Prev;
            }
            else
            {
                throw (new FormatException("Invalid formula syntax. Operator missing expression."));
            }
            if (Prev != null)
            {
                Prev.Next = expression;
            }
            return(expression);
        }
Exemplo n.º 2
0
        public virtual Expression MergeWithNext()
        {
            var expression = this;

            if (Next != null && Operator != null)
            {
                var result = Operator.Apply(Compile(), Next.Compile());
                expression = ExpressionConverter.Instance.FromCompileResult(result);
                if (Next != null)
                {
                    expression.Operator = Next.Operator;
                }
                else
                {
                    expression.Operator = null;
                }
                expression.Next = Next.Next;
                if (expression.Next != null)
                {
                    expression.Next.Prev = expression;
                }
                expression.Prev = Prev;
            }
            if (Prev != null)
            {
                Prev.Next = expression;
            }
            return(expression);
        }
Exemplo n.º 3
0
    //etc.
    #endregion
    public static void Main(string[] args)
    {
        User user = new User()
        {
            Age = 16, UserName = "******"
        };

        Console.WriteLine(Operator.Apply(user, "greater_than", "Age", 15));
        Console.WriteLine(Operator.Apply(user, "greater_than", "Age", 17));
        Console.WriteLine(Operator.Apply(user, "equal", "UserName", "John"));
        Console.WriteLine(Operator.Apply(user, "equal", "UserName", "Bob"));
    }
Exemplo n.º 4
0
        public void CanCompareTimestampsFromDifferentTimezones()
        {
            var afterTimestamp = "1970-01-01T00:00:00-01:00"; //equivalent to 1970-01-01T01:00:00Z
            var utcTimestamp   = "1970-01-01T00:00:01Z";

            var after  = new JValue(afterTimestamp);
            var before = new JValue(utcTimestamp);

            Assert.True(Operator.Apply("after", after, before));
            Assert.False(Operator.Apply("after", before, after));

            Assert.True(Operator.Apply("before", before, after));
            Assert.False(Operator.Apply("before", after, before));
        }
Exemplo n.º 5
0
        public void CanCompareTimestampWithUnixMillis()
        {
            var afterTimestamp = "1970-01-01T00:00:00-01:00"; //equivalent to 1970-01-01T01:00:00Z
            var beforeMillis   = 1000;

            var after  = new JValue(afterTimestamp);
            var before = new JValue(beforeMillis);

            Assert.True(Operator.Apply("after", after, before));
            Assert.False(Operator.Apply("after", before, after));

            Assert.True(Operator.Apply("before", before, after));
            Assert.False(Operator.Apply("before", after, before));
        }
        public void Apply_StateUnderTest_ExpectedBehavior()
        {
            // Arrange

            //var operator = this.CreateOperator();
            //Payment payment = null;
            //string op = null;
            //string prop = null;

            // Act
            Operator.Apply(
                new Payment {
                PaymentId = 23, Purpose = "Book", NextAction = "String"
            },
                string.Empty,
                string.Empty);

            // Assert
            Assert.Fail();
            this.mockRepository.VerifyAll();
        }
Exemplo n.º 7
0
        public override Expression MergeWithNext()
        {
            Expression returnValue = null;

            if (Next != null && Operator != null)
            {
                var result           = Operator.Apply(Compile(), Next.Compile());
                var expressionString = result.Result.ToString();
                var converter        = new ExpressionConverter();
                returnValue = converter.FromCompileResult(result);
                if (Next != null)
                {
                    Operator = Next.Operator;
                }
                else
                {
                    Operator = null;
                }
                Next = Next.Next;
            }
            return(returnValue);
        }
Exemplo n.º 8
0
 public void Apply_LessThan_SupportedTypes_ReturnsFalse(object userValue, object clauseValue)
 {
     Assert.False(Operator.Apply("lessThan", new JValue(userValue), new JValue(clauseValue)));
 }
Exemplo n.º 9
0
 public void Apply_LessThanOrEqual_SupportedTypes_ReturnsTrue(object userValue, object clauseValue)
 {
     Assert.True(Operator.Apply("lessThanOrEqual", new JValue(userValue), new JValue(clauseValue)));
 }
Exemplo n.º 10
0
 public void Apply_Contains_SupportedTypes_ReturnsTrue()
 {
     Assert.True(Operator.Apply("contains", new JValue("userValue"), new JValue("serValu")));
 }
Exemplo n.º 11
0
 public void Apply_Contains_SupportedTypes_ReturnsFalse(object userValue, object clauseValue)
 {
     Assert.False(Operator.Apply("contains", new JValue(userValue), new JValue(clauseValue)));
 }
Exemplo n.º 12
0
 public void Apply_UnknownOperation_ReturnsFalse()
 {
     Assert.False(Operator.Apply("unknown", new JValue(10), new JValue(10)));
 }
Exemplo n.º 13
0
 public void Apply_UserValueIsNull_ReturnsFalse()
 {
     Assert.False(Operator.Apply("in", LdValue.Null, LdValue.Of(10)));
 }
Exemplo n.º 14
0
 public void Apply_ClauseValueIsNull_ReturnsFalse()
 {
     Assert.False(Operator.Apply("in", new JValue(10), null));
 }
Exemplo n.º 15
0
 public void Apply_EndsWith_ReturnsFalse(object userValue, object clauseValue)
 {
     Assert.False(Operator.Apply("endsWith", ArbitraryValue(userValue), ArbitraryValue(clauseValue)));
 }
Exemplo n.º 16
0
        public void Apply_Any_Operators(string opName, object userValue, object clauseValue, bool expected)
        {
            var result = Operator.Apply(opName, new JValue(userValue), new JValue(clauseValue));

            Assert.Equal(expected, result);
        }
Exemplo n.º 17
0
 public void Apply_LessThan_SupportedTypes_ReturnsTrue(object userValue, object clauseValue)
 {
     Assert.True(Operator.Apply("lessThan", ArbitraryValue(userValue), ArbitraryValue(clauseValue)));
 }
Exemplo n.º 18
0
 public void Apply_LessThanOrEqual_SupportedTypes_ReturnsFalse(object userValue, object clauseValue)
 {
     Assert.False(Operator.Apply("lessThanOrEqual", ArbitraryValue(userValue), ArbitraryValue(clauseValue)));
 }
Exemplo n.º 19
0
 public bool Match(UnlaunchUser user)
 {
     return(user.GetAttributes().ContainsKey(_attribute) && _operator.Apply(_value, user.GetAttributes()[_attribute], _type));
 }
Exemplo n.º 20
0
 public void Apply_ClauseValueIsNull_ReturnsFalse()
 {
     Assert.False(Operator.Apply("in", LdValue.Of(10), LdValue.Null));
 }
Exemplo n.º 21
0
 public void Apply_GreaterThan_SupportedTypes_ReturnsTrue(object userValue, object clauseValue)
 {
     Assert.True(Operator.Apply("greaterThan", new JValue(userValue), new JValue(clauseValue)));
 }
Exemplo n.º 22
0
 public void Apply_Matches_SupportedTypes_ReturnsFalse(object userValue, object clauseValue)
 {
     Assert.False(Operator.Apply("matches", ArbitraryValue(userValue), ArbitraryValue(clauseValue)));
 }
Exemplo n.º 23
0
 public void Apply_GreaterThanOrEqual_SupportedTypes_ReturnsFalse(object userValue, object clauseValue)
 {
     Assert.False(Operator.Apply("greaterThanOrEqual", new JValue(userValue), new JValue(clauseValue)));
 }
Exemplo n.º 24
0
 public void Apply_StartsWith_ReturnsFalse(object userValue, object clauseValue)
 {
     Assert.False(Operator.Apply("startsWith", new JValue(userValue), new JValue(clauseValue)));
 }
Exemplo n.º 25
0
 public void Apply_EndsWith_SupportedTypes_ReturnsTrue(string userValue, string clauseValue)
 {
     Assert.True(Operator.Apply("endsWith", LdValue.Of(userValue), LdValue.Of(clauseValue)));
 }
Exemplo n.º 26
0
 public void Apply_Matches_SupportedTypes_ReturnsTrue()
 {
     Assert.True(Operator.Apply("matches", new JValue("22"), new JValue(@"\d")));
 }
Exemplo n.º 27
0
 public void Apply_UserValueIsNull_ReturnsFalse()
 {
     Assert.False(Operator.Apply("in", null, new JValue(10)));
 }
Exemplo n.º 28
0
 public void Apply_GreaterThanOrEqual_SupportedTypes_ReturnsTrue(object userValue, object clauseValue)
 {
     Assert.True(Operator.Apply("greaterThanOrEqual", ArbitraryValue(userValue), ArbitraryValue(clauseValue)));
 }
Exemplo n.º 29
0
 public void Apply_In_SupportedTypes_ValuesAreEqual_ReturnsTrue(object userValue, object clauseValue)
 {
     Assert.True(Operator.Apply("in", new JValue(userValue), new JValue(clauseValue)));
 }
Exemplo n.º 30
0
 public void Apply_StartsWith_SupportedTypes_ReturnsTrue(string userValue, string clauseValue)
 {
     Assert.True(Operator.Apply("startsWith", new JValue(userValue), new JValue(clauseValue)));
 }