public void Setup() { try { // Create a client and set up authentication Client = new AvaTaxClient(typeof(TransactionTests).Assembly.FullName, typeof(TransactionTests).Assembly.GetName().Version.ToString(), Environment.MachineName, AvaTaxEnvironment.Sandbox) .WithSecurity(Environment.GetEnvironmentVariable("SANDBOX_USERNAME"), Environment.GetEnvironmentVariable("SANDBOX_PASSWORD")); // Verify that we can ping successfully var pingResult = Client.Ping(); // Assert that ping succeeded Assert.NotNull(pingResult, "Should be able to call Ping"); Assert.True(pingResult.authenticated, "Environment variables should provide correct authentication"); //Get the default company. var defaultCompanyModel = Client.QueryCompanies(string.Empty, "isDefault EQ true", null, null, string.Empty).value.FirstOrDefault(); DefaultCompanyId = defaultCompanyModel.id; // Create a basic company with nexus in the state of Washington TestCompany = Client.CompanyInitialize(new CompanyInitializationModel() { city = "Bainbridge Island", companyCode = Guid.NewGuid().ToString().Substring(0, 25), country = "US", email = "*****@*****.**", faxNumber = null, firstName = "Bob", lastName = "McExample", line1 = "100 Ravine Lane", mobileNumber = "206 555 1212", phoneNumber = "206 555 1212", postalCode = "98110", region = "WA", taxpayerIdNumber = "123456789", name = "Bob's Greatest Popcorn", title = "Owner/CEO" }); // Add a delay after creating company System.Threading.Thread.Sleep(6 * 1000); // Assert that company setup succeeded Assert.NotNull(TestCompany, "Test company should be created"); Assert.True(TestCompany.nexus.Count > 0, "Test company should have nexus"); Assert.True(TestCompany.locations.Count > 0, "Test company should have locations"); // Shouldn't fail } catch (Exception ex) { Assert.Fail("Exception in SetUp: " + ex); } }
public void Setup() { _client = null; _testCompany = null; try { // Create a client and set up authentication _client = new AvaTaxClient(GetType().Name, GetType().GetTypeInfo().Assembly.ImageRuntimeVersion.ToString(), Environment.MachineName, AvaTaxEnvironment.Sandbox) .WithSecurity(Environment.GetEnvironmentVariable("SANDBOX_USERNAME"), Environment.GetEnvironmentVariable("SANDBOX_PASSWORD")); // Verify that we can ping successfully var pingResult = _client.Ping(); // Assert that ping succeeded Assert.NotNull(pingResult, "Should be able to call Ping"); Assert.True(pingResult.authenticated, "Environment variables should provide correct authentication"); _companyCode = Guid.NewGuid().ToString("N").Substring(0, 25); // Create a basic company with nexus in the state of Washington _testCompany = _client.CompanyInitialize(new CompanyInitializationModel() { city = "Bainbridge Island", companyCode = _companyCode, country = "US", email = "*****@*****.**", faxNumber = null, firstName = "Bob", lastName = "McExample", line1 = "100 Ravine Lane", mobileNumber = "206 555 1212", phoneNumber = "206 555 1212", postalCode = "98110", region = "WA", taxpayerIdNumber = "123456789", name = "Bob's Hardware Store", title = "Owner/CEO" }); // Add a delay after creating a company System.Threading.Thread.Sleep(6 * 1000); // Assert that company setup succeeded Assert.NotNull(_testCompany, "Test company should be created"); Assert.True(_testCompany.nexus.Count > 0, "Test company should have nexus"); Assert.True(_testCompany.locations.Count > 0, "Test company should have locations"); // Shouldn't fail } catch (Exception ex) { Assert.Fail("Exception in SetUp: " + ex); } }
/// <summary> /// To debug this application, call app must be called with args[0] as username and args[1] as password /// </summary> /// <param name="args"></param> public static void Main(string[] args) { // Connect to the server var client = new AvaTaxClient("ConsoleTest", "1.0", Environment.MachineName, AvaTaxEnvironment.Sandbox); client.WithSecurity(args[0], args[1]); // Call Ping var pingResult = client.Ping(); Console.WriteLine(pingResult.version); // Call fetch try { var companies = client.QueryCompanies(null, null, 0, 0, null); Console.WriteLine(companies.ToString()); // Initialize a company and fetch it back var init = client.CompanyInitialize(new CompanyInitializationModel() { city = "Bainbridge Island", companyCode = Guid.NewGuid().ToString("N").Substring(0, 25), country = "US", email = "*****@*****.**", faxNumber = null, firstName = "Bob", lastName = "Example", line1 = "100 Ravine Lane", line2 = null, line3 = null, mobileNumber = null, name = "Bob Example", phoneNumber = "206 555 1212", postalCode = "98110", region = "WA", taxpayerIdNumber = "123456789", title = "Owner", vatRegistrationId = null }); Console.WriteLine(init.ToString()); // Fetch it back var fetchBack = client.GetCompany(init.id, "Locations"); Console.WriteLine(fetchBack.ToString()); // Execute a transaction var t = new TransactionBuilder(client, init.companyCode, DocumentType.SalesInvoice, "ABC") .WithAddress(TransactionAddressType.SingleLocation, "123 Main Street", "Irvine", "CA", "92615", "US") .WithLine(100.0m) .WithExemptLine(50.0m, "NT") .Create(); Console.WriteLine(t.ToString()); } catch (AvaTaxError ex) { Console.WriteLine(ex.error.ToString()); } catch (Exception ex2) { Console.WriteLine(ex2.ToString()); } // Finished Console.WriteLine("Done"); }