public void CustomerQueryRequest_FilterByNameRange_Test() { var request = new QbXmlRequest(); var innerRequest = new CustomerQueryRqType { NameRangeFilter = new NameRangeFilter { FromName = "ab", ToName = "ac" } }; request.AddToSingle(innerRequest); var xml = request.GetRequest(); XmlDocument requestXmlDoc = new XmlDocument(); requestXmlDoc.LoadXml(xml); var nameRangeFilter = requestXmlDoc.GetElementsByTagName("NameRangeFilter"); Assert.AreEqual(1, nameRangeFilter.Count); Assert.AreEqual(innerRequest.NameRangeFilter.FromName, nameRangeFilter.Item(0).ReadNode("./FromName")); Assert.AreEqual(innerRequest.NameRangeFilter.ToName, nameRangeFilter.Item(0).ReadNode("./ToName")); Assert.IsEmpty(QuickBooksTestHelper.GetXmlValidation(xml)); }
public void BasicCustomerWhenCallingMaxReturnedMultipleTimes() { var request = new QbXmlRequest(); var innerRequest = new CustomerQueryRqType(); innerRequest.MaxReturned = "100"; innerRequest.MaxReturned = "200"; request.AddToSingle(innerRequest); var xml = request.GetRequest(); XmlDocument requestXmlDoc = new XmlDocument(); requestXmlDoc.LoadXml(xml); Assert.AreEqual(1, requestXmlDoc.GetElementsByTagName("MaxReturned").Count); Assert.AreEqual("200", requestXmlDoc.GetElementsByTagName("MaxReturned").Item(0).InnerText); Assert.IsEmpty(QuickBooksTestHelper.GetXmlValidation(xml)); }
public void BasicCustomerQueryRequestWithAccentTest() { var request = new QbXmlRequest(); var innerRequest = new CustomerQueryRqType(); innerRequest.NameFilter = new NameFilter { MatchCriterion = MatchCriterion.Contains, Name = "Jean-Sébastien Goupil" }; request.AddToSingle(innerRequest); var xml = request.GetRequest(); XmlDocument requestXmlDoc = new XmlDocument(); requestXmlDoc.LoadXml(xml); Assert.IsTrue(xml.Contains("Jean-Sébastien Goupil")); }
public void BasicCustomerQueryWithSomeFilters() { var request = new QbXmlRequest(); var innerRequest = new CustomerQueryRqType(); innerRequest.ActiveStatus = ActiveStatus.ActiveOnly; innerRequest.OwnerID = new GUIDTYPE[] { new GUIDTYPE(Guid.NewGuid()) }; innerRequest.MaxReturned = "100"; request.AddToSingle(innerRequest); var xml = request.GetRequest(); XmlDocument requestXmlDoc = new XmlDocument(); requestXmlDoc.LoadXml(xml); Assert.AreEqual(1, requestXmlDoc.GetElementsByTagName("CustomerQueryRq").Count); Assert.AreEqual(0, requestXmlDoc.GetElementsByTagName("ListID").Count); Assert.AreEqual(0, requestXmlDoc.GetElementsByTagName("FullName").Count); Assert.IsEmpty(QuickBooksTestHelper.GetXmlValidation(xml)); }
public void BasicCustomerQueryRequestTest() { var request = new QbXmlRequest(); var innerRequest = new CustomerQueryRqType(); request.AddToSingle(innerRequest); var xml = request.GetRequest(); XmlDocument requestXmlDoc = new XmlDocument(); requestXmlDoc.LoadXml(xml); Assert.AreEqual(1, requestXmlDoc.GetElementsByTagName("CustomerQueryRq").Count); Assert.AreEqual(0, requestXmlDoc.GetElementsByTagName("ListID").Count); Assert.AreEqual(0, requestXmlDoc.GetElementsByTagName("FullName").Count); Assert.IsEmpty(QuickBooksTestHelper.GetXmlValidation(xml)); // Make sure we have no xmlns attribute Assert.IsTrue(!xml.Contains("xmlns"), "The XML contains XMLNS. The Web Connector will reject the request."); Assert.IsTrue(xml.Contains("<?qbxml version=\"13.0\"?>"), "Version is not not included in the XML. The Web Connector will reject the request."); }
public void CustomerQueryRequest_FilterByFullname_Test() { var list = new List <string> { "abc", "def" }; var request = new QbXmlRequest(); var innerRequest = new CustomerQueryRqType(); innerRequest.FullName = list; request.AddToSingle(innerRequest); var xml = request.GetRequest(); XmlDocument requestXmlDoc = new XmlDocument(); requestXmlDoc.LoadXml(xml); Assert.AreEqual(innerRequest.FullName.Count(), requestXmlDoc.GetElementsByTagName("FullName").Count); Assert.AreEqual(list[0], requestXmlDoc.GetElementsByTagName("FullName").Item(0).InnerText); Assert.AreEqual(list[1], requestXmlDoc.GetElementsByTagName("FullName").Item(1).InnerText); Assert.IsEmpty(QuickBooksTestHelper.GetXmlValidation(xml)); }
public void CustomerQueryRequest_FilterByListId_Test() { var list = new List <string> { "1234", "3456" }; var request = new QbXmlRequest(); var innerRequest = new CustomerQueryRqType { ListID = list }; request.AddToSingle(innerRequest); var xml = request.GetRequest(); XmlDocument requestXmlDoc = new XmlDocument(); requestXmlDoc.LoadXml(xml); Assert.AreEqual(innerRequest.ListID.Count(), requestXmlDoc.GetElementsByTagName("ListID").Count); Assert.AreEqual(list[0], requestXmlDoc.GetElementsByTagName("ListID").Item(0).InnerText); Assert.AreEqual(list[1], requestXmlDoc.GetElementsByTagName("ListID").Item(1).InnerText); Assert.IsEmpty(QuickBooksTestHelper.GetXmlValidation(xml)); }
public void CustomerQueryRequest_FilterByFullname_Test() { var list = new List<string> { "abc", "def" }; var request = new QbXmlRequest(); var innerRequest = new CustomerQueryRqType(); innerRequest.FullName = list; request.AddToSingle(innerRequest); var xml = request.GetRequest(); XmlDocument requestXmlDoc = new XmlDocument(); requestXmlDoc.LoadXml(xml); Assert.AreEqual(innerRequest.FullName.Count(), requestXmlDoc.GetElementsByTagName("FullName").Count); Assert.AreEqual(list[0], requestXmlDoc.GetElementsByTagName("FullName").Item(0).InnerText); Assert.AreEqual(list[1], requestXmlDoc.GetElementsByTagName("FullName").Item(1).InnerText); Assert.IsEmpty(QuickBooksTestHelper.GetXmlValidation(xml)); }
public void CustomerQueryRequest_FilterByNameRange_Test() { var request = new QbXmlRequest(); var innerRequest = new CustomerQueryRqType(); innerRequest.NameRangeFilter = new NameRangeFilter { FromName = "ab", ToName = "ac" }; request.AddToSingle(innerRequest); var xml = request.GetRequest(); XmlDocument requestXmlDoc = new XmlDocument(); requestXmlDoc.LoadXml(xml); var nameRangeFilter = requestXmlDoc.GetElementsByTagName("NameRangeFilter"); Assert.AreEqual(1, nameRangeFilter.Count); Assert.AreEqual(innerRequest.NameRangeFilter.FromName, nameRangeFilter.Item(0).ReadNode("./FromName")); Assert.AreEqual(innerRequest.NameRangeFilter.ToName, nameRangeFilter.Item(0).ReadNode("./ToName")); Assert.IsEmpty(QuickBooksTestHelper.GetXmlValidation(xml)); }
private void TransferJobs(XmlSerializer serializer, XmlSerializerNamespaces ns, QBXML qbxml, QBXMLMsgsRq qbMsgsRq) { MemoryStream ms; StreamReader sr; string xmlRequest; var custrq = new CustomerQueryRqType(); custrq.requestID = "1"; qbMsgsRq.Items = new object[1] { custrq }; qbxml.Items[0] = qbMsgsRq; ms = new MemoryStream(); serializer.Serialize(ms, qbxml, ns); ms.Seek(0, SeekOrigin.Begin); sr = new StreamReader(ms); xmlRequest = sr.ReadToEnd(); xmlRequest = xmlRequest.Replace("<?xml version=\"1.0\"?>", "<?xml version=\"1.0\"?><?qbxml version=\"4.0\"?>"); if (DEBUGMODE) { File.WriteAllText("c:\\QB\\CustQBXML.xml", xmlRequest); } _Response = _Rp.ProcessRequest(_Ticket, xmlRequest); if (DEBUGMODE) { File.WriteAllText("c:\\QB\\Customers.xml", _Response); } QBXML rsXML = GetQbxml(serializer); if (rsXML?.Items?[0] is QBXMLMsgsRs) { QBXMLMsgsRs msgsrs = (QBXMLMsgsRs)rsXML.Items[0]; if (msgsrs?.Items?[0] is CustomerQueryRsType) { CustomerQueryRsType rs = (CustomerQueryRsType)msgsrs.Items[0]; if (rs.statusCode != "0") { MessageBox.Show(rs.statusMessage); } else { for (int i = 0; i < rs.CustomerRet.Length; i++) { CustomerRet cr = rs.CustomerRet[i]; if (cr.Sublevel == "0") { continue; //don't process the top level customers; we only want the job records } Match m = _JobRegEx.Match(cr?.FullName); if (!m.Success) { continue; //this isn't a job number we can use } string qbJobID = m.Groups[1].Value; string qbJobName = m.Groups[2].Value; using (ApexDataDataContext dc = new ApexDataDataContext(_SqlConnBuilder.ConnectionString)) { Job job = null; QBJob qbjob; qbjob = dc.QBJobs.Where(s => s.ApexCompany == _ApexTargetCompany && s.ApexJobID == qbJobID && s.QBListID != cr.ListID) .FirstOrDefault(); if (qbjob != null) { MessageBox.Show($"Job {qbJobID} from {qbJobName} has already been assigned to {qbjob.QBJobName} and cannot be transferred.", "Duplicate job"); continue; } qbjob = dc.QBJobs.Where(s => s.ApexCompany == _ApexTargetCompany && s.QBListID == cr.ListID).SingleOrDefault(); if (qbjob != null) { if (qbjob.ApexJobID != qbJobID.PadLeft(12)) //we need to delete and treat as new { dc.QBJobs.DeleteOnSubmit(qbjob); QBJob qbjob2 = new QBJob(); qbjob2.QBListID = cr?.ListID; qbjob2.QBJobName = cr?.FullName; qbjob2.ApexJobID = qbJobID.PadLeft(12); qbjob2.ApexCompany = _ApexTargetCompany; dc.QBJobs.InsertOnSubmit(qbjob2); } else { qbjob.QBJobName = cr?.FullName; } } else { qbjob = new QBJob(); qbjob.QBListID = cr?.ListID; qbjob.QBJobName = cr?.FullName; qbjob.ApexJobID = qbJobID.PadLeft(12); qbjob.ApexCompany = _ApexTargetCompany; dc.QBJobs.InsertOnSubmit(qbjob); } job = dc.Jobs.Where(s => s.Job1 == qbjob.ApexJobID.PadLeft(12)).SingleOrDefault(); if (job != null) { SetJobFields(cr, qbJobName, job); } else { job = new Job(); //Start the new Apex job job.Job1 = qbJobID.PadLeft(12); job.Act = "A"; job.Schedule = "STD"; job.TaxDefault = "Y"; job.TaxRate = 0; job.POMsg = String.Empty; SetJobFields(cr, qbJobName, job); dc.Jobs.InsertOnSubmit(job); } dc.SubmitChanges(); } } } } } }