public void test_WHEN_neither_field_refs_nor_value_specified_THEN_expression_is_not_valid()
        {
            var xml = string.Format(
                "<DateRangesOverlap>" +
                "</DateRangesOverlap>");

            var analyzer = new ReDateRangesOverlapAnalyzer(XmlHelper.Get(xml), null);

            Assert.IsFalse(analyzer.IsValid());
        }
        public void test_WHEN_field_ref_not_specified_and_value_specified_THEN_expression_is_not_valid()
        {
            var xml = string.Format(
                "<DateRangesOverlap>" +
                "    <Value Type=\"DateTime\"><Now/></Value>" +
                "</DateRangesOverlap>");

            var analyzer = new ReDateRangesOverlapAnalyzer(XmlHelper.Get(xml), null);

            Assert.IsFalse(analyzer.IsValid());
        }
        public void test_WHEN_field_refs_specified_and_value_not_specified_THEN_expression_is_not_valid()
        {
            var xml = string.Format(
                "<DateRangesOverlap>" +
                "    <FieldRef Name=\"StartField\" />" +
                "    <FieldRef Name=\"StopField\" />" +
                "    <FieldRef Name=\"RecurrenceField\" />" +
                "</DateRangesOverlap>");

            var analyzer = new ReDateRangesOverlapAnalyzer(XmlHelper.Get(xml), null);

            Assert.IsFalse(analyzer.IsValid());
        }
        public void test_WHEN_field_refs_and_incorrect_text_value_specified_THEN_expression_is_not_valid()
        {
            var xml = string.Format(
                "<DateRangesOverlap>" +
                "    <FieldRef Name=\"StartField\" />" +
                "    <FieldRef Name=\"StopField\" />" +
                "    <FieldRef Name=\"RecurrenceField\" />" +
                "    <Value Type=\"DateTime\">test</Value>" +
                "</DateRangesOverlap>");

            var analyzer = new ReDateRangesOverlapAnalyzer(XmlHelper.Get(xml), new ReOperandBuilderFromCaml());

            Assert.IsFalse(analyzer.IsValid());
        }
        public void test_WHEN_expression_is_valid_THEN_operation_is_returned()
        {
            var xml = string.Format(
                "<DateRangesOverlap>" +
                "    <FieldRef Name=\"Title\" />" +
                "    <FieldRef Name=\"Title\" />" +
                "    <FieldRef Name=\"Title\" />" +
                "    <Value Type=\"DateTime\"><Now/></Value>" +
                "</DateRangesOverlap>");

            var b = MockRepository.GenerateStub <IReOperandBuilder>();

            b.Stub(c => c.CreateFieldRefOperand(null)).Return(new FieldRefOperand("Title")).IgnoreArguments();
            b.Stub(c => c.CreateValueOperand(null, false)).Return(new DateTimeValueOperand("Now", false)).IgnoreArguments();

            var analyzer  = new ReDateRangesOverlapAnalyzer(XmlHelper.Get(xml), b);
            var operation = analyzer.GetOperation();

            Assert.IsInstanceOf <DateRangesOverlapOperation>(operation);
            var operationT = (DateRangesOverlapOperation)operation;

            Assert.That(operationT.ToExpression().ToString(), Is.EqualTo(
                            "DateRangesOverlap(x.get_Item(\"Title\"), x.get_Item(\"Title\"), x.get_Item(\"Title\"), Convert(Convert(Camlex.Now)))"));
        }
        public void test_WHEN_xml_is_null_THEN_expression_is_not_valid()
        {
            var analyzer = new ReDateRangesOverlapAnalyzer(null, null);

            Assert.IsFalse(analyzer.IsValid());
        }
        public void test_WHEN_expression_is_not_valid_THEN_exception_is_thrown()
        {
            var analyzer = new ReDateRangesOverlapAnalyzer(null, null);

            Assert.Throws <CamlAnalysisException>(() => analyzer.GetOperation());
        }
        public void test_WHEN_expression_is_not_valid_THEN_exception_is_thrown()
        {
            var analyzer = new ReDateRangesOverlapAnalyzer(null, null);

            analyzer.GetOperation();
        }