public void FilterOrConditionTest() { 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> <or> <lessthanorequalto> <field>RECORDNO</field> <value>10</value> </lessthanorequalto> <equalto> <field>RECORDNO</field> <value>100</value> </equalto> <equalto> <field>RECORDNO</field> <value>1000</value> </equalto> <equalto> <field>RECORDNO</field> <value>10000</value> </equalto> </or> </filter> <options /> </query> </function>"; SelectBuilder builder = new SelectBuilder(); ISelect[] fields = builder.Fields(new[] { "CUSTOMERID", "RECORDNO" }).GetFields(); OrOperator filter = new OrOperator(new List <IFilter>()); filter.AddFilter((new Filter("RECORDNO")).SetLessThanOrEqualTo("10")); filter.AddFilter((new Filter("RECORDNO")).SetEqualTo("100")); filter.AddFilter((new Filter("RECORDNO")).SetEqualTo("1000")); filter.AddFilter((new Filter("RECORDNO")).SetEqualTo("10000")); IQueryFunction query = new QueryFunction("unittest") { FromObject = "ARINVOICE", SelectFields = fields, Filter = filter }; this.CompareXml(expected, query); }
public void AddFilterTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>" + "<or>" + "<lessthanorequalto>" + "<field>RECORDNO</field>" + "<value>1</value>" + "</lessthanorequalto>" + "<equalto>" + "<field>RECORDNO</field>" + "<value>100</value>" + "</equalto>" + "<equalto>" + "<field>RECORDNO</field>" + "<value>1000</value>" + "</equalto>" + "<equalto>" + "<field>RECORDNO</field>" + "<value>10000</value>" + "</equalto>" + "</or>"; Stream stream = new MemoryStream(); XmlWriterSettings xmlSettings = new XmlWriterSettings { Encoding = Encoding.GetEncoding("UTF-8") }; IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings); OrOperator orFilter = new OrOperator(null); orFilter.AddFilter((new Filter("RECORDNO")).SetLessThanOrEqualTo("1")); orFilter.AddFilter((new Filter("RECORDNO")).SetEqualTo("100")); orFilter.AddFilter((new Filter("RECORDNO")).SetEqualTo("1000")); orFilter.AddFilter((new Filter("RECORDNO")).SetEqualTo("10000")); orFilter.WriteXml(ref xml); xml.Flush(); stream.Position = 0; StreamReader reader = new StreamReader(stream); Assert.Equal(expected, reader.ReadToEnd()); }
public void AddNullFilterTest() { Stream stream = new MemoryStream(); XmlWriterSettings xmlSettings = new XmlWriterSettings { Encoding = Encoding.GetEncoding("UTF-8") }; IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings); OrOperator orFilter = new OrOperator(null); orFilter.AddFilter(null); var ex = Record.Exception(() => orFilter.WriteXml(ref xml)); Assert.IsType <IntacctException>(ex); Assert.Equal("Two or more IFilter objects required for or", ex.Message); }
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); }