public void GreaterThanCondition()
        {
            var greaterThanCondition = new GreaterThanCondition <decimal>();

            var expr1 = greaterThanCondition.For <TestSource>(x => x.Price);

            Assert.IsNull(expr1);

            greaterThanCondition.Value = new FilterValue <decimal?>
            {
                LeftValue = 1M
            };

            var expr2 = greaterThanCondition.For <TestSource>(x => x.Price);

            Assert.IsTrue(expr2.Compile()(new TestSource {
                Price = 2
            }));

            greaterThanCondition.Value = new FilterValue <decimal?>
            {
                LeftValue = 5M
            };

            var expr3 = greaterThanCondition.For <TestSource>(x => x.Price);

            Assert.IsFalse(expr3.Compile()(new TestSource {
                Price = 5
            }));
        }
Exemplo n.º 2
0
        public void RubberStamp_Conditions_GreaterThanCondition_SetMessage_Test()
        {
            var condition = new GreaterThanCondition <TestClass, string>(t => t.Name, "TEST")
                            .SetMessage("Error message");

            Assert.AreEqual("Error message", condition.Message);
        }
Exemplo n.º 3
0
        public void RubberStamp_Conditions_GreaterThanCondition_String_Equal_Test()
        {
            var condition = new GreaterThanCondition <TestClass, string>(t => t.Name, "cde");

            Assert.IsFalse(condition.IsValid(new TestClass {
                Name = "cde"
            }));
        }
Exemplo n.º 4
0
        public void RubberStamp_Conditions_GreaterThanCondition_Int_Lower_Invalid_Test()
        {
            var condition = new GreaterThanCondition <TestClass, int>(t => t.Index, 3);

            Assert.IsFalse(condition.IsValid(new TestClass {
                Index = 2
            }));
        }
Exemplo n.º 5
0
    public void ToStringTest()
    {
        var left  = new FakeToStringCondition("Valor1");
        var right = new FakeToStringCondition("Valor2");

        var sut    = new GreaterThanCondition(left, right);
        var actual = sut.ToString();

        actual.Should().Be("Valor1 > Valor2");
    }
Exemplo n.º 6
0
 public static void NumericConditions <TProperty>(IDictionary <string, IValueTypeCondition <TProperty> > conditions) where TProperty : struct, IComparable, IComparable <TProperty>, IEquatable <TProperty>
 {
     conditions["none"]               = new ValueTypeNoneCondition <TProperty>("None");
     conditions["equal"]              = new ValueTypeEqualCondition <TProperty>("Equal");
     conditions["notequal"]           = new ValueTypeNotEqualCondition <TProperty>("NotEqual");
     conditions["between"]            = new BetweenCondition <TProperty>("Between");
     conditions["lessthan"]           = new LessThanCondition <TProperty>("LessThan");
     conditions["greaterthan"]        = new GreaterThanCondition <TProperty>("GreaterThan");
     conditions["lessthanorequal"]    = new LessThanOrEqualCondition <TProperty>("LessThanOrEqual");
     conditions["greaterthanorequal"] = new GreaterThanOrEqualCondition <TProperty>("GreaterThanOrEqual");
     conditions["isnull"]             = new ValueTypeIsNullCondition <TProperty>("IsNull");
     conditions["isnotnull"]          = new ValueTypeIsNotNullCondition <TProperty>("IsNotNull");
 }
Exemplo n.º 7
0
        public void ValueTypeFilterSetDefaultValue_Lazy()
        {
            var filter = new ValueTypeFilter <TestSource, int>();

            filter.For(x => x.Id);
            filter.Conditions(condition =>
            {
                condition["equal"]       = new ValueTypeEqualCondition <int>();
                condition["greaterthan"] = new GreaterThanCondition <int>();
            });


            var expr1 = filter.BuildExpression <TestSource>();

            Assert.IsNull(expr1);

            filter.SetDefaultValue(() => new FilterValue <int?>
            {
                LeftValue    = 10,
                ConditionKey = "equal"
            });

            var expr2 = filter.BuildExpression <TestSource>();

            Assert.IsNotNull(expr2);

            Assert.IsTrue(expr2.Compile()(new TestSource {
                Id = 10
            }));

            Assert.IsFalse(expr2.Compile()(new TestSource {
                Id = 12
            }));

            filter.Init(new FilterValue <int?>
            {
                ConditionKey = "greaterthan",
                LeftValue    = 5
            });

            var expr3 = filter.BuildExpression <TestSource>();

            Assert.IsNotNull(expr3);

            Assert.IsTrue(expr3.Compile()(new TestSource {
                Id = 10
            }));
            Assert.IsFalse(expr3.Compile()(new TestSource {
                Id = 4
            }));
        }
Exemplo n.º 8
0
        public void Test___Method_Check___Equals___Generic()
        {
            var testee = new GreaterThanCondition <int>()
            {
                Value1 = new AnyVariable <int>()
                {
                    Value = 20
                },
                Value2 = new AnyVariable <int>()
                {
                    Value = 20
                }
            };

            Assert.IsFalse(testee.Check());
        }
Exemplo n.º 9
0
        public void Test___Method_Check___Less()
        {
            var testee = new GreaterThanCondition()
            {
                Value1 = new AnyVariable()
                {
                    Value = 10
                },
                Value2 = new AnyVariable()
                {
                    Value = 20
                }
            };

            Assert.IsFalse(testee.Check());
        }
Exemplo n.º 10
0
    public void Evaluate(object leftValue, object rightValue, bool expectedResult)
    {
        var variables = A.Dummy <IVariableDictionary>();

        var left = A.Fake <IConditionKeyword>(i => i.Strict());

        A.CallTo(() => left.Evaluate(variables)).Returns(leftValue);

        var right = A.Fake <IConditionKeyword>(i => i.Strict());

        A.CallTo(() => right.Evaluate(variables)).Returns(rightValue);

        var sut    = new GreaterThanCondition(left, right);
        var actual = sut.Evaluate(variables);

        actual.Should().Be(expectedResult);
    }
Exemplo n.º 11
0
        public void RubberStamp_Conditions_GreaterThanCondition_String_Message_Test()
        {
            var condition = new GreaterThanCondition <TestClass, string>(t => t.Name, "TEST");

            Assert.AreEqual("The Property Name has to be greater than TEST", condition.Message);
        }
Exemplo n.º 12
0
        public void RubberStamp_Conditions_GreaterThanCondition_Int_Message_Test()
        {
            var condition = new GreaterThanCondition <TestClass, int>(t => t.Index, 3);

            Assert.AreEqual("The Property Index has to be greater than 3", condition.Message);
        }