Exemplo n.º 1
0
        /// <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 void WriteXmlSessionTest()
        {
            ClientConfig clientConfig = new ClientConfig()
            {
                SessionId = "fakesession..",
            };

            List <IFunction> contentBlock = new List <IFunction>();
            ApiSessionCreate func         = new ApiSessionCreate()
            {
                ControlId = "unittest",
            };

            contentBlock.Add(func);

            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<operation transaction=""false"">
    <authentication>
        <sessionid>fakesession..</sessionid>
    </authentication>
    <content>
        <function controlid=""unittest"">
            <getAPISession />
        </function>
    </content>
</operation>";

            OperationBlock operationBlock = new OperationBlock(clientConfig, new RequestConfig(), contentBlock);

            this.CompareXml(expected, operationBlock);
        }
Exemplo n.º 3
0
 public SynchronousResponse(Stream body) : base(body)
 {
     if (xml.Element("response").Element("operation") == null)
     {
         throw new IntacctException("Response is missing operation block");
     }
     Operation = new OperationBlock(xml.Element("response").Element("operation"));
 }
        public void WriteXmlLoginTest()
        {
            SdkConfig config = new SdkConfig()
            {
                CompanyId    = "testcompany",
                UserId       = "testuser",
                UserPassword = "******",
            };

            Content          contentBlock = new Content();
            ApiSessionCreate func         = new ApiSessionCreate()
            {
                ControlId = "unittest",
            };

            contentBlock.Add(func);

            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<operation transaction=""false"">
    <authentication>
        <login>
            <userid>testuser</userid>
            <companyid>testcompany</companyid>
            <password>testpass</password>
        </login>
    </authentication>
    <content>
        <function controlid=""unittest"">
            <getAPISession />
        </function>
    </content>
</operation>";

            Stream            stream      = new MemoryStream();
            XmlWriterSettings xmlSettings = new XmlWriterSettings();

            xmlSettings.Encoding    = Encoding.UTF8;
            xmlSettings.Indent      = true;
            xmlSettings.IndentChars = "    ";

            IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings);

            OperationBlock operationBlock = new OperationBlock(config, contentBlock);

            operationBlock.WriteXml(ref xml);

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

            Diff xmlDiff = DiffBuilder.Compare(expected).WithTest(reader.ReadToEnd())
                           .WithDifferenceEvaluator(DifferenceEvaluators.Default)
                           .Build();

            Assert.IsFalse(xmlDiff.HasDifferences(), xmlDiff.ToString());
        }
        public void NoCredentialsTest()
        {
            SdkConfig config = new SdkConfig()
            {
            };

            Content          contentBlock = new Content();
            ApiSessionCreate func         = new ApiSessionCreate();

            contentBlock.Add(func);

            OperationBlock operationBlock = new OperationBlock(config, contentBlock);
        }
Exemplo n.º 6
0
    public void HitOperationBrick(Interactable i)
    {
        OperationBlock b = i as OperationBlock;

        if (operation != Multiplier.NONE)
        {
            number1 = result;
            number2 = Int32.MinValue;
            result  = Int32.MinValue;
        }

        operation      = b.multiplier;
        process        = 3;
        operationRound = false;
    }
Exemplo n.º 7
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-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);
            OperationBlock operation = response.Operation;

            Assert.IsInstanceOfType(operation.Authentication, typeof(Authentication));
            Assert.IsInstanceOfType(operation.Results, typeof(List<Result>));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Constructs the RequestBlock object with the supplied config and content
        /// </summary>
        /// <param name="config"></param>
        /// <param name="content"></param>
        public RequestBlock(SdkConfig config, Content content)
        {
            if (!String.IsNullOrWhiteSpace(config.Encoding))
            {
                var encodingInfo = Encoding.GetEncodings().FirstOrDefault(info => info.Name == config.Encoding);
                if (encodingInfo != null)
                {
                    Encoding encoding = encodingInfo.GetEncoding();
                }
                else
                {
                    throw new ArgumentException("Requested encoding is not supported");
                }
            }
            else
            {
                encoding = Encoding.GetEncoding("UTF-8");
            }

            control   = new ControlBlock(config);
            operation = new OperationBlock(config, content);
        }
        public void WriteXmlLoginTest()
        {
            ClientConfig clientConfig = new ClientConfig()
            {
                CompanyId    = "testcompany",
                UserId       = "testuser",
                UserPassword = "******",
            };

            List <IFunction> contentBlock = new List <IFunction>();
            ApiSessionCreate func         = new ApiSessionCreate()
            {
                ControlId = "unittest",
            };

            contentBlock.Add(func);

            string expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
<operation transaction=""false"">
    <authentication>
        <login>
            <userid>testuser</userid>
            <companyid>testcompany</companyid>
            <password>testpass</password>
        </login>
    </authentication>
    <content>
        <function controlid=""unittest"">
            <getAPISession />
        </function>
    </content>
</operation>";

            OperationBlock operationBlock = new OperationBlock(clientConfig, new RequestConfig(), contentBlock);

            this.CompareXml(expected, operationBlock);
        }
Exemplo n.º 10
0
 public RequestBlock(ClientConfig clientConfig, RequestConfig requestConfig, List <IFunction> content)
 {
     this.Encoding  = requestConfig.Encoding;
     this.Control   = new ControlBlock(clientConfig, requestConfig);
     this.Operation = new OperationBlock(clientConfig, requestConfig, content);
 }
Exemplo n.º 11
0
 protected virtual void OnOperationBlock(bool on)
 {
     OperationBlock.Raise(this, new EventArgs <bool> {
         Value = on
     });
 }