Skip to content

Commit

Permalink
v2.0 (#8)
Browse files Browse the repository at this point in the history
This updates the Intacct SDK for .NET to be of the same design as the Intacct SDK for PHP.
  • Loading branch information
jimmymcpeter authored Jan 4, 2018
1 parent e2a0420 commit 4c0d324
Show file tree
Hide file tree
Showing 689 changed files with 16,278 additions and 22,919 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: csharp
solution: intacct-sdk-net.sln
mono: none
dotnet: 2.0.0
install:
- dotnet restore

script:
- dotnet build --configuration Release
- dotnet test Intacct.SDK.Tests/Intacct.SDK.Tests.csproj --framework "netcoreapp2.0"

notifications:
slack:
secure: D3WkYcHFpnZoB4rFlW8Ugj04qx5Dtp1UyeQ5XtUxU4Pf1Hfu3tN5rTrsafKPVPQ57ve0vNiUb7e1xV9+YUJvFBaNvh/zJaqEE9zGHYKlt4EfnDUktYBQJ8KE0FuW+OPIkAHye/e/D598OZNFRQV+m/0JYw7Yr4xQUl8SWqgMg6x6+lQo4W1L7kTxct4avUOJ9J0NcrCl52TaHRE0SkorooYu871+euzoLOYBs6bunypKN84GY51Bvlh9CcQDjau26TzP+AV/i5zfCnQE1ihl1N40zdmAPm9iZAswPYjQVSHPDikRTnOyo37t45/+JSgikhgB+JskTNE3Gc05JdPVwl6lvtISPt8xQLDc+faHFn3CDn2rSeS8gFRQ0dzpyVDotLQELcY95R566Yf6uCtI7q5W4txjPAxnsATRh2llfs7bWXMkRNu6Rm6zXCf8NcOO5K7TAR0I/j/Up9Bk8QMOg0/P1gzgyI/Ytne5iFTTyQTv7vBa0488P2kLfSpKEbCXmQQKoquuK1Nox6fW2H/jV1S5xIx26KnctFyHLBX1u6pM3+eFHDxOWAgiXIkMMDQddjzVuw/Lbt9QpJsN5ehAuvZ+ZwAlHkC5eOwmLmmwlySeyfGP3uCpqlidy+exEby70wm1v6yKKQJGpRRcosH2xXimJChAKrw1ORh2fP0cl1Q=
29 changes: 29 additions & 0 deletions Intacct.SDK.Tests/ClientConfigTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Intacct.SDK.Logging;
using NLog;
using Xunit;

namespace Intacct.SDK.Tests
{
public class ClientConfigTest
{
[Fact]
public void ExecuteTest()
{
ClientConfig clientConfig = new ClientConfig();

Assert.Null(clientConfig.ProfileFile);
Assert.Null(clientConfig.ProfileName);
Assert.Null(clientConfig.EndpointUrl);
Assert.Null(clientConfig.SenderId);
Assert.Null(clientConfig.SenderPassword);
Assert.Null(clientConfig.SessionId);
Assert.Null(clientConfig.CompanyId);
Assert.Null(clientConfig.UserId);
Assert.Null(clientConfig.UserPassword);
Assert.Null(clientConfig.Credentials);
Assert.Null(clientConfig.Logger);
Assert.Equal(LogLevel.Debug, clientConfig.LogLevel);
Assert.IsType<MessageFormatter>(clientConfig.LogMessageFormatter);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Intacct Corporation.
* Copyright 2018 Sage Intacct, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. You may obtain a copy
Expand All @@ -13,99 +13,96 @@
* permissions and limitations under the License.
*/

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Intacct.Sdk.Tests.Helpers;
using Intacct.SDK.Credentials;
using Xunit;

namespace Intacct.Sdk.Tests
namespace Intacct.SDK.Tests.Credentials
{

[TestClass()]
public class EndpointTest
{

[TestMethod()]
[Fact]
public void DefaultEndpointTest()
{
SdkConfig config = new SdkConfig();
ClientConfig config = new ClientConfig();

Endpoint endpoint = new Endpoint(config);

Assert.AreEqual("https://api.intacct.com/ia/xml/xmlgw.phtml", endpoint.Url);
StringAssert.Equals("https://api.intacct.com/ia/xml/xmlgw.phtml", endpoint);
Assert.Equal("https://api.intacct.com/ia/xml/xmlgw.phtml", endpoint.Url);
Assert.Equal("https://api.intacct.com/ia/xml/xmlgw.phtml", endpoint.ToString());
}

[TestMethod()]
[Fact]
public void EnvVariableEndpointTest()
{
string url = "https://envunittest.intacct.com/ia/xml/xmlgw.phtml";

Environment.SetEnvironmentVariable("INTACCT_ENDPOINT_URL", url);

SdkConfig config = new SdkConfig();
ClientConfig config = new ClientConfig();

Endpoint endpoint = new Endpoint(config);

Assert.AreEqual(url, endpoint.Url);
StringAssert.Equals(url, endpoint);
Assert.Equal(url, endpoint.Url);
Assert.Equal(url, endpoint.ToString());

Environment.SetEnvironmentVariable("INTACCT_ENDPOINT_URL", null);
}

[TestMethod()]
[Fact]
public void ConfigEndpointTest()
{
string url = "https://configunittest.intacct.com/ia/xml/xmlgw.phtml";

SdkConfig config = new SdkConfig()
ClientConfig config = new ClientConfig()
{
EndpointUrl = url
};

Endpoint endpoint = new Endpoint(config);

Assert.AreEqual(url, endpoint.Url);
StringAssert.Equals(url, endpoint);
Assert.Equal(url, endpoint.Url);
Assert.Equal(url, endpoint.ToString());
}

[TestMethod()]
[Fact]
public void NullEndpointTest()
{
SdkConfig config = new SdkConfig()
ClientConfig config = new ClientConfig()
{
EndpointUrl = null
EndpointUrl = ""
};

Endpoint endpoint = new Endpoint(config);

Assert.AreEqual("https://api.intacct.com/ia/xml/xmlgw.phtml", endpoint.Url);
StringAssert.Equals("https://api.intacct.com/ia/xml/xmlgw.phtml", endpoint);
Assert.Equal("https://api.intacct.com/ia/xml/xmlgw.phtml", endpoint.Url);
Assert.Equal("https://api.intacct.com/ia/xml/xmlgw.phtml", endpoint.ToString());
}

[TestMethod()]
[ExpectedExceptionWithMessage(typeof(ArgumentException), "Endpoint URL is not a valid URL")]

[Fact]
public void InvalidUrlEndpointTest()
{
SdkConfig config = new SdkConfig()
ClientConfig config = new ClientConfig()
{
EndpointUrl = "invalidurl"
};

Endpoint endpoint = new Endpoint(config);
var ex = Record.Exception(() => new Endpoint(config));
Assert.IsType<ArgumentException>(ex);
Assert.Equal("Endpoint URL is not a valid URL", ex.Message);
}

[TestMethod()]
[ExpectedExceptionWithMessage(typeof(ArgumentException), "Endpoint URL is not a valid intacct.com domain name")]

[Fact]
public void InvalidIntacctEndpointTest()
{
SdkConfig config = new SdkConfig()
ClientConfig config = new ClientConfig()
{
EndpointUrl = "https://api.notintacct.com"
EndpointUrl = "https://api.example.com/xmlgw.phtml"
};

Endpoint endpoint = new Endpoint(config);
var ex = Record.Exception(() => new Endpoint(config));
Assert.IsType<ArgumentException>(ex);
Assert.Equal("Endpoint URL is not a valid intacct.com domain name", ex.Message);
}

}

}
17 changes: 17 additions & 0 deletions Intacct.SDK.Tests/Credentials/Ini/default.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[default]
sender_id = defsenderid
sender_password = defsenderpass
company_id = defcompanyid
user_id = defuserid
user_password = defuserpass
endpoint_url = https://unittest.intacct.com/ia/xml/xmlgw.phtml

[unittest]
company_id = inicompanyid
user_id = iniuserid
user_password = iniuserpass

[anothertest]
sender_id = inisenderid
sender_password = inisenderpass
endpoint_url = https://unittest.intacct.com/ia/xmlgw.phtml
3 changes: 3 additions & 0 deletions Intacct.SDK.Tests/Credentials/Ini/notdefault.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[notdefault]
sender_id = testsenderid
sender_password = testsenderpass
121 changes: 121 additions & 0 deletions Intacct.SDK.Tests/Credentials/LoginCredentialsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright 2018 Sage Intacct, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "LICENSE" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

using System;
using System.IO;
using Intacct.SDK.Credentials;
using Xunit;

namespace Intacct.SDK.Tests.Credentials
{

public class LoginCredentialsTest
{

protected SenderCredentials SenderCreds;

public LoginCredentialsTest()
{
ClientConfig config = new ClientConfig
{
SenderId = "testsenderid",
SenderPassword = "pass123!"
};
this.SenderCreds = new SenderCredentials(config);
}

[Fact]
public void CredsFromConfigTest()
{
ClientConfig config = new ClientConfig
{
CompanyId = "testcompany",
UserId = "testuser",
UserPassword = "testpass"
};

LoginCredentials loginCreds = new LoginCredentials(config, this.SenderCreds);

Assert.Equal("testcompany", loginCreds.CompanyId);
Assert.Equal("testuser", loginCreds.UserId);
Assert.Equal("testpass", loginCreds.Password);
Endpoint endpoint = loginCreds.SenderCredentials.Endpoint;
Assert.Equal("https://api.intacct.com/ia/xml/xmlgw.phtml", endpoint.ToString());
Assert.IsType<SenderCredentials>(loginCreds.SenderCredentials);
}

[Fact]
public void CredsFromProfileTest()
{
string tempFile = Path.Combine(Directory.GetCurrentDirectory(), "Credentials", "Ini", "default.ini");

ClientConfig config = new ClientConfig()
{
ProfileFile = tempFile,
ProfileName = "unittest",
};

LoginCredentials loginCreds = new LoginCredentials(config, this.SenderCreds);
Assert.Equal("inicompanyid", loginCreds.CompanyId);
Assert.Equal("iniuserid", loginCreds.UserId);
Assert.Equal("iniuserpass", loginCreds.Password);
}

[Fact]
public void CredsFromArrayNoCompanyIdTest()
{
ClientConfig config = new ClientConfig
{
CompanyId = "",
UserId = "testuser",
UserPassword = "testpass"
};

var ex = Record.Exception(() => new LoginCredentials(config, this.SenderCreds));
Assert.IsType<ArgumentException>(ex);
Assert.Equal("Required Company ID not supplied in config or env variable \"INTACCT_COMPANY_ID\"", ex.Message);
}

[Fact]
public void CredsFromArrayNoUserIdTest()
{
ClientConfig config = new ClientConfig
{
CompanyId = "testcompany",
UserId = "",
UserPassword = "testpass"
};

var ex = Record.Exception(() => new LoginCredentials(config, this.SenderCreds));
Assert.IsType<ArgumentException>(ex);
Assert.Equal("Required User ID not supplied in config or env variable \"INTACCT_USER_ID\"", ex.Message);
}

[Fact]
public void CredsFromArrayNoUserPasswordTest()
{
ClientConfig config = new ClientConfig
{
CompanyId = "testcompany",
UserId = "testuser",
UserPassword = ""
};

var ex = Record.Exception(() => new LoginCredentials(config, this.SenderCreds));
Assert.IsType<ArgumentException>(ex);
Assert.Equal("Required User Password not supplied in config or env variable \"INTACCT_USER_PASSWORD\"", ex.Message);
}
}
}
58 changes: 58 additions & 0 deletions Intacct.SDK.Tests/Credentials/ProfileCredentialProviderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2018 Sage Intacct, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "LICENSE" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

using System;
using System.IO;
using Intacct.SDK.Credentials;
using Xunit;

namespace Intacct.SDK.Tests.Credentials
{
public class ProfileCredentialProviderTest
{
[Fact]
public void GetLoginCredentialsFromSpecificProfileTest()
{
string tempFile = Path.Combine(Directory.GetCurrentDirectory(), "Credentials", "Ini", "default.ini");

ClientConfig config = new ClientConfig()
{
ProfileFile = tempFile,
ProfileName = "unittest",
};

ClientConfig loginCreds = ProfileCredentialProvider.GetLoginCredentials(config);

Assert.Equal("inicompanyid", loginCreds.CompanyId);
Assert.Equal("iniuserid", loginCreds.UserId);
Assert.Equal("iniuserpass", loginCreds.UserPassword);
}

[Fact]
public void GetLoginCredentialsMissingDefault()
{
string tempFile = Path.Combine(Directory.GetCurrentDirectory(), "Credentials", "Ini", "notdefault.ini");

ClientConfig config = new ClientConfig()
{
ProfileFile = tempFile,
};

var ex = Record.Exception(() => ProfileCredentialProvider.GetLoginCredentials(config));
Assert.IsType<ArgumentException>(ex);
Assert.Equal("Profile name \"default\" not found in credentials file", ex.Message);
}
}
}
Loading

0 comments on commit 4c0d324

Please sign in to comment.