Skip to content

Commit

Permalink
Merge pull request #47 from codymullins/bug/int-1329-async-method-params
Browse files Browse the repository at this point in the history
Bug/int 1329 async method params
  • Loading branch information
codymullins authored Oct 30, 2020
2 parents a653c79 + 60836fa commit 7f9cdb2
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ src/packages/*
TaxJar.dll
Taxjar.userprefs

.env
.env
secrets.json
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -941,10 +941,12 @@ catch(TaxjarException e)

## Tests

We use [NUnit](https://github.com/nunit/nunit) and [WireMock.Net](https://github.com/WireMock-Net/WireMock.Net) for testing. Before running the specs, create a `.env` file inside the `Taxjar.Tests` directory with your sandbox API key:
We use [NUnit](https://github.com/nunit/nunit) and [WireMock.Net](https://github.com/WireMock-Net/WireMock.Net) for testing. Before running the specs, create a `secrets.json` file inside the `Taxjar.Tests` directory with your sandbox API Token:

```
TAXJAR_API_KEY=YOUR_TAXJAR_SANDBOX_API_KEY
{
"ApiToken": "YOUR_SANDBOX_KEY"
}
```

## More Information
Expand Down
23 changes: 17 additions & 6 deletions src/Taxjar.Tests/Bootstrap.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using NUnit.Framework;
using System.IO;
using Newtonsoft.Json;
using NUnit.Framework;
using WireMock.Server;
using WireMock.Settings;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;

namespace Taxjar.Tests
{
Expand All @@ -16,8 +16,6 @@ public class Bootstrap
[OneTimeSetUp]
public static void Init()
{
DotNetEnv.Env.Load("../../../.env");

if (server == null)
{
server = FluentMockServer.Start(new FluentMockServerSettings
Expand All @@ -26,7 +24,8 @@ public static void Init()
});
}

apiKey = System.Environment.GetEnvironmentVariable("TAXJAR_API_KEY") ?? "foo123";
var options = GetTestOptions();
apiKey = options.ApiToken;
client = new TaxjarApi(apiKey, new { apiUrl = "http://localhost:9191" });
}

Expand All @@ -35,5 +34,17 @@ public static void Destroy()
{
server.Stop();
}

private static TestOptions GetTestOptions()
{
var json = File.ReadAllText("../../../secrets.json");
var options = JsonConvert.DeserializeObject<TestOptions>(json);
return options;
}

private class TestOptions
{
public string ApiToken { get; set; }
}
}
}
29 changes: 26 additions & 3 deletions src/Taxjar.Tests/Customers.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using NUnit.Framework;
using System;
using System.Net;
using System.Threading.Tasks;
using Taxjar.Infrastructure;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;

Expand Down Expand Up @@ -253,6 +254,7 @@ public async Task when_updating_a_customer_async()
.WithBodyAsJson(body)
);

// verify customer_id
var customer = await Bootstrap.client.UpdateCustomerAsync(new
{
customer_id = "123",
Expand All @@ -272,6 +274,27 @@ public async Task when_updating_a_customer_async()
});

AssertCustomer(customer);

// verify CustomerId
customer = await Bootstrap.client.UpdateCustomerAsync(new
{
CustomerId = "123",
exemption_type = "wholesale",
name = "Sterling Cooper",
exempt_regions = new[] {
new {
country = "US",
state = "NY"
}
},
country = "US",
state = "NY",
zip = "10010",
city = "New York",
street = "405 Madison Ave"
});

AssertCustomer(customer);
}

[Test]
Expand All @@ -289,7 +312,7 @@ public void when_updating_a_customer_with_missing_customer_id()
.WithBodyAsJson(body)
);

var systemException = Assert.Throws<Exception>(() => Bootstrap.client.UpdateCustomer(new
var systemException = Assert.Throws<ArgumentException>(() => Bootstrap.client.UpdateCustomer(new
{
exemption_type = "wholesale",
name = "Sterling Cooper",
Expand All @@ -306,7 +329,7 @@ public void when_updating_a_customer_with_missing_customer_id()
street = "405 Madison Ave"
}));

Assert.AreEqual("Missing customer ID for `UpdateCustomer`", systemException.Message);
Assert.AreEqual(ErrorMessage.MissingCustomerId, systemException.Message);
}

[Test]
Expand Down
3 changes: 1 addition & 2 deletions src/Taxjar.Tests/TaxJar.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net452</TargetFrameworks>
Expand Down Expand Up @@ -26,7 +26,6 @@
<PackageReference Include="RestSharp" Version="106.10.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="WireMock.Net.StandAlone" Version="1.0.19.0" />
<PackageReference Include="DotNetEnv" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
34 changes: 29 additions & 5 deletions src/Taxjar.Tests/Transactions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using NUnit.Framework;
using System;
using System.Net;
using System.Threading.Tasks;
using Taxjar.Infrastructure;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;

Expand Down Expand Up @@ -330,6 +331,7 @@ public async Task when_updating_an_order_transaction_async()
.WithBodyAsJson(body)
);

// verify transaction_id
var order = await Bootstrap.client.UpdateOrderAsync(new
{
transaction_id = "123",
Expand All @@ -350,6 +352,28 @@ public async Task when_updating_an_order_transaction_async()
});

AssertOrder(order);

// verify TransactionId
order = await Bootstrap.client.UpdateOrderAsync(new
{
TransactionId = "123",
amount = 17.95,
shipping = 2,
exemption_type = "non_exempt",
line_items = new[] {
new {
quantity = 1,
product_identifier = "12-34243-0",
description = "Heavy Widget",
product_tax_code = "20010",
unit_price = 15,
discount = 0,
sales_tax = 0.95
}
}
});

AssertOrder(order);
}

[Test]
Expand All @@ -367,7 +391,7 @@ public void when_updating_an_order_transaction_with_missing_transaction_id()
.WithBodyAsJson(body)
);

var systemException = Assert.Throws<Exception>(() => Bootstrap.client.UpdateOrder(new
var systemException = Assert.Throws<ArgumentException>(() => Bootstrap.client.UpdateOrder(new
{
amount = 17.95,
shipping = 2,
Expand All @@ -385,7 +409,7 @@ public void when_updating_an_order_transaction_with_missing_transaction_id()
}
}));

Assert.AreEqual("Missing transaction ID for `UpdateOrder`", systemException.Message);
Assert.AreEqual(ErrorMessage.MissingTransactionId, systemException.Message);
}

[Test]
Expand Down Expand Up @@ -711,7 +735,7 @@ public void when_updating_a_refund_transaction_with_missing_transaction_id()
.WithBodyAsJson(body)
);

var systemException = Assert.Throws<Exception>(() => Bootstrap.client.UpdateRefund(new
var systemException = Assert.Throws<ArgumentException>(() => Bootstrap.client.UpdateRefund(new
{
amount = 17.95,
shipping = 2,
Expand All @@ -729,7 +753,7 @@ public void when_updating_a_refund_transaction_with_missing_transaction_id()
}
}));

Assert.AreEqual("Missing transaction ID for `UpdateRefund`", systemException.Message);
Assert.AreEqual(ErrorMessage.MissingTransactionId, systemException.Message);
}

[Test]
Expand Down
15 changes: 15 additions & 0 deletions src/Taxjar/Infrastructure/ErrorMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;

[assembly: InternalsVisibleTo("TaxJar.Tests")]

namespace Taxjar.Infrastructure
{
internal static class ErrorMessage
{
public const string MissingTransactionId = "Transaction ID cannot be null or an empty string.";
public const string MissingCustomerId = "Customer ID cannot be null or an empty string.";
}
}
2 changes: 1 addition & 1 deletion src/Taxjar/Taxjar.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
Expand Down
Loading

0 comments on commit 7f9cdb2

Please sign in to comment.