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); }
public void GetXmlTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <function controlid=""unittest""> <getAPISession /> </function>"; Stream stream = new MemoryStream(); XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Encoding = Encoding.UTF8; xmlSettings.Indent = true; xmlSettings.IndentChars = " "; IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings); ApiSessionCreate session = new ApiSessionCreate("unittest"); session.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 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 GetXmlTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <function controlid=""unittest""> <getAPISession /> </function>"; ApiSessionCreate apiFunction = new ApiSessionCreate("unittest"); this.CompareXml(expected, apiFunction); }
public void NoCredentialsTest() { SdkConfig config = new SdkConfig() { }; Content contentBlock = new Content(); ApiSessionCreate func = new ApiSessionCreate(); contentBlock.Add(func); OperationBlock operationBlock = new OperationBlock(config, contentBlock); }
public void GetXmlWithEmptyLocationTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <function controlid=""unittest""> <getAPISession> <locationid /> </getAPISession> </function>"; ApiSessionCreate apiFunction = new ApiSessionCreate("unittest"); apiFunction.EntityId = ""; this.CompareXml(expected, apiFunction); }
/// <summary> /// Create a new session-based ClientConfig, based on a different ClientConfig /// </summary> /// <param name="config"></param> /// <returns></returns> /// <exception cref="IntacctException"></exception> public static async Task <ClientConfig> Factory(ClientConfig config = null) { if (config == null) { config = new ClientConfig(); } RequestConfig requestConfig = new RequestConfig() { ControlId = "sessionProvider", NoRetryServerErrorCodes = new int[] { }, // Retry all 500 level errors }; ApiSessionCreate apiFunction = new ApiSessionCreate(); if (!string.IsNullOrWhiteSpace(config.SessionId) && config.EntityId != null) { apiFunction.EntityId = config.EntityId; } OnlineClient client = new OnlineClient(config); OnlineResponse response = await client.Execute(apiFunction, requestConfig).ConfigureAwait(false); Authentication authentication = response.Authentication; Result result = response.Results[0]; result.EnsureStatusSuccess(); // Throw any result errors List <XElement> data = result.Data; XElement api = data[0]; config.SessionId = api.Element("sessionid")?.Value; config.EndpointUrl = api.Element("endpoint")?.Value; config.EntityId = api.Element("locationid")?.Value; config.CompanyId = authentication.CompanyId; config.UserId = authentication.UserId; config.Credentials = new SessionCredentials(config, new SenderCredentials(config)); return(config); }
public void NoCredentialsTest() { ClientConfig clientConfig = new ClientConfig() { SessionId = "", CompanyId = "", UserId = "", UserPassword = "", }; List <IFunction> contentBlock = new List <IFunction>(); ApiSessionCreate func = new ApiSessionCreate(); contentBlock.Add(func); var ex = Record.Exception(() => new OperationBlock(clientConfig, new RequestConfig(), contentBlock)); Assert.IsType <ArgumentException>(ex); Assert.Equal("Authentication credentials [Company ID, User ID, and User Password] or [Session ID] are required and cannot be blank", ex.Message); }
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); }