Пример #1
0
        public void test_WHEN_method_call_result_is_null_and_casted_to_string_based_THEN_nullvalue_operand_is_created()
        {
            Expression <Func <SPListItem, bool> > expr = x => x["Foo"] == (DataTypes.Integer)val1();

            var operandBuilder = new OperandBuilder();
            var operand        = operandBuilder.CreateValueOperandForNativeSyntax(((BinaryExpression)expr.Body).Right);

            Assert.That(operand, Is.InstanceOf <NullValueOperand>());
        }
        public void test_WHEN_nested_method_call_result_is_null_THEN_nullvalue_operand_is_created()
        {
            Func <object> f = () => null;
            Expression <Func <SPListItem, bool> > expr = x => x["Foo"] == f();

            var operandBuilder = new OperandBuilder();
            var operand        = operandBuilder.CreateValueOperandForNativeSyntax(((BinaryExpression)expr.Body).Right);

            Assert.That(operand, Is.InstanceOf <NullValueOperand>());
        }
        public void test_WHEN_native_value_is_text_THEN_text_operand_is_created()
        {
            var operandBuilder = new OperandBuilder();
            Expression <Func <SPListItem, bool> > expr = x => (string)x["Email"] == "*****@*****.**";
            var operand = operandBuilder.CreateValueOperandForNativeSyntax(((BinaryExpression)expr.Body).Right);

            Assert.That(operand, Is.InstanceOf <TextValueOperand>());

            var valueOperand = operand as TextValueOperand;

            Assert.That(valueOperand.Type, Is.EqualTo(typeof(DataTypes.Text)));
            Assert.That(valueOperand.Value, Is.EqualTo("*****@*****.**"));
        }
        public void test_WHEN_native_value_is_decimal_THEN_number_operand_is_created()
        {
            var operandBuilder = new OperandBuilder();
            Expression <Func <SPListItem, bool> > expr = x => (decimal)x["Foo"] == 1.5m;
            var operand = operandBuilder.CreateValueOperandForNativeSyntax(((BinaryExpression)expr.Body).Right);

            Assert.That(operand, Is.InstanceOf <NumberValueOperand>());

            var valueOperand = operand as NumberValueOperand;

            Assert.That(valueOperand.Type, Is.EqualTo(typeof(DataTypes.Number)));
            Assert.That(valueOperand.Value, Is.EqualTo(1.5));
        }
        public void test_WHEN_native_value_is_boolean_THEN_boolean_operand_is_created()
        {
            var operandBuilder = new OperandBuilder();
            Expression <Func <SPListItem, bool> > expr = x => (bool)x["Foo"] == true;
            var operand = operandBuilder.CreateValueOperandForNativeSyntax(((BinaryExpression)expr.Body).Right);

            Assert.That(operand, Is.InstanceOf <BooleanValueOperand>());

            var valueOperand = operand as BooleanValueOperand;

            Assert.That(valueOperand.Type, Is.EqualTo(typeof(DataTypes.Boolean)));
            Assert.That(valueOperand.Value, Is.True);
        }
        public void test_WHEN_native_value_is_datetime_with_includetimevalue_THEN_datetime_operand_is_created()
        {
            var operandBuilder = new OperandBuilder();
            Expression <Func <SPListItem, bool> > expr = x => (DateTime)x["Foo"] == new DateTime(2010, 1, 2, 3, 4, 5).IncludeTimeValue();
            var operand = operandBuilder.CreateValueOperandForNativeSyntax(((BinaryExpression)expr.Body).Right);

            Assert.That(operand, Is.InstanceOf <DateTimeValueOperand>());

            var valueOperand = operand as DateTimeValueOperand;

            Assert.That(valueOperand.Type, Is.EqualTo(typeof(DataTypes.DateTime)));
            Assert.That(valueOperand.Value, Is.EqualTo(new DateTime(2010, 1, 2, 3, 4, 5)));
            Assert.That(valueOperand.IncludeTimeValue, Is.True);
        }
        public void test_WHEN_native_value_is_guid_THEN_guid_operand_is_created()
        {
            var operandBuilder = new OperandBuilder();

            var guid = new Guid("4feaf1f3-5b04-4d93-b0fc-4e48d0c60eed");
            Expression <Func <SPListItem, bool> > expr = x => (Guid)x["Foo"] == guid;
            var operand = operandBuilder.CreateValueOperandForNativeSyntax(((BinaryExpression)expr.Body).Right);

            Assert.That(operand, Is.InstanceOf <GuidValueOperand>());

            var valueOperand = operand as GuidValueOperand;

            Assert.That(valueOperand.Type, Is.EqualTo(typeof(DataTypes.Guid)));
            Assert.That(valueOperand.Value, Is.EqualTo(new Guid("4feaf1f3-5b04-4d93-b0fc-4e48d0c60eed")));
        }