Beispiel #1
0
        public void AddFilterTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>" +
                              "<and>" +
                              "<greaterthanorequalto>" +
                              "<field>RECORDNO</field>" +
                              "<value>1</value>" +
                              "</greaterthanorequalto>" +
                              "<lessthanorequalto>" +
                              "<field>RECORDNO</field>" +
                              "<value>100</value>" +
                              "</lessthanorequalto>" +
                              "</and>";

            Stream            stream      = new MemoryStream();
            XmlWriterSettings xmlSettings = new XmlWriterSettings
            {
                Encoding = Encoding.GetEncoding("UTF-8")
            };

            IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings);

            AndOperator andFilter = new AndOperator(null);

            andFilter.AddFilter((new Filter("RECORDNO")).SetGreaterThanOrEqualTo("1"));
            andFilter.AddFilter((new Filter("RECORDNO")).SetLessThanOrEqualTo("100"));
            andFilter.WriteXml(ref xml);

            xml.Flush();

            stream.Position = 0;
            StreamReader reader = new StreamReader(stream);

            Assert.Equal(expected, reader.ReadToEnd());
        }
Beispiel #2
0
        public void FilterOrWithAndConditionTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <query>
        <select>
            <field>BATCHNO</field>
            <field>RECORDNO</field>
            <field>STATE</field>
        </select>
        <object>GLBATCH</object>
        <filter>
            <or>
                <equalto>
                    <field>JOURNAL</field>
                    <value>APJ</value>
                </equalto>
                <and>
                    <greaterthanorequalto>
                        <field>BATCHNO</field>
                        <value>1</value>
                    </greaterthanorequalto>
                    <equalto>
                        <field>STATE</field>
                        <value>Posted</value>
                    </equalto>
                </and>
            </or>
        </filter>
        <options />
    </query>
</function>";

            SelectBuilder builder = new SelectBuilder();

            ISelect[] fields = builder.Fields(new[] { "BATCHNO", "RECORDNO", "STATE" }).GetFields();

            AndOperator batchnoAndState = new AndOperator(new List <IFilter>());

            batchnoAndState.AddFilter((new Filter("BATCHNO")).SetGreaterThanOrEqualTo("1"));
            batchnoAndState.AddFilter((new Filter("STATE")).SetEqualTo("Posted"));

            IFilter journal = new Filter("JOURNAL").SetEqualTo("APJ");

            IFilter filter = new OrOperator(new List <IFilter>()
            {
                journal, batchnoAndState
            });

            IQueryFunction query = new QueryFunction("unittest")
            {
                FromObject   = "GLBATCH",
                SelectFields = fields,
                Filter       = filter
            };

            this.CompareXml(expected, query);
        }
Beispiel #3
0
        public void FilterAndConditionTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <query>
        <select>
            <field>CUSTOMERID</field>
            <field>RECORDNO</field>
        </select>
        <object>ARINVOICE</object>
        <filter>
            <and>
                <greaterthanorequalto>
                    <field>RECORDNO</field>
                    <value>1</value>
                </greaterthanorequalto>
                <lessthanorequalto>
                    <field>RECORDNO</field>
                    <value>100</value>
                </lessthanorequalto>
            </and>
        </filter>
        <options />
    </query>
</function>";

            SelectBuilder builder = new SelectBuilder();

            ISelect[] fields = builder.Fields(new[] { "CUSTOMERID", "RECORDNO" }).GetFields();

            AndOperator filter = new AndOperator(new List <IFilter>());

            filter.AddFilter((new Filter("RECORDNO")).SetGreaterThanOrEqualTo("1"));
            filter.AddFilter((new Filter("RECORDNO")).SetLessThanOrEqualTo("100"));

            IQueryFunction query = new QueryFunction("unittest")
            {
                FromObject   = "ARINVOICE",
                SelectFields = fields,
                Filter       = filter
            };

            this.CompareXml(expected, query);
        }
Beispiel #4
0
        public void AddNullFilterTest()
        {
            Stream            stream      = new MemoryStream();
            XmlWriterSettings xmlSettings = new XmlWriterSettings
            {
                Encoding = Encoding.GetEncoding("UTF-8")
            };

            IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings);

            AndOperator andFilter = new AndOperator(null);

            andFilter.AddFilter(null);

            var ex = Record.Exception(() => andFilter.WriteXml(ref xml));

            Assert.IsType <IntacctException>(ex);
            Assert.Equal("Two or more IFilter objects required for and", ex.Message);
        }
Beispiel #5
0
        public void ThreeLevelFilterTest()
        {
            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<function controlid=""unittest"">
    <query>
        <select>
            <field>BATCHNO</field>
            <field>RECORDNO</field>
            <field>STATE</field>
        </select>
        <object>GLBATCH</object>
        <filter>
            <or>
                <and>
                    <equalto>
                        <field>JOURNAL</field>
                        <value>APJ</value>
                    </equalto>
                    <equalto>
                        <field>STATE</field>
                        <value>Posted</value>
                    </equalto>
                </and>
                <and>
                    <equalto>
                        <field>JOURNAL</field>
                        <value>RCPT</value>
                    </equalto>
                    <equalto>
                        <field>STATE</field>
                        <value>Posted</value>
                    </equalto>
                    <or>
                        <equalto>
                            <field>RECORDNO</field>
                            <value>168</value>
                        </equalto>
                        <equalto>
                            <field>RECORDNO</field>
                            <value>132</value>
                        </equalto>
                    </or>
                </and>
            </or>
        </filter>
        <options />
    </query>
</function>";

            SelectBuilder builder = new SelectBuilder();

            ISelect[] fields = builder.Fields(new[] { "BATCHNO", "RECORDNO", "STATE" }).GetFields();

            AndOperator apjAndState = new AndOperator(new List <IFilter>());

            apjAndState.AddFilter((new Filter("JOURNAL")).SetEqualTo("APJ"));
            apjAndState.AddFilter((new Filter("STATE")).SetEqualTo("Posted"));

            OrOperator recordnoOr = new OrOperator(new List <IFilter>());

            recordnoOr.AddFilter((new Filter("RECORDNO")).SetEqualTo("168"));
            recordnoOr.AddFilter((new Filter("RECORDNO")).SetEqualTo("132"));

            AndOperator rcptAndState = new AndOperator(new List <IFilter>());

            rcptAndState.AddFilter((new Filter("JOURNAL")).SetEqualTo("RCPT"));
            rcptAndState.AddFilter((new Filter("STATE")).SetEqualTo("Posted"));
            rcptAndState.AddFilter(recordnoOr);

            IFilter filter = new OrOperator(new List <IFilter>()
            {
                apjAndState, rcptAndState
            });

            IFunction query = new QueryFunction("unittest")
            {
                FromObject   = "GLBATCH",
                SelectFields = fields,
                Filter       = filter
            };

            this.CompareXml(expected, query);
        }