Example #1
0
        public void Build_WFS_Filters()
        {
            var wfsFilter = new WFSFilter();

            Assert.IsFalse(wfsFilter.CanUndo);
            Assert.IsFalse(wfsFilter.CanAddLogicalOperation);
            Assert.IsTrue(wfsFilter.CanAddComparisionOperation);

            var taxonIdEqualToOperation = new BinaryComparisionOperation(
                new FieldValue("TaxonId"),
                new ConstantValue("4000107"),
                WFSBinaryComparisionOperator.EqualTo);

            wfsFilter.AddComparisionOperation(taxonIdEqualToOperation);
            Assert.AreEqual("'TaxonId' = 4000107", wfsFilter.FormulaRepresentation());
            Assert.IsTrue(wfsFilter.CanAddLogicalOperation);
            Assert.IsFalse(wfsFilter.CanAddComparisionOperation);
            Assert.IsTrue(wfsFilter.CanUndo);


            var observationCountGreaterThanOperation = new BinaryComparisionOperation(
                new FieldValue("ObservationCount"),
                new ConstantValue("100"),
                WFSBinaryComparisionOperator.GreaterThan);

            wfsFilter.AddLogicalOperation(WFSLogicalOperator.And, observationCountGreaterThanOperation);
            Assert.AreEqual("('TaxonId' = 4000107 And 'ObservationCount' > 100)", wfsFilter.FormulaRepresentation());
            Assert.IsTrue(wfsFilter.CanAddLogicalOperation);
            Assert.IsFalse(wfsFilter.CanAddComparisionOperation);
            Assert.IsTrue(wfsFilter.CanUndo);

            wfsFilter.AddUnaryLogicalOperation(WFSUnaryLogicalOperator.Not);
            Assert.AreEqual("Not(('TaxonId' = 4000107 And 'ObservationCount' > 100))", wfsFilter.FormulaRepresentation());

            wfsFilter.Undo();
            Assert.AreEqual("('TaxonId' = 4000107 And 'ObservationCount' > 100)", wfsFilter.FormulaRepresentation());
            wfsFilter.Undo();
            Assert.AreEqual("'TaxonId' = 4000107", wfsFilter.FormulaRepresentation());
            Assert.IsTrue(wfsFilter.CanAddLogicalOperation);
            Assert.IsFalse(wfsFilter.CanAddComparisionOperation);
            Assert.IsTrue(wfsFilter.CanUndo);
            wfsFilter.Undo();
            Assert.AreEqual("", wfsFilter.FormulaRepresentation());
            Assert.IsFalse(wfsFilter.CanUndo);
            Assert.IsFalse(wfsFilter.CanAddLogicalOperation);
            Assert.IsTrue(wfsFilter.CanAddComparisionOperation);
        }
Example #2
0
        public void Test_WFS_Filters()
        {
            WFSFilter wfsFilter;
            string    strWFSRepresentation;
            string    strFormulaRepresentation;


            var equalToOperation = new BinaryComparisionOperation(
                new FieldValue("TaxonId"),
                new ConstantValue("4000107"),
                WFSBinaryComparisionOperator.EqualTo);

            wfsFilter                = new WFSFilter();
            wfsFilter.Formula        = equalToOperation;
            strWFSRepresentation     = wfsFilter.WFSRepresentation();
            strFormulaRepresentation = wfsFilter.FormulaRepresentation();
            Assert.AreEqual(
                "<Filter><PropertyIsEqualTo><PropertyName>TaxonId</PropertyName><Literal>4000107</Literal></PropertyIsEqualTo></Filter>",
                strWFSRepresentation);


            var greaterThanOperation = new BinaryComparisionOperation(
                new FieldValue("ObservationCount"),
                new ConstantValue("100"),
                WFSBinaryComparisionOperator.GreaterThan);
            var andOperation = new BinaryLogicalOperation(equalToOperation, greaterThanOperation, WFSBinaryLogicalOperator.And);

            wfsFilter                = new WFSFilter();
            wfsFilter.Formula        = andOperation;
            strWFSRepresentation     = wfsFilter.WFSRepresentation();
            strFormulaRepresentation = wfsFilter.FormulaRepresentation();
            Assert.AreEqual(
                "<Filter><And><PropertyIsEqualTo><PropertyName>TaxonId</PropertyName><Literal>4000107</Literal></PropertyIsEqualTo><PropertyIsGreaterThan><PropertyName>ObservationCount</PropertyName><Literal>100</Literal></PropertyIsGreaterThan></And></Filter>",
                strWFSRepresentation);


            var orOperation = new BinaryLogicalOperation(
                andOperation,
                new UnaryComparisionOperation(new FieldValue("Author"), WFSUnaryComparisionOperator.IsNull),
                WFSBinaryLogicalOperator.Or);

            wfsFilter                = new WFSFilter();
            wfsFilter.Formula        = orOperation;
            strWFSRepresentation     = wfsFilter.WFSRepresentation();
            strFormulaRepresentation = wfsFilter.FormulaRepresentation();
        }