Example #1
0
        public void CustomerQueryWithPreviousIterator()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket      = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };
            var iteratorID         = "123456";
            var iteratorKey        = StepQueryWithIterator <CustomerQueryRqType, CustomerQueryRsType> .IteratorKey;
            var updateCustomerMock = new Mock <StepQueryWithIterator <CustomerQueryRqType, CustomerQueryRsType> >();

            updateCustomerMock
            .Protected()
            .Setup <string>("RetrieveMessage", ItExpr.Is <string>(s => s == authenticatedTicket.Ticket), ItExpr.Is <string>(s => s == authenticatedTicket.CurrentStep), ItExpr.Is <string>(s => s == iteratorKey))
            .Returns(iteratorID);
            updateCustomerMock.CallBase = true;

            var xml = updateCustomerMock.Object.SendXML(authenticatedTicket);

            XmlDocument requestXmlDoc = new XmlDocument();

            requestXmlDoc.LoadXml(xml);

            var node = requestXmlDoc.SelectSingleNode("//CustomerQueryRq");

            Assert.IsNotNull(node);
            Assert.AreEqual("Continue", node.Attributes.GetNamedItem("iterator").Value);
            Assert.AreEqual(iteratorID, node.Attributes.GetNamedItem("iteratorID").Value);
        }
Example #2
0
        public async Task StepQueryResponseWithIterator_CustomerQueryWithResponseWithIterators()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket      = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };
            var iteratorID = "{eb05f701-e727-472f-8ade-6753c4f67a46}";
            var xml        = @"<?xml version=""1.0"" ?><QBXML><QBXMLMsgsRs><CustomerQueryRs requestID=""1"" statusCode=""0"" statusSeverity=""Info"" statusMessage=""Status OK"" iteratorRemainingCount=""18"" iteratorID=""" + iteratorID + @""">" +
                             "<CustomerRet>" +
                             "<ListID>110000-1232697602</ListID>" +
                             "<TimeCreated>2009-01-23T03:00:02-05:00</TimeCreated>" +
                             "<TimeModified>2009-01-23T03:00:02-05:00</TimeModified>" +
                             "<EditSequence>1232697602</EditSequence>" +
                             "<Name>10th Customer</Name>" +
                             "<FullName>ABC Customer</FullName>" +
                             "<IsActive>true</IsActive>" +
                             "<Sublevel>0</Sublevel>" +
                             "<Balance>0.00</Balance>" +
                             "<TotalBalance>0.00</TotalBalance>" +
                             "<JobStatus>None</JobStatus>" +
                             "</CustomerRet>" +
                             "</CustomerQueryRs></QBXMLMsgsRs></QBXML>";

            var stepQueryResponseWithIteratorMock = new Mock <StepQueryResponseWithIterator <CustomerQueryRsType> >
            {
                CallBase = true
            };

            var ret = await stepQueryResponseWithIteratorMock.Object.ReceiveXMLAsync(authenticatedTicket, xml, string.Empty, string.Empty);

            Assert.AreEqual(0, ret);
        }
        public void CustomerQueryWithResponseWithIterators()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };
            var iteratorID = "{eb05f701-e727-472f-8ade-6753c4f67a46}";
            var xml = @"<?xml version=""1.0"" ?><QBXML><QBXMLMsgsRs><CustomerQueryRs requestID=""1"" statusCode=""0"" statusSeverity=""Info"" statusMessage=""Status OK"" iteratorRemainingCount=""18"" iteratorID=""" + iteratorID + @""">" +
                "<CustomerRet>" +
                    "<ListID>110000-1232697602</ListID>" +
                    "<TimeCreated>2009-01-23T03:00:02-05:00</TimeCreated>" +
                    "<TimeModified>2009-01-23T03:00:02-05:00</TimeModified>" +
                    "<EditSequence>1232697602</EditSequence>" +
                    "<Name>10th Customer</Name>" +
                    "<FullName>ABC Customer</FullName>" +
                    "<IsActive>true</IsActive>" +
                    "<Sublevel>0</Sublevel>" +
                    "<Balance>0.00</Balance>" +
                    "<TotalBalance>0.00</TotalBalance>" +
                    "<JobStatus>None</JobStatus>" +
                "</CustomerRet>" +
                "</CustomerQueryRs></QBXMLMsgsRs></QBXML>";

            var stepQueryWithIteratorMock = new Mock<StepQueryWithIterator<CustomerQueryRqType, CustomerQueryRsType>>();
            stepQueryWithIteratorMock.CallBase = true;

            var ret = stepQueryWithIteratorMock.Object.ReceiveXML(authenticatedTicket, xml, string.Empty, string.Empty);
            Assert.AreEqual(0, ret);
        }
        public async Task GroupStepQueryResponseBaseTests_RequestedAborted()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket      = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };

            var xml = $@"<?xml version=""1.0"" ?><QBXML><QBXMLMsgsRs>{customerResponseError}{customerResponseAborted}</QBXMLMsgsRs></QBXML>";

            var groupStepQueryResponseBaseMock = new Mock <GroupStepQueryResponseBase>();

            groupStepQueryResponseBaseMock
            .Setup(m => m.ExecuteResponseAsync(It.Is <IAuthenticatedTicket>(n => n == authenticatedTicket), It.IsAny <IEnumerable <IQbResponse> >()))
            .Returns(Task.CompletedTask)
            .Callback <IAuthenticatedTicket, IEnumerable <IQbResponse> >((ticket, responses) =>
            {
                Assert.AreEqual(2, responses.Count());
                var firstResponse = responses.First();
                Assert.IsInstanceOf(typeof(CustomerAddRsType), firstResponse);
                Assert.AreEqual("3090", firstResponse.statusCode);

                var secondResponse = responses.Skip(1).First();
                Assert.IsInstanceOf(typeof(CustomerQueryRsType), secondResponse);
                Assert.AreEqual("3231", secondResponse.statusCode);
            });
            groupStepQueryResponseBaseMock.CallBase = true;

            var ret = await groupStepQueryResponseBaseMock.Object.ReceiveXMLAsync(authenticatedTicket, xml, string.Empty, string.Empty);

            Assert.AreEqual(0, ret);
        }
Example #5
0
        public void CustomerQueryWithResponseWithNoIterators()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket      = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };
            var xml = @"<?xml version=""1.0"" ?><QBXML><QBXMLMsgsRs><CustomerQueryRs requestID=""1"" statusCode=""0"" statusSeverity=""Info"" statusMessage=""Status OK"">" +
                      "<CustomerRet>" +
                      "<ListID>110000-1232697602</ListID>" +
                      "<TimeCreated>2009-01-23T03:00:02-05:00</TimeCreated>" +
                      "<TimeModified>2009-01-23T03:00:02-05:00</TimeModified>" +
                      "<EditSequence>1232697602</EditSequence>" +
                      "<Name>10th Customer</Name>" +
                      "<FullName>ABC Customer</FullName>" +
                      "<IsActive>true</IsActive>" +
                      "<Sublevel>0</Sublevel>" +
                      "<Balance>0.00</Balance>" +
                      "<TotalBalance>0.00</TotalBalance>" +
                      "<JobStatus>None</JobStatus>" +
                      "</CustomerRet>" +
                      "</CustomerQueryRs></QBXMLMsgsRs></QBXML>";

            var stepQueryWithIteratorMock = new Mock <StepQueryWithIterator <CustomerQueryRqType, CustomerQueryRsType> >();

            stepQueryWithIteratorMock.CallBase = true;

            var ret = stepQueryWithIteratorMock.Object.ReceiveXML(authenticatedTicket, xml, string.Empty, string.Empty);

            Assert.AreEqual(0, ret);
        }
        public void CustomerQueryWithPreviousIterator()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };
            var iteratorID = "123456";
            var iteratorKey = StepQueryWithIterator<CustomerQueryRqType, CustomerQueryRsType>.IteratorKey;
            var updateCustomerMock = new Mock<StepQueryWithIterator<CustomerQueryRqType, CustomerQueryRsType>>();
            updateCustomerMock
                .Protected()
                .Setup<string>("RetrieveMessage", ItExpr.Is<string>(s => s == authenticatedTicket.Ticket), ItExpr.Is<string>(s => s == authenticatedTicket.CurrentStep), ItExpr.Is<string>(s => s == iteratorKey))
                .Returns(iteratorID);
            updateCustomerMock.CallBase = true;

            var xml = updateCustomerMock.Object.SendXML(authenticatedTicket);

            XmlDocument requestXmlDoc = new XmlDocument();
            requestXmlDoc.LoadXml(xml);

            var node = requestXmlDoc.SelectSingleNode("//CustomerQueryRq");

            Assert.IsNotNull(node);
            Assert.AreEqual("Continue", node.Attributes.GetNamedItem("iterator").Value);
            Assert.AreEqual(iteratorID, node.Attributes.GetNamedItem("iteratorID").Value);
        }
        public void CustomerQueryWithIteratorNegativeMaxReturned()
        {
            const int expectedMaxResult = 100;

            var defaultMaxResult = "-1";
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };

            var stepQueryWithIteratorMock = new Mock<StepQueryWithIteratorMaxReturnedHarness>(defaultMaxResult);
            stepQueryWithIteratorMock.CallBase = true;

            var xml = stepQueryWithIteratorMock.Object.SendXML(authenticatedTicket);

            XmlDocument requestXmlDoc = new XmlDocument();
            requestXmlDoc.LoadXml(xml);

            var node = requestXmlDoc.SelectSingleNode("//CustomerQueryRq");

            Assert.IsNotNull(node);
            Assert.AreEqual("Start", node.Attributes.GetNamedItem("iterator").Value);
            Assert.IsNotNull(node.SelectSingleNode("MaxReturned"));
            Assert.AreEqual(expectedMaxResult.ToString(), node.SelectSingleNode("MaxReturned").InnerText);
        }
Example #8
0
        public async Task CustomerQueryWithIteratorInvalidMaxReturned()
        {
            const int expectedMaxResult = 100;

            var defaultMaxResult    = "INVALID_MAX_RETURN_VALUE";
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket      = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };

            var stepQueryWithIteratorMock = new Mock <StepQueryWithIteratorMaxReturnedHarness>(defaultMaxResult);

            stepQueryWithIteratorMock.CallBase = true;

            var xml = await stepQueryWithIteratorMock.Object.SendXMLAsync(authenticatedTicket);

            XmlDocument requestXmlDoc = new XmlDocument();

            requestXmlDoc.LoadXml(xml);

            var node = requestXmlDoc.SelectSingleNode("//CustomerQueryRq");

            Assert.IsNotNull(node);
            Assert.AreEqual("Start", node.Attributes.GetNamedItem("iterator").Value);
            Assert.IsNotNull(node.SelectSingleNode("MaxReturned"));
            Assert.AreEqual(expectedMaxResult.ToString(), node.SelectSingleNode("MaxReturned").InnerText);
        }
        protected override CustomerQueryRqType CreateRequest(AuthenticatedTicket authenticatedTicket)
        {
            CustomerQueryRqType req = base.CreateRequest(authenticatedTicket);

            req.MaxReturned = this.DefaultMaxReturned;
            return(req);
        }
Example #10
0
        public async Task CustomerQueryWithNoInitialMessage()
        {
            var defaultMaxResult    = 100;
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket      = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };

            var stepQueryWithIteratorMock = new Mock <StepQueryWithIterator <CustomerQueryRqType, CustomerQueryRsType> >();

            stepQueryWithIteratorMock.CallBase = true;

            var xml = await stepQueryWithIteratorMock.Object.SendXMLAsync(authenticatedTicket);

            XmlDocument requestXmlDoc = new XmlDocument();

            requestXmlDoc.LoadXml(xml);

            var node = requestXmlDoc.SelectSingleNode("//CustomerQueryRq");

            Assert.IsNotNull(node);
            Assert.AreEqual("Start", node.Attributes.GetNamedItem("iterator").Value);
            Assert.IsNotNull(node.SelectSingleNode("MaxReturned"));
            Assert.AreEqual(defaultMaxResult.ToString(), node.SelectSingleNode("MaxReturned").InnerText);
        }
Example #11
0
        public void CustomerQueryWithIteratorValidMaxReturned()
        {
            string defaultMaxResult    = "500";
            var    authenticatedTicket = new AuthenticatedTicket
            {
                Ticket      = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };

            var stepQueryWithIteratorMock = new Mock <StepQueryWithIteratorMaxReturnedHarness>(defaultMaxResult);

            stepQueryWithIteratorMock.CallBase = true;

            var xml = stepQueryWithIteratorMock.Object.SendXML(authenticatedTicket);

            XmlDocument requestXmlDoc = new XmlDocument();

            requestXmlDoc.LoadXml(xml);

            var node = requestXmlDoc.SelectSingleNode("//CustomerQueryRq");

            Assert.IsNotNull(node);
            Assert.AreEqual("Start", node.Attributes.GetNamedItem("iterator").Value);
            Assert.IsNotNull(node.SelectSingleNode("MaxReturned"));
            Assert.AreEqual(defaultMaxResult.ToString(), node.SelectSingleNode("MaxReturned").InnerText);
        }
 public SetupValidTicketAttribute()
 {
     AuthenticatedTicket = new AuthenticatedTicket
     {
         Authenticated = true,
         Ticket        = Guid.NewGuid().ToString()
     };
 }
 public SetupWrongCredentialTicketAttribute()
 {
     AuthenticatedTicket = new AuthenticatedTicket
     {
         Authenticated = false,
         Ticket        = Guid.NewGuid().ToString()
     };
 }
 public SetupValidTicketAttribute()
 {
     AuthenticatedTicket = new AuthenticatedTicket
     {
         Authenticated = true,
         CurrentStep   = AuthenticatedTicket.InitialStep,
         Ticket        = Guid.NewGuid().ToString()
     };
 }
Example #15
0
        public async Task GroupStepQueryRequestBaseTests_WithTwoMessages()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket      = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };

            var groupStepQueryRequestMock = new Mock <GroupStepQueryRequestBase>();

            groupStepQueryRequestMock
            .Setup(m => m.ExecuteRequestAsync(It.Is <IAuthenticatedTicket>(n => n == authenticatedTicket)))
            .ReturnsAsync(() =>
            {
                return(new List <IQbRequest>
                {
                    new CustomerQueryRqType
                    {
                        ActiveStatus = ActiveStatus.ActiveOnly
                    },
                    new CustomerAddRqType
                    {
                        CustomerAdd = new CustomerAdd
                        {
                            Name = "Unique Name",
                            FirstName = "User 1"
                        }
                    }
                });
            });
            groupStepQueryRequestMock.CallBase = true;

            var xml = await groupStepQueryRequestMock.Object.SendXMLAsync(authenticatedTicket);

            XmlDocument requestXmlDoc = new XmlDocument();

            requestXmlDoc.LoadXml(xml);

            var msgRqs = requestXmlDoc.SelectNodes("//QBXMLMsgsRq");

            Assert.AreEqual(1, msgRqs.Count);

            var msgRq = msgRqs.Item(0);

            Assert.AreEqual("continueOnError", msgRq.Attributes.GetNamedItem("onError").Value);
            var requestNodes = msgRq.SelectNodes("*");

            Assert.AreEqual(2, requestNodes.Count);

            var node1 = requestNodes.Item(0);
            var node2 = requestNodes.Item(1);

            Assert.AreEqual("CustomerQueryRq", node1.Name);
            Assert.AreEqual("CustomerAddRq", node2.Name);
        }
        protected override async Task ExecuteResponseAsync(AuthenticatedTicket authenticatedTicket, Y response)
        {
            // We have more that can come our way.
            if (response.iteratorRemainingCount.HasValue && response.iteratorRemainingCount.Value > 0)
            {
                gotoNextStep = false;
                await SaveMessageAsync(authenticatedTicket, IteratorKey, response.iteratorID);
            }

            await base.ExecuteResponseAsync(authenticatedTicket, response);
        }
        protected override void ExecuteResponse(AuthenticatedTicket authenticatedTicket, Y response)
        {
            // We have more that can come our way.
            if (response.iteratorRemainingCount.HasValue && response.iteratorRemainingCount.Value > 0)
            {
                gotoNextStep = false;
                SaveMessage(authenticatedTicket.Ticket, authenticatedTicket.CurrentStep, IteratorKey, response.iteratorID);
            }

            base.ExecuteResponse(authenticatedTicket, response);
        }
Example #18
0
        public virtual int ReceiveXML(AuthenticatedTicket authenticatedTicket, string response, string hresult, string message)
        {
            var responseObject = new QbXmlResponse(qbXmlResponseOptions);

            if (!string.IsNullOrEmpty(response))
            {
                var msgResponseObject = responseObject.GetSingleItemFromResponse(response, typeof(Y)) as Y;
                ExecuteResponse(authenticatedTicket, msgResponseObject);

                return(0);
            }

            return(-1);
        }
Example #19
0
        protected override bool ExecuteRequest(AuthenticatedTicket authenticatedTicket, T request)
        {
            var savedMessage = RetrieveMessage(authenticatedTicket.Ticket, authenticatedTicket.CurrentStep, IteratorKey);

            request.iterator = IteratorType.Start;
            if (!string.IsNullOrEmpty(savedMessage))
            {
                request.iterator   = IteratorType.Continue;
                request.iteratorID = savedMessage;
            }

            request.MaxReturned = "100";

            return(base.ExecuteRequest(authenticatedTicket, request));
        }
Example #20
0
        public async Task GroupStepQueryRequestBaseTests_WithNoMessage()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket      = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };

            var groupStepQueryRequestMock = new Mock <GroupStepQueryRequestBase>();

            groupStepQueryRequestMock.CallBase = true;

            var xml = await groupStepQueryRequestMock.Object.SendXMLAsync(authenticatedTicket);

            Assert.IsNull(xml);
        }
Example #21
0
        public virtual string SendXML(AuthenticatedTicket authenticatedTicket)
        {
            var requestObject = CreateRequest(authenticatedTicket);

            if (requestObject != null)
            {
                if (ExecuteRequest(authenticatedTicket, requestObject))
                {
                    var qbXmlRequest = new QbXmlRequest();
                    qbXmlRequest.AddToSingle(requestObject);

                    return(qbXmlRequest.GetRequest());
                }
            }

            return(null);
        }
Example #22
0
        public async Task CustomerQueryWithTimeZoneFix()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket      = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };
            var xml = @"<?xml version=""1.0"" ?><QBXML><QBXMLMsgsRs><CustomerQueryRs requestID=""1"" statusCode=""0"" statusSeverity=""Info"" statusMessage=""Status OK"">" +
                      "<CustomerRet>" +
                      "<ListID>110000-1232697602</ListID>" +
                      "<TimeCreated>2015-04-03T10:06:17-08:00</TimeCreated>" +
                      "<TimeModified>2015-04-03T10:06:17-08:00</TimeModified>" +
                      "<EditSequence>1232697602</EditSequence>" +
                      "<Name>10th Customer</Name>" +
                      "<FullName>ABC Customer</FullName>" +
                      "<IsActive>true</IsActive>" +
                      "<Sublevel>0</Sublevel>" +
                      "<Balance>0.00</Balance>" +
                      "<TotalBalance>0.00</TotalBalance>" +
                      "<JobStatus>None</JobStatus>" +
                      "</CustomerRet>" +
                      "</CustomerQueryRs></QBXMLMsgsRs></QBXML>";

            var qbXmlResponseOptions = new QbXmlResponseOptions
            {
                TimeZoneBugFix = QuickBooksTestHelper.GetPacificStandardTimeZoneInfo()
            };

            var stepQueryWithIteratorMock = new Mock <StepQueryResponseBase <CustomerQueryRqType, CustomerQueryRsType> >();

            stepQueryWithIteratorMock
            .Protected()
            .Setup <Task>("ExecuteResponseAsync", ItExpr.IsAny <AuthenticatedTicket>(), ItExpr.IsAny <CustomerQueryRsType>())
            .Returns(Task.FromResult <object>(null));
            stepQueryWithIteratorMock.CallBase = true;
            await stepQueryWithIteratorMock.Object.SetOptionsAsync(qbXmlResponseOptions);

            var ret = await stepQueryWithIteratorMock.Object.ReceiveXMLAsync(authenticatedTicket, xml, string.Empty, string.Empty);

            Assert.AreEqual(0, ret);
            var expectedHour = 17;

            stepQueryWithIteratorMock
            .Protected()
            .Verify("ExecuteResponseAsync", Times.Once(), ItExpr.IsAny <AuthenticatedTicket>(), ItExpr.Is <CustomerQueryRsType>(m => m.CustomerRet[0].TimeModified.ToDateTime().ToUniversalTime().Hour == expectedHour));
        }
        public virtual async Task <string> SendXMLAsync(AuthenticatedTicket authenticatedTicket)
        {
            var requestObject = await CreateRequestAsync(authenticatedTicket);

            if (requestObject != null)
            {
                if (await ExecuteRequestAsync(authenticatedTicket, requestObject))
                {
                    var qbXmlRequest = new QbXmlRequest();
                    qbXmlRequest.AddToSingle(requestObject);

                    return(qbXmlRequest.GetRequest());
                }
            }

            return(null);
        }
Example #24
0
        public void CustomerQueryWithShortCircuitExecuteRequest()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket      = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };
            var updateCustomerMock = new Mock <StepQueryWithIterator <CustomerQueryRqType, CustomerQueryRsType> >();

            updateCustomerMock
            .Protected()
            .Setup <bool>("ExecuteRequest", ItExpr.IsAny <AuthenticatedTicket>(), ItExpr.IsAny <CustomerQueryRqType>())
            .Returns(false);
            updateCustomerMock.CallBase = true;

            var xml = updateCustomerMock.Object.SendXML(authenticatedTicket);

            Assert.IsNull(xml);
        }
        public async Task StepQueryRequestWithIterator_CustomerQueryWithShortCircuitExecuteRequest()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket      = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };
            var updateCustomerMock = new Mock <StepQueryRequestWithIterator <CustomerQueryRqType> >();

            updateCustomerMock
            .Protected()
            .Setup <Task <bool> >("ExecuteRequestAsync", ItExpr.IsAny <AuthenticatedTicket>(), ItExpr.IsAny <CustomerQueryRqType>())
            .Returns(Task.FromResult(false));
            updateCustomerMock.CallBase = true;

            var xml = await updateCustomerMock.Object.SendXMLAsync(authenticatedTicket);

            Assert.IsNull(xml);
        }
Example #26
0
        public async Task GroupStepQueryRequestBaseTests_WithDifferentOnError()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket      = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };

            var groupStepQueryRequestMock = new Mock <GroupStepQueryRequestBase>();

            groupStepQueryRequestMock
            .Setup(m => m.ExecuteRequestAsync(It.Is <IAuthenticatedTicket>(n => n == authenticatedTicket)))
            .ReturnsAsync(() =>
            {
                return(new List <IQbRequest>
                {
                    new CustomerQueryRqType
                    {
                        ActiveStatus = ActiveStatus.ActiveOnly
                    }
                });
            });
            groupStepQueryRequestMock
            .Setup(m => m.GetOnErrorAttributeAsync(It.Is <IAuthenticatedTicket>(n => n == authenticatedTicket)))
            .ReturnsAsync(() =>
            {
                return(QBXMLMsgsRqOnError.stopOnError);
            });
            groupStepQueryRequestMock.CallBase = true;

            var xml = await groupStepQueryRequestMock.Object.SendXMLAsync(authenticatedTicket);

            XmlDocument requestXmlDoc = new XmlDocument();

            requestXmlDoc.LoadXml(xml);

            var msgRqs = requestXmlDoc.SelectNodes("//QBXMLMsgsRq");

            var msgRq = msgRqs.Item(0);

            Assert.AreEqual("stopOnError", msgRq.Attributes.GetNamedItem("onError").Value);
        }
        protected override bool ExecuteRequest(AuthenticatedTicket authenticatedTicket, T request)
        {
            var savedMessage = RetrieveMessage(authenticatedTicket.Ticket, authenticatedTicket.CurrentStep, IteratorKey);

            request.iterator = IteratorType.Start;
            if (!string.IsNullOrEmpty(savedMessage))
            {
                request.iterator   = IteratorType.Continue;
                request.iteratorID = savedMessage;
            }

            int  maxVal;
            bool isValid = int.TryParse(request.MaxReturned, out maxVal);

            if (!isValid || (isValid && (maxVal < 1)))
            {
                // Not a valid max returned value. Set to 100 by default.
                request.MaxReturned = MaxReturnedDefault;
            }

            return(base.ExecuteRequest(authenticatedTicket, request));
        }
Example #28
0
 /// <summary>
 /// Processes the response sent for the first time by the WebConnector.
 /// </summary>
 /// <param name="authenticatedTicket">The ticket.</param>
 /// <param name="response">First Message.</param>
 protected virtual Task ProcessClientInformationAsync(AuthenticatedTicket authenticatedTicket, string response)
 {
     return(Task.FromResult <object>(null));
 }
        public void CustomerQueryWithTimeZoneNoFix()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };
            var xml = @"<?xml version=""1.0"" ?><QBXML><QBXMLMsgsRs><CustomerQueryRs requestID=""1"" statusCode=""0"" statusSeverity=""Info"" statusMessage=""Status OK"">" +
                "<CustomerRet>" +
                    "<ListID>110000-1232697602</ListID>" +
                    "<TimeCreated>2015-04-03T10:06:17-08:00</TimeCreated>" +
                    "<TimeModified>2015-04-03T10:06:17-08:00</TimeModified>" +
                    "<EditSequence>1232697602</EditSequence>" +
                    "<Name>10th Customer</Name>" +
                    "<FullName>ABC Customer</FullName>" +
                    "<IsActive>true</IsActive>" +
                    "<Sublevel>0</Sublevel>" +
                    "<Balance>0.00</Balance>" +
                    "<TotalBalance>0.00</TotalBalance>" +
                    "<JobStatus>None</JobStatus>" +
                "</CustomerRet>" +
                "</CustomerQueryRs></QBXMLMsgsRs></QBXML>";

            var qbXmlResponseOptions = new QbXmlResponseOptions
            {
            };

            var stepQueryWithIteratorMock = new Mock<StepQueryResponseBase<CustomerQueryRqType, CustomerQueryRsType>>();
            stepQueryWithIteratorMock
                .Protected()
                .Setup("ExecuteResponse", ItExpr.IsAny<AuthenticatedTicket>(), ItExpr.IsAny<CustomerQueryRsType>());
            stepQueryWithIteratorMock.CallBase = true;
            stepQueryWithIteratorMock.Object.SetOptions(qbXmlResponseOptions);

            var ret = stepQueryWithIteratorMock.Object.ReceiveXML(authenticatedTicket, xml, string.Empty, string.Empty);
            Assert.AreEqual(0, ret);
            var expectedHour = 18;
            stepQueryWithIteratorMock
                .Protected()
                .Verify("ExecuteResponse", Times.Once(), ItExpr.IsAny<AuthenticatedTicket>(), ItExpr.Is<CustomerQueryRsType>(m => m.CustomerRet[0].TimeModified.ToDateTime().ToUniversalTime().Hour == expectedHour));
        }
        public void CustomerQueryWithShortCircuitExecuteRequest()
        {
            var authenticatedTicket = new AuthenticatedTicket
            {
                Ticket = Guid.NewGuid().ToString(),
                CurrentStep = "step4"
            };
            var updateCustomerMock = new Mock<StepQueryWithIterator<CustomerQueryRqType, CustomerQueryRsType>>();
            updateCustomerMock
                .Protected()
                .Setup<bool>("ExecuteRequest", ItExpr.IsAny<AuthenticatedTicket>(), ItExpr.IsAny<CustomerQueryRqType>())
                .Returns(false);
            updateCustomerMock.CallBase = true;

            var xml = updateCustomerMock.Object.SendXML(authenticatedTicket);

            Assert.IsNull(xml);
        }
Example #31
0
 /// <summary>
 /// Logs messages to a database.
 /// </summary>
 /// <param name="authenticatedTicket">The ticket which has the ticket string. The ticket could also be not authenticated if an error happened.</param>
 /// <param name="messageType">Type of message.</param>
 /// <param name="direction">Direction of the message (In the WebService, or Out the WebService).</param>
 /// <param name="arguments">Other arguments to save.</param>
 protected internal virtual Task LogMessageAsync(AuthenticatedTicket authenticatedTicket, LogMessageType messageType, LogDirection direction, string ticket, params string[] arguments)
 {
     return(Task.FromResult <object>(null));
 }
Example #32
0
 /// <summary>
 /// Gets the options for the SyncManager.
 /// </summary>
 /// <param name="authenticatedTicket">The ticket.</param>
 /// <returns>Options.</returns>
 protected internal virtual Task <QbXmlResponseOptions> GetOptionsAsync(AuthenticatedTicket authenticatedTicket)
 {
     return(Task.FromResult <QbXmlResponseOptions>(null));
 }
 protected override async Task<CustomerQueryRqType> CreateRequestAsync(AuthenticatedTicket authenticatedTicket)
 {
     CustomerQueryRqType req = await base.CreateRequestAsync(authenticatedTicket);
     req.MaxReturned = this.DefaultMaxReturned;
     return req;
 }
Example #34
0
 protected abstract string RetrieveMessage(AuthenticatedTicket ticket, string key);
Example #35
0
 protected abstract void SaveMessage(AuthenticatedTicket ticket, string key, string value);