/// <summary>
        /// Gets a new Intacct API session ID and endpoint URL
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        private async Task <SdkConfig> getAPISession(SdkConfig config)
        {
            Content content = new Content();

            content.Add(new ApiSessionCreate());

            RequestHandler requestHandler = new RequestHandler(config);

            SynchronousResponse response = await requestHandler.ExecuteSynchronous(config, content);

            OperationBlock operation      = response.Operation;
            Authentication authentication = operation.Authentication;
            XElement       api            = operation.Results[0].Data.Element("api");

            SdkConfig session = new SdkConfig()
            {
                SessionId             = api.Element("sessionid").Value,
                EndpointUrl           = api.Element("endpoint").Value,
                CurrentCompanyId      = authentication.CompanyId,
                CurrentUserId         = authentication.UserId,
                CurrentUserIsExternal = authentication.SlideInUser,
                Logger       = config.Logger,
                LogFormatter = config.LogFormatter,
                LogLevel     = config.LogLevel,
            };

            return(session);
        }
        public async Task MockDefaultNo524RetryTest()
        {
            HttpResponseMessage mockResponse1 = new HttpResponseMessage()
            {
                StatusCode = (HttpStatusCode)524,
            };

            List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage>
            {
                mockResponse1,
            };

            MockHandler mockHandler = new MockHandler(mockResponses);

            SdkConfig config = new SdkConfig()
            {
                SenderId       = "testsenderid",
                SenderPassword = "******",
                SessionId      = "testsession..",
                MockHandler    = mockHandler,
            };

            Content content = new Content();

            RequestBlock requestBlock = new RequestBlock(config, content);

            RequestHandler      requestHandler = new RequestHandler(config);
            SynchronousResponse response       = await requestHandler.ExecuteSynchronous(config, content);
        }
Example #3
0
        public void MissingResultBlockTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>ControlIdHere</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>fakeuser</userid>
                  <companyid>fakecompany</companyid>
                  <sessiontimestamp>2015-10-22T20:58:27-07:00</sessiontimestamp>
            </authentication>
      </operation>
</response>";

            Stream stream = new MemoryStream();
            StreamWriter streamWriter = new StreamWriter(stream);
            streamWriter.Write(xml);
            streamWriter.Flush();

            stream.Position = 0;

            SynchronousResponse response = new SynchronousResponse(stream);
        }
        public async Task ExecuteSynchronousTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>requestUnitTest</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>testuser</userid>
                  <companyid>testcompany</companyid>
                  <sessiontimestamp>2015-12-06T15:57:08-08:00</sessiontimestamp>
            </authentication>
            <result>
                  <status>success</status>
                  <function>getAPISession</function>
                  <controlid>func1UnitTest</controlid>
                  <data>
                        <api>
                              <sessionid>unittest..</sessionid>
                              <endpoint>https://unittest.intacct.com/ia/xml/xmlgw.phtml</endpoint>
                        </api>
                  </data>
            </result>
      </operation>
</response>";

            HttpResponseMessage mockResponse1 = new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent(xml)
            };

            List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage>
            {
                mockResponse1,
            };

            MockHandler mockHandler = new MockHandler(mockResponses);

            SdkConfig config = new SdkConfig
            {
                MockHandler = mockHandler,
            };

            Content content = new Content();

            content.Add(new ApiSessionCreate("func1UnitTest"));

            SynchronousResponse response = await client.Execute(content, false, "requestUnitTest", false, config);

            Assert.AreEqual("requestUnitTest", response.Control.ControlId);
        }
Example #5
0
        public void StatusNotFailuredOnAbortedTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>ControlIdHere</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>fakeuser</userid>
                  <companyid>fakecompany</companyid>
                  <sessiontimestamp>2015-10-25T10:08:34-07:00</sessiontimestamp>
            </authentication>
            <result>
                  <status>aborted</status>
                  <function>readByQuery</function>
                  <controlid>testFunctionId</controlid>
                  <errormessage>
                          <error>
                                <errorno>Query Failed</errorno>
                                <description></description>
                                <description2>Object definition VENDOR9 not found</description2>
                                <correction></correction>
                          </error>
                          <error>
                                <errorno>XL03000009</errorno>
                                <description></description>
                                <description2>The entire transaction in this operation has been rolled back due to an error.</description2>
                                <correction></correction>
                          </error>
                  </errormessage>
            </result>
      </operation>
</response>";

            Stream       stream       = new MemoryStream();
            StreamWriter streamWriter = new StreamWriter(stream);

            streamWriter.Write(xml);
            streamWriter.Flush();

            stream.Position = 0;

            SynchronousResponse response = new SynchronousResponse(stream);
            Result result = response.Operation.Results[0];

            result.EnsureStatusNotFailure();
        }
        public async Task MockDefaultRetryFailureTest()
        {
            HttpResponseMessage mockResponse1 = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.InternalServerError,
            };
            HttpResponseMessage mockResponse2 = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.NotImplemented,
            };
            HttpResponseMessage mockResponse3 = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.BadGateway,
            };
            HttpResponseMessage mockResponse4 = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.GatewayTimeout,
            };
            HttpResponseMessage mockResponse5 = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.HttpVersionNotSupported,
            };
            HttpResponseMessage mockResponse6 = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.InternalServerError,
            };

            List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage>
            {
                mockResponse1,
                mockResponse2,
                mockResponse3,
                mockResponse4,
                mockResponse5,
                mockResponse6,
            };

            MockHandler mockHandler = new MockHandler(mockResponses);

            SdkConfig config = new SdkConfig()
            {
                SenderId       = "testsenderid",
                SenderPassword = "******",
                SessionId      = "testsession..",
                MockHandler    = mockHandler,
            };

            Content content = new Content();

            RequestHandler      requestHandler = new RequestHandler(config);
            SynchronousResponse response       = await requestHandler.ExecuteSynchronous(config, content);
        }
        public void SuccessTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>ControlIdHere</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>fakeuser</userid>
                  <companyid>fakecompany</companyid>
                  <sessiontimestamp>2015-10-24T18:56:52-07:00</sessiontimestamp>
            </authentication>
            <result>
                  <status>success</status>
                  <function>getAPISession</function>
                  <controlid>testControlId</controlid>
                  <data>
                        <api>
                              <sessionid>faKEsesSiOnId..</sessionid>
                              <endpoint>https://api.intacct.com/ia/xml/xmlgw.phtml</endpoint>
                        </api>
                  </data>
            </result>
      </operation>
</response>";

            Stream       stream       = new MemoryStream();
            StreamWriter streamWriter = new StreamWriter(stream);

            streamWriter.Write(xml);
            streamWriter.Flush();

            stream.Position = 0;

            SynchronousResponse response = new SynchronousResponse(stream);
            Authentication      auth     = response.Operation.Authentication;

            Assert.AreEqual("success", auth.Status);
            Assert.AreEqual("fakeuser", auth.UserId);
            Assert.AreEqual("fakecompany", auth.CompanyId);
            Assert.AreEqual(false, auth.SlideInUser);
        }
Example #8
0
        public void GetErrorsTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>ControlIdHere</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>fakeuser</userid>
                  <companyid>fakecompany</companyid>
                  <sessiontimestamp>2015-10-25T11:07:22-07:00</sessiontimestamp>
            </authentication>
            <result>
                  <status>failure</status>
                  <function>readByQuery</function>
                  <controlid>testControlId</controlid>
                  <errormessage>
                        <error>
                              <errorno>Query Failed</errorno>
                              <description></description>
                              <description2>Object definition BADOBJECT not found</description2>
                              <correction></correction>
                        </error>
                  </errormessage>
            </result>
      </operation>
</response>";

            Stream       stream       = new MemoryStream();
            StreamWriter streamWriter = new StreamWriter(stream);

            streamWriter.Write(xml);
            streamWriter.Flush();

            stream.Position = 0;

            SynchronousResponse response = new SynchronousResponse(stream);
            var result = response.Operation.Results[0];

            Assert.AreEqual("failure", result.Status);
            Assert.IsInstanceOfType(result.Errors, typeof(List <string>));
        }
Example #9
0
        public void SuccessTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>ControlIdHere</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>fakeuser</userid>
                  <companyid>fakecompany</companyid>
                  <sessiontimestamp>2015-10-25T10:08:34-07:00</sessiontimestamp>
            </authentication>
            <result>
                  <status>success</status>
                  <function>readByQuery</function>
                  <controlid>testControlId</controlid>
                  <data listtype=""department"" count=""0"" totalcount=""0"" numremaining=""0"" resultId=""""/>
            </result>
      </operation>
</response>";

            Stream       stream       = new MemoryStream();
            StreamWriter streamWriter = new StreamWriter(stream);

            streamWriter.Write(xml);
            streamWriter.Flush();

            stream.Position = 0;

            SynchronousResponse response = new SynchronousResponse(stream);
            var result = response.Operation.Results[0];

            Assert.IsInstanceOfType(result, typeof(Result));
            Assert.AreEqual("success", result.Status);
            Assert.AreEqual("readByQuery", result.Function);
            Assert.AreEqual("testControlId", result.ControlId);
            Assert.IsInstanceOfType(result.Data, typeof(XElement));
            result.EnsureStatusSuccess();
        }
        public void GetErrorsTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>ControlIdHere</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>failure</status>
                  <userid>fakeuser</userid>
                  <companyid>fakecompany</companyid>
            </authentication>
            <errormessage>
                  <error>
                        <errorno>XL03000006</errorno>
                        <description></description>
                        <description2>Sign-in information is incorrect</description2>
                        <correction></correction>
                  </error>
            </errormessage>
      </operation>
</response>";

            Stream       stream       = new MemoryStream();
            StreamWriter streamWriter = new StreamWriter(stream);

            streamWriter.Write(xml);
            streamWriter.Flush();
            stream.Position = 0;

            try
            {
                SynchronousResponse response = new SynchronousResponse(stream);
            }
            catch (OperationException ex)
            {
                Assert.IsInstanceOfType(ex.Errors, typeof(List <string>));
            }
        }
        protected async Task <SynchronousResponse> Execute(
            Content contentBlock,
            bool transaction,
            string requestControlId,
            bool uniqueFunctionControlIds,
            SdkConfig config
            )
        {
            SdkConfig sessionConfig = SessionConfig();

            if (!String.IsNullOrWhiteSpace(sessionConfig.SenderId))
            {
                config.SenderId = sessionConfig.SenderId;
            }

            if (!String.IsNullOrWhiteSpace(sessionConfig.SenderPassword))
            {
                config.SenderPassword = sessionConfig.SenderPassword;
            }

            if (!String.IsNullOrWhiteSpace(sessionConfig.EndpointUrl))
            {
                config.EndpointUrl = sessionConfig.EndpointUrl;
            }

            if (!String.IsNullOrWhiteSpace(sessionConfig.SessionId))
            {
                config.SessionId = sessionConfig.SessionId;
            }

            config.Logger       = config.Logger != null ? config.Logger : sessionConfig.Logger;
            config.LogFormatter = config.LogFormatter != null ? config.LogFormatter : sessionConfig.LogFormatter;
            config.LogLevel     = config.LogLevel != null ? config.LogLevel : sessionConfig.LogLevel;

            config.Transaction = transaction;
            config.ControlId   = requestControlId;
            config.UniqueId    = uniqueFunctionControlIds;

            RequestHandler requestHandler = new RequestHandler(config);

            SynchronousResponse response = await requestHandler.ExecuteSynchronous(config, contentBlock);

            return(response);
        }
        public void GetOperationTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>ControlIdHere</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>fakeuser</userid>
                  <companyid>fakecompany</companyid>
                  <sessiontimestamp>2015-10-22T20:58:27-07:00</sessiontimestamp>
            </authentication>
            <result>
                  <status>success</status>
                  <function>getAPISession</function>
                  <controlid>testControlId</controlid>
                  <data>
                        <api>
                              <sessionid>fAkESesSiOnId..</sessionid>
                              <endpoint>https://api.intacct.com/ia/xml/xmlgw.phtml</endpoint>
                        </api>
                  </data>
            </result>
      </operation>
</response>";

            Stream stream = new MemoryStream();
            StreamWriter streamWriter = new StreamWriter(stream);
            streamWriter.Write(xml);
            streamWriter.Flush();
            
            stream.Position = 0;

            SynchronousResponse response = new SynchronousResponse(stream);
            Assert.IsInstanceOfType(response.Operation, typeof(OperationBlock));
        }
        public void MissingOperationBlockTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>ControlIdHere</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
</response>";

            Stream stream = new MemoryStream();
            StreamWriter streamWriter = new StreamWriter(stream);
            streamWriter.Write(xml);
            streamWriter.Flush();

            stream.Position = 0;

            SynchronousResponse response = new SynchronousResponse(stream);
        }
Example #14
0
        public void MissingControlIdElementTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>ControlIdHere</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>fakeuser</userid>
                  <companyid>fakecompany</companyid>
                  <sessiontimestamp>2015-10-25T10:08:34-07:00</sessiontimestamp>
            </authentication>
            <result>
                  <status>success</status>
                  <function>readByQuery</function>
                  <!--<controlid>testControlId</controlid>-->
                  <data listtype=""department"" count=""0"" totalcount=""0"" numremaining=""0"" resultId=""""/>
            </result>
      </operation>
</response>";

            Stream       stream       = new MemoryStream();
            StreamWriter streamWriter = new StreamWriter(stream);

            streamWriter.Write(xml);
            streamWriter.Flush();

            stream.Position = 0;

            SynchronousResponse response = new SynchronousResponse(stream);
        }
Example #15
0
        public void GetErrorsTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>failure</status>
            <senderid>testsenderid</senderid>
            <controlid>ControlIdHere</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <errormessage>
            <error>
                  <errorno>XL03000006</errorno>
                  <description></description>
                  <description2>test is not a valid transport policy.</description2>
                  <correction></correction>
            </error>
      </errormessage>
</response>";

            Stream       stream       = new MemoryStream();
            StreamWriter streamWriter = new StreamWriter(stream);

            streamWriter.Write(xml);
            streamWriter.Flush();
            stream.Position = 0;

            try
            {
                SynchronousResponse response = new SynchronousResponse(stream);
            }
            catch (ResponseException ex)
            {
                Assert.IsInstanceOfType(ex.Errors, typeof(List <string>));
            }
        }
        public async Task MockExecuteWithDebugLoggerTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>sessionProvider</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>testuser</userid>
                  <companyid>testcompany</companyid>
                  <sessiontimestamp>2015-12-06T15:57:08-08:00</sessiontimestamp>
            </authentication>
            <result>
                  <status>success</status>
                  <function>getAPISession</function>
                  <controlid>func1UnitTest</controlid>
                  <data>
                        <api>
                              <sessionid>unittest..</sessionid>
                              <endpoint>https://unittest.intacct.com/ia/xml/xmlgw.phtml</endpoint>
                        </api>
                  </data>
            </result>
      </operation>
</response>";

            HttpResponseMessage mockResponse = new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent(xml)
            };

            List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage>
            {
                mockResponse,
            };

            MockHandler mockHandler = new MockHandler(mockResponses);

            MemoryTarget target = new MemoryTarget();

            target.Layout = "${message}";
            SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);

            SdkConfig config = new SdkConfig()
            {
                SenderId       = "testsenderid",
                SenderPassword = "******",
                SessionId      = "testsession..",
                MockHandler    = mockHandler,
                Logger         = LogManager.GetCurrentClassLogger(),
            };

            Content content = new Content()
            {
                new ApiSessionCreate(),
            };

            RequestHandler      requestHandler = new RequestHandler(config);
            SynchronousResponse response       = await requestHandler.ExecuteSynchronous(config, content);

            Assert.IsTrue(target.Logs[0].Contains("intacct-api-net-client/")); // Check for the user agent
        }
        public async Task MockRetryTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>sessionProvider</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>testuser</userid>
                  <companyid>testcompany</companyid>
                  <sessiontimestamp>2015-12-06T15:57:08-08:00</sessiontimestamp>
            </authentication>
            <result>
                  <status>success</status>
                  <function>getAPISession</function>
                  <controlid>func1UnitTest</controlid>
                  <data>
                        <api>
                              <sessionid>unittest..</sessionid>
                              <endpoint>https://unittest.intacct.com/ia/xml/xmlgw.phtml</endpoint>
                        </api>
                  </data>
            </result>
      </operation>
</response>";

            HttpResponseMessage mockResponse1 = new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.BadGateway,
            };
            HttpResponseMessage mockResponse2 = new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent(xml)
            };

            List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage>
            {
                mockResponse1,
                mockResponse2,
            };

            MockHandler mockHandler = new MockHandler(mockResponses);

            SdkConfig config = new SdkConfig()
            {
                SenderId       = "testsenderid",
                SenderPassword = "******",
                SessionId      = "testsession..",
                MockHandler    = mockHandler,
            };

            Content content = new Content();

            RequestHandler      requestHandler = new RequestHandler(config);
            SynchronousResponse response       = await requestHandler.ExecuteSynchronous(config, content);

            Assert.AreEqual("testsenderid", response.Control.SenderId);
        }
        public async Task LoggerTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>requestUnitTest</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>testuser</userid>
                  <companyid>testcompany</companyid>
                  <sessiontimestamp>2015-12-06T15:57:08-08:00</sessiontimestamp>
            </authentication>
            <result>
                <status>success</status>
                <function>readByQuery</function>
                <controlid>func1UnitTest</controlid>
                <data listtype=""customer"" count=""1"" totalcount=""1"" numremaining=""0"" resultId="""">
                    <customer>
                        <CUSTOMERID>C0001</CUSTOMERID>
                        <NAME>Intacct Corporation</NAME>
                    </customer>
                </data>
            </result>
      </operation>
</response>";

            HttpResponseMessage mockResponse1 = new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent(xml)
            };

            List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage>
            {
                mockResponse1,
            };

            MockHandler mockHandler = new MockHandler(mockResponses);

            MemoryTarget target = new MemoryTarget();

            target.Layout = "${message}";
            SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);

            SdkConfig config = new SdkConfig
            {
                MockHandler = mockHandler,
                Logger      = LogManager.GetCurrentClassLogger(),
            };

            Content content = new Content();

            content.Add(new ApiSessionCreate("func1UnitTest"));

            SynchronousResponse response = await client.Execute(content, false, "requestUnitTest", false, config);

            Assert.IsTrue(target.Logs[0].Contains("<password>REDACTED</password>"));
        }