diff --git a/.gitignore b/.gitignore index aa3bc35..017a898 100644 --- a/.gitignore +++ b/.gitignore @@ -286,3 +286,4 @@ __pycache__/ # Editor Config .editorconfig +ShippoTesting/.env diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2e73567 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: csharp +dist: xenial +mono: none +dotnet: 3.1 +install: + - dotnet restore + script: + - dotnet build + - dotnet test ShippoTesting/ShippoTesting.csproj diff --git a/Shippo.sln b/Shippo.sln index d707368..01c440e 100644 --- a/Shippo.sln +++ b/Shippo.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 15.0.28010.2019 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shippo", "Shippo\Shippo.csproj", "{6816FD58-3FC6-4EFC-95F8-D11E9C1D387F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShippoExample", "ShippoExample\ShippoExample.csproj", "{7712EC9C-2581-49EE-8B61-745843F2CD6F}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShippoTesting", "ShippoTesting\ShippoTesting.csproj", "{4AF39DE0-2FA9-43D1-9254-CF8546FF22C8}" EndProject Global diff --git a/Shippo/APIResource.cs b/Shippo/APIResource.cs index c6438a1..4886638 100644 --- a/Shippo/APIResource.cs +++ b/Shippo/APIResource.cs @@ -25,23 +25,25 @@ using System.Net; using System.Text; using System.Web; - +using Microsoft.Extensions.Logging; using Newtonsoft.Json; - namespace Shippo { public class APIResource { public static readonly string api_endpoint = "https://api.goshippo.com"; static readonly string user_agent = "Shippo/v1 CSharpBindings/1.0"; public static readonly int RatesReqTimeout = 25; public static readonly int TransactionReqTimeout = 25; + + public readonly ILogger logger; static readonly Encoding encoding = Encoding.UTF8; String accessToken; String apiVersion; // API Resource Constructor - public APIResource(string inputToken) + public APIResource(ILogger logger, string inputToken) { + this.logger = logger; accessToken = inputToken; TimeoutSeconds = 25; apiVersion = null; @@ -103,7 +105,9 @@ public virtual string DoRequest(string endpoint, string method, string body) { string result = null; WebRequest req = SetupRequest(method, endpoint); + logger.LogInformation($"GoShippo Http request endpoint: {endpoint}, method: {method}"); if (body != null) { + logger.LogInformation($"GoShippo Http request body: {body}"); byte[] bytes = encoding.GetBytes(body.ToString()); req.ContentLength = bytes.Length; using (Stream st = req.GetRequestStream()) { @@ -123,11 +127,15 @@ public virtual string DoRequest(string endpoint, string method, string body) if (resp != null) status_code = resp.StatusCode; + logger.LogInformation($"GoShippo Http request statuscode: {status_code}"); + if ((int) status_code <= 500) throw new ShippoException(json_error, wexc); } throw; } + logger.LogInformation($"GoShippo Http request result: {result}"); + return result; } @@ -391,7 +399,7 @@ public ShippoCollection AllCarrierAccount(Hashtable parameters) public ShippoCollection AllCarrierAccount() { - string ep = String.Format("{0}/carrier_accounts", api_endpoint); + string ep = String.Format("{0}/carrier_accounts/?carrier=usps", api_endpoint); return DoRequest>(ep); } diff --git a/Shippo/Manifest.cs b/Shippo/Manifest.cs index 1213c4f..5234045 100644 --- a/Shippo/Manifest.cs +++ b/Shippo/Manifest.cs @@ -19,8 +19,8 @@ public class Manifest : ShippoId { [JsonProperty(PropertyName = "provider")] public object Provider { get; set; } - [JsonProperty(PropertyName = "submission_date")] - public object SubmissionDate { get; set; } + [JsonProperty(PropertyName = "shipment_date")] + public object ShipmentDate { get; set; } [JsonProperty(PropertyName = "address_from")] public object AddressFrom { get; set; } diff --git a/Shippo/Shippo.csproj b/Shippo/Shippo.csproj index 4b18e47..5b1e1f7 100644 --- a/Shippo/Shippo.csproj +++ b/Shippo/Shippo.csproj @@ -1,7 +1,6 @@  - net45;net40 2.1.15 Shippo client library .NET library which integrates with Shippo Multi Carrier Shipping API. This library provides access to Shippo (goshippo.com) API capabilities. Including label generation, rating, tracking and more. @@ -12,10 +11,7 @@ Bug fix for extra slash in Shippo API URL Github false - - - - 0 + net7.0 @@ -30,37 +26,10 @@ - - - - - - - - - - - - - + + - - NET45;NETFULL - - - 4 - - - - - - - - - - - - + diff --git a/Shippo/Transaction.cs b/Shippo/Transaction.cs index 636f58b..a882b70 100644 --- a/Shippo/Transaction.cs +++ b/Shippo/Transaction.cs @@ -8,13 +8,13 @@ public class Transaction : ShippoId { public object ObjectState { get; set; } [JsonProperty(PropertyName = "status")] - public object Status { get; set; } + public string Status { get; set; } [JsonProperty(PropertyName = "object_created")] public object ObjectCreated { get; set; } [JsonProperty(PropertyName = "object_updated")] - public object ObjectUPdated { get; set; } + public object ObjectUpdated { get; set; } [JsonProperty(PropertyName = "object_owner")] public object ObjectOwner { get; set; } @@ -26,16 +26,16 @@ public class Transaction : ShippoId { public object Rate { get; set; } [JsonProperty(PropertyName = "tracking_number")] - public object TrackingNumber { get; set; } + public string TrackingNumber { get; set; } [JsonProperty(PropertyName = "tracking_status")] - public object TrackingStatus { get; set; } + public ShippoEnums.TrackingStatus TrackingStatus { get; set; } [JsonProperty(PropertyName = "tracking_url_provider")] - public object TrackingUrlProvider { get; set; } + public string TrackingUrlProvider { get; set; } [JsonProperty(PropertyName = "label_url")] - public object LabelURL { get; set; } + public string LabelURL { get; set; } [JsonProperty(PropertyName = "commercial_invoice_url")] public object CommercialInvoiceUrl { get; set; } diff --git a/ShippoExample/App.config b/ShippoExample/App.config deleted file mode 100644 index 8e15646..0000000 --- a/ShippoExample/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/ShippoExample/Program.cs b/ShippoExample/Program.cs deleted file mode 100644 index 4ccf30a..0000000 --- a/ShippoExample/Program.cs +++ /dev/null @@ -1,158 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -using Shippo; - -namespace ShippoExample -{ - class Program - { - static readonly string TRACKING_NO = "9205590164917312751089"; - - private static void RunBatchExample(APIResource resource) - { - ShippoCollection carrierAccounts = resource.AllCarrierAccount(); - string defaultCarrierAccount = ""; - foreach (CarrierAccount account in carrierAccounts) { - if (account.Carrier.ToString() == "usps") - defaultCarrierAccount = account.ObjectId; - } - - Address addressFrom = Address.createForPurchase("Mr. Hippo", "965 Mission St.", "Ste 201", "SF", - "CA", "94103", "US", "4151234567", "ship@gmail.com"); - Address addressTo = Address.createForPurchase("Mrs. Hippo", "965 Missions St.", "Ste 202", "SF", - "CA", "94103", "US", "4151234568", "msship@gmail.com"); - Parcel[] parcels = {Parcel.createForShipment(5, 5, 5, "in", 2, "oz")}; - Shipment shipment = Shipment.createForBatch(addressFrom, addressTo, parcels); - BatchShipment batchShipment = BatchShipment.createForBatchShipments(defaultCarrierAccount, "usps_priority", shipment); - - List batchShipments = new List(); - batchShipments.Add(batchShipment); - - Batch batch = resource.CreateBatch(defaultCarrierAccount, "usps_priority", ShippoEnums.LabelFiletypes.PDF_4x6, - "BATCH #170", batchShipments); - Console.WriteLine("Batch Status = " + batch.Status); - Console.WriteLine("Metadata = " + batch.Metadata); - } - - private static void RunTrackingExample(APIResource resource) - { - Track track = resource.RetrieveTracking("usps", TRACKING_NO); - Console.WriteLine("Carrier = " + track.Carrier.ToUpper()); - Console.WriteLine("Tracking number = " + track.TrackingNumber); - } - - private static void RunInternationalAddressValidationExample(APIResource resource) - { - Hashtable parameters = new Hashtable(); - parameters.Add("name", "Shippo Hippo"); - parameters.Add("company", "Shippo"); - parameters.Add("street_no", null); - parameters.Add("street1", "40 Bay St"); - parameters.Add("street2", null); - parameters.Add("city", "Toronto"); - parameters.Add("state", "ON"); - parameters.Add("zip", "M5J 2X2"); - parameters.Add("country", "CA"); - parameters.Add("phone", "+1 555 341 9393"); - parameters.Add("email", "hippo@goshippo.com"); - parameters.Add("metadata", "Customer ID 123456"); - parameters.Add("validate", "true"); - Address address = resource.CreateAddress(parameters); - Console.Out.WriteLine("Address IsValid: " + address.ValidationResults.IsValid); - if (address.ValidationResults.Messages != null) { - foreach (ValidationMessage message in address.ValidationResults.Messages) { - Console.Out.WriteLine("Address Message Code: " + message.Code); - Console.Out.WriteLine("Address Message Text: " + message.Text); - Console.Out.WriteLine(); - } - } - Console.Out.WriteLine("Address Latitude: " + address.Latitude); - Console.Out.WriteLine("Address Longitude: " + address.Longitude); - } - - static void Main(string[] args) - { - // replace with your Shippo Token - // don't have one? get more info here - // (https://goshippo.com/docs/#overview) - APIResource resource = new APIResource(""); - // to address - Hashtable toAddressTable = new Hashtable(); - toAddressTable.Add("name", "Mr. Hippo"); - toAddressTable.Add("company", "Shippo"); - toAddressTable.Add("street1", "215 Clayton St."); - toAddressTable.Add("city", "San Francisco"); - toAddressTable.Add("state", "CA"); - toAddressTable.Add("zip", "94117"); - toAddressTable.Add("country", "US"); - toAddressTable.Add("phone", "+1 555 341 9393"); - toAddressTable.Add("email", "support@goshipppo.com"); - - // from address - Hashtable fromAddressTable = new Hashtable(); - fromAddressTable.Add("name", "Ms Hippo"); - fromAddressTable.Add("company", "San Diego Zoo"); - fromAddressTable.Add("street1", "2920 Zoo Drive"); - fromAddressTable.Add("city", "San Diego"); - fromAddressTable.Add("state", "CA"); - fromAddressTable.Add("zip", "92101"); - fromAddressTable.Add("country", "US"); - fromAddressTable.Add("email", "hippo@goshipppo.com"); - fromAddressTable.Add("phone", "+1 619 231 1515"); - fromAddressTable.Add("metadata", "Customer ID 123456"); - - // parcel - Hashtable parcelTable = new Hashtable(); - parcelTable.Add("length", "5"); - parcelTable.Add("width", "5"); - parcelTable.Add("height", "5"); - parcelTable.Add("distance_unit", "in"); - parcelTable.Add("weight", "2"); - parcelTable.Add("mass_unit", "lb"); - List parcels = new List(); - parcels.Add(parcelTable); - - - // shipment - Hashtable shipmentTable = new Hashtable(); - shipmentTable.Add("address_to", toAddressTable); - shipmentTable.Add("address_from", fromAddressTable); - shipmentTable.Add("parcels", parcels); - shipmentTable.Add("object_purpose", "PURCHASE"); - shipmentTable.Add("async", false); - - // create Shipment object - Console.WriteLine("Creating Shipment object.."); - Shipment shipment = resource.CreateShipment(shipmentTable); - - // select desired shipping rate according to your business logic - // we simply select the first rate in this example - Rate rate = shipment.Rates[0]; - - Console.WriteLine("Getting shipping label.."); - Hashtable transactionParameters = new Hashtable(); - transactionParameters.Add("rate", rate.ObjectId); - transactionParameters.Add("async", false); - Transaction transaction = resource.CreateTransaction(transactionParameters); - - if (((String) transaction.Status).Equals("SUCCESS", StringComparison.OrdinalIgnoreCase)) { - Console.WriteLine("Label url : " + transaction.LabelURL); - Console.WriteLine("Tracking number : " + transaction.TrackingNumber); - } else { - Console.WriteLine("An Error has occured while generating your label. Messages : " + transaction.Messages); - } - - Console.WriteLine("\nBatch\n"); - RunBatchExample(resource); - - Console.WriteLine("\nTrack\n"); - RunTrackingExample(resource); - - Console.WriteLine("\nValidating International Address\n"); - RunInternationalAddressValidationExample(resource); - } - - } -} diff --git a/ShippoExample/Properties/AssemblyInfo.cs b/ShippoExample/Properties/AssemblyInfo.cs deleted file mode 100644 index e11055a..0000000 --- a/ShippoExample/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ShippoExample")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ShippoExample")] -[assembly: AssemblyCopyright("Copyright © 2018")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("7712ec9c-2581-49ee-8b61-745843f2cd6f")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ShippoExample/ShippoExample.csproj b/ShippoExample/ShippoExample.csproj deleted file mode 100644 index b6f1b0b..0000000 --- a/ShippoExample/ShippoExample.csproj +++ /dev/null @@ -1,63 +0,0 @@ - - - - - Debug - AnyCPU - {7712EC9C-2581-49EE-8B61-745843F2CD6F} - Exe - ShippoExample - ShippoExample - v4.5 - 512 - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - ShippoExample.Program - - - - ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll - - - ..\packages\Shippo.2.1.8\lib\net45\Shippo.dll - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ShippoExample/packages.config b/ShippoExample/packages.config deleted file mode 100644 index 9037ace..0000000 --- a/ShippoExample/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/ShippoTesting/APIResourceTest.cs b/ShippoTesting/APIResourceTest.cs index 3cc3dc6..cf2912a 100644 --- a/ShippoTesting/APIResourceTest.cs +++ b/ShippoTesting/APIResourceTest.cs @@ -1,16 +1,16 @@ using NUnit.Framework; using System; using System.Net; - using Shippo; - +using Microsoft.Extensions.Logging; +using NUnit.Framework.Legacy; namespace ShippoTesting { [TestFixture] public class APIResourceTest : ShippoTest { public class MockAPIResource : APIResource { - public MockAPIResource(string inputToken) : base(inputToken) {} + public MockAPIResource(ILogger logger, string inputToken) : base(logger, inputToken) {} public WebRequest SetupRequestTest(String method, String url) { return SetupRequest(method, url); @@ -23,11 +23,11 @@ public void TestValidHeader() { String dummyUrl = "http://example.com"; String dummyApiToken = "1234abcd"; String dummyApiVersion = "2014-02-11"; - MockAPIResource resource = new MockAPIResource(dummyApiToken); + MockAPIResource resource = new MockAPIResource(null, dummyApiToken); resource.SetApiVersion(dummyApiVersion); WebRequest request = resource.SetupRequestTest(dummyMethod, dummyUrl); - Assert.AreEqual("ShippoToken " + dummyApiToken, request.Headers.Get("Authorization")); - Assert.AreEqual(dummyApiVersion, request.Headers.Get("Shippo-API-Version")); + ClassicAssert.AreEqual("ShippoToken " + dummyApiToken, request.Headers.Get("Authorization")); + ClassicAssert.AreEqual(dummyApiVersion, request.Headers.Get("Shippo-API-Version")); } [Test] @@ -36,11 +36,11 @@ public void TestValidOAuthHeader() { String dummyUrl = "http://example.com"; String dummyApiToken = "oauth.abcdefffff.yyyyassaldjf="; String dummyApiVersion = "2018-02-08"; - MockAPIResource resource = new MockAPIResource(dummyApiToken); + MockAPIResource resource = new MockAPIResource(null, dummyApiToken); resource.SetApiVersion(dummyApiVersion); WebRequest request = resource.SetupRequestTest(dummyMethod, dummyUrl); - Assert.AreEqual("Bearer " + dummyApiToken, request.Headers.Get("Authorization")); - Assert.AreEqual(dummyApiVersion, request.Headers.Get("Shippo-API-Version")); + ClassicAssert.AreEqual("Bearer " + dummyApiToken, request.Headers.Get("Authorization")); + ClassicAssert.AreEqual(dummyApiVersion, request.Headers.Get("Shippo-API-Version")); } } diff --git a/ShippoTesting/AddressTest.cs b/ShippoTesting/AddressTest.cs index 1766034..c3e93af 100644 --- a/ShippoTesting/AddressTest.cs +++ b/ShippoTesting/AddressTest.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using Shippo; +using NUnit.Framework.Legacy; namespace ShippoTesting { [TestFixture] @@ -11,7 +12,8 @@ public class AddressTest : ShippoTest { public void TestValidCreate() { Address testObject = AddressTest.getDefaultObject(); - Assert.AreEqual(true, testObject.IsComplete); + ClassicAssert.AreEqual( +true, testObject.IsComplete); } [Test] @@ -21,7 +23,8 @@ public void testValidRetrieve() Address retrievedObject; retrievedObject = apiResource.RetrieveAddress((string) testObject.ObjectId); - Assert.AreEqual(testObject.ObjectId, retrievedObject.ObjectId); + ClassicAssert.AreEqual( +testObject.ObjectId, retrievedObject.ObjectId); } public static Address getDefaultObject() diff --git a/ShippoTesting/BatchTest.cs b/ShippoTesting/BatchTest.cs index cb8ff57..707f1bb 100644 --- a/ShippoTesting/BatchTest.cs +++ b/ShippoTesting/BatchTest.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using NUnit.Framework; - +using NUnit.Framework.Legacy; using Shippo; @@ -10,13 +10,13 @@ namespace ShippoTesting [TestFixture] public class BatchTest : ShippoTest { - void HandleFunc() {} + void HandleFunc() { } [Test] public void TestValidCreate() { Batch testBatch = getDefaultObject(); - Assert.AreEqual(ShippoEnums.Statuses.VALIDATING, testBatch.Status); + ClassicAssert.AreEqual(ShippoEnums.Statuses.VALIDATING, testBatch.Status); } [Test] @@ -31,8 +31,10 @@ public void TestValidRetrieve() { Batch batch = getDefaultObject(); Batch retrieve = getAPIResource().RetrieveBatch(batch.ObjectId, 0, ShippoEnums.ObjectResults.none); - Assert.AreEqual(batch.ObjectId, retrieve.ObjectId); - Assert.AreEqual(batch.ObjectCreated, retrieve.ObjectCreated); + ClassicAssert.AreEqual( +batch.ObjectId, retrieve.ObjectId); + ClassicAssert.AreEqual( +batch.ObjectCreated, retrieve.ObjectCreated); } [Test] @@ -41,56 +43,60 @@ public void TestInvalidRetrieve() Assert.That(() => getAPIResource().RetrieveBatch("INVALID_ID", 0, ShippoEnums.ObjectResults.none), Throws.TypeOf()); } -/* - [Test] - public void TestValidAddShipmentToBatch() - { - setLive(true);//Temporary work around for batch request bug with test token - Batch batch = getDefaultObject(); - Assert.AreEqual(batch.Status, ShippoEnums.Statuses.VALIDATING); - - List shipmentIds = new List(); - Shipment shipment = ShipmentTest.getDefaultObject(); - shipmentIds.Add(shipment.ObjectId); - - Batch retrieve = getValidBatch(batch.ObjectId); - Batch newBatch = getAPIResource().AddShipmentsToBatch(retrieve.ObjectId, shipmentIds); - setLive(false); - Assert.AreEqual(retrieve.BatchShipments.Count + shipmentIds.Count, newBatch.BatchShipments.Count); - } -*/ + /* + [Test] + public void TestValidAddShipmentToBatch() + { + setLive(true);//Temporary work around for batch request bug with test token + Batch batch = getDefaultObject(); + ClassicAssert.AreEqual( + batch.Status, ShippoEnums.Statuses.VALIDATING); + + List shipmentIds = new List(); + Shipment shipment = ShipmentTest.getDefaultObject(); + shipmentIds.Add(shipment.ObjectId); + + Batch retrieve = getValidBatch(batch.ObjectId); + Batch newBatch = getAPIResource().AddShipmentsToBatch(retrieve.ObjectId, shipmentIds); + setLive(false); + ClassicAssert.AreEqual( + retrieve.BatchShipments.Count + shipmentIds.Count, newBatch.BatchShipments.Count); + } + */ [Test] public void TestInvalidAddShipmentToBatch() { List shipmentIds = new List(); shipmentIds.Add("123"); - Assert.That(() => getAPIResource().AddShipmentsToBatch("INVALID_ID", shipmentIds), + Assert.That(() => getAPIResource().AddShipmentsToBatch("INVALID_ID", shipmentIds), Throws.TypeOf()); } -/* - [Test] - public void TestValidRemoveShipmentsFromBatch() - { - setLive(true); - Batch batch = getDefaultObject(); - Assert.AreEqual(batch.Status, ShippoEnums.Statuses.VALIDATING); - - List shipmentIds = new List(); - Shipment shipment = ShipmentTest.getDefaultObject(); - shipmentIds.Add(shipment.ObjectId); - - Batch retrieve = getValidBatch(batch.ObjectId); - Batch addBatch = getAPIResource().AddShipmentsToBatch(retrieve.ObjectId, shipmentIds); - - string removeId = addBatch.BatchShipments.Results[0].ObjectId; - List shipmentsToRemove = new List(); - shipmentsToRemove.Add(removeId); - - Batch removeBatch = getAPIResource().RemoveShipmentsFromBatch(batch.ObjectId, shipmentsToRemove); - setLive(false); - Assert.AreEqual(retrieve.BatchShipments.Count, removeBatch.BatchShipments.Count); - } -*/ + /* + [Test] + public void TestValidRemoveShipmentsFromBatch() + { + setLive(true); + Batch batch = getDefaultObject(); + ClassicAssert.AreEqual( + batch.Status, ShippoEnums.Statuses.VALIDATING); + + List shipmentIds = new List(); + Shipment shipment = ShipmentTest.getDefaultObject(); + shipmentIds.Add(shipment.ObjectId); + + Batch retrieve = getValidBatch(batch.ObjectId); + Batch addBatch = getAPIResource().AddShipmentsToBatch(retrieve.ObjectId, shipmentIds); + + string removeId = addBatch.BatchShipments.Results[0].ObjectId; + List shipmentsToRemove = new List(); + shipmentsToRemove.Add(removeId); + + Batch removeBatch = getAPIResource().RemoveShipmentsFromBatch(batch.ObjectId, shipmentsToRemove); + setLive(false); + ClassicAssert.AreEqual( + retrieve.BatchShipments.Count, removeBatch.BatchShipments.Count); + } + */ [Test] public void TestInvalidRemoveShipmentsFromBatch() { @@ -100,15 +106,16 @@ public void TestInvalidRemoveShipmentsFromBatch() Throws.TypeOf()); } -/* [Test] - public void TestValidPurchase() - { - Batch batch = getDefaultObject(); - Batch retrieve = getValidBatch(batch.ObjectId); - Batch purchase = getAPIResource().PurchaseBatch(retrieve.ObjectId); - Assert.AreEqual(ShippoEnums.Statuses.PURCHASING, purchase.Status); - } -*/ + /* [Test] + public void TestValidPurchase() + { + Batch batch = getDefaultObject(); + Batch retrieve = getValidBatch(batch.ObjectId); + Batch purchase = getAPIResource().PurchaseBatch(retrieve.ObjectId); + ClassicAssert.AreEqual( + ShippoEnums.Statuses.PURCHASING, purchase.Status); + } + */ [Test] public void TestInvalidPurchase() { @@ -124,7 +131,8 @@ public Batch getValidBatch(String id) { Batch batch; int retries = 10; - for (; retries > 0; retries--) { + for (; retries > 0; retries--) + { batch = getAPIResource().RetrieveBatch(id, 0, ShippoEnums.ObjectResults.none); if (batch.Status != ShippoEnums.Statuses.VALIDATING) return batch; @@ -140,16 +148,19 @@ public static Batch getDefaultObject() // other words, remove the depedence on a USPS carrier account to exist. ShippoCollection carrierAccounts = getAPIResource().AllCarrierAccount(); string defaultCarrierAccount = ""; - foreach (CarrierAccount account in carrierAccounts) { + foreach (CarrierAccount account in carrierAccounts) + { if (account.Carrier.ToString() == "usps") defaultCarrierAccount = account.ObjectId; } + + Address addressFrom = Address.createForPurchase("Mr. Hippo", "965 Mission St.", "Ste 201", "SF", "CA", "94103", "US", "4151234567", "ship@gmail.com"); Address addressTo = Address.createForPurchase("Mrs. Hippo", "965 Missions St.", "Ste 202", "SF", "CA", "94103", "US", "4151234568", "msship@gmail.com"); - Parcel[] parcels = {Parcel.createForShipment(5, 5, 5, "in", 2, "oz")}; + Parcel[] parcels = { Parcel.createForShipment(5, 5, 5, "in", 2, "oz") }; Shipment shipment = Shipment.createForBatch(addressFrom, addressTo, parcels); BatchShipment batchShipment = BatchShipment.createForBatchShipments(defaultCarrierAccount, "usps_priority", shipment); @@ -158,7 +169,7 @@ public static Batch getDefaultObject() Batch batch = getAPIResource().CreateBatch(defaultCarrierAccount, "usps_priority", ShippoEnums.LabelFiletypes.PDF_4x6, "BATCH #170", batchShipments); - Assert.AreEqual(ShippoEnums.Statuses.VALIDATING, batch.Status); + ClassicAssert.AreEqual(ShippoEnums.Statuses.VALIDATING, batch.Status); return batch; } } diff --git a/ShippoTesting/CarrierAccountTest.cs b/ShippoTesting/CarrierAccountTest.cs index d927909..70b6435 100644 --- a/ShippoTesting/CarrierAccountTest.cs +++ b/ShippoTesting/CarrierAccountTest.cs @@ -1,25 +1,26 @@ using NUnit.Framework; using System; using System.Collections; - using Shippo; +using NUnit.Framework.Legacy; namespace ShippoTesting { [TestFixture] - public class CarrierAccountTest : ShippoTest { + public class CarrierAccountTest : ShippoTest + { [Test] public void TestValidRetrieve() { ShippoCollection testObject = CarrierAccountTest.getDefaultObject(); - Assert.Greater(testObject.Data.Count, 0); + Assert.That(testObject.Data.Count > 0); } [Test] public void TestParametersRetreive() { ShippoCollection testObject = CarrierAccountTest.getParameterObject(); - Assert.AreEqual(1, testObject.Data.Count); + ClassicAssert.AreEqual(1, testObject.Data.Count); } public static ShippoCollection getDefaultObject() diff --git a/ShippoTesting/CustomsDeclarationTest.cs b/ShippoTesting/CustomsDeclarationTest.cs index 9164ce5..0fad6ce 100644 --- a/ShippoTesting/CustomsDeclarationTest.cs +++ b/ShippoTesting/CustomsDeclarationTest.cs @@ -6,17 +6,21 @@ using System.Collections.Generic; using Shippo; +using NUnit.Framework.Legacy; -namespace ShippoTesting { +namespace ShippoTesting +{ [TestFixture] - public class CustomsDeclarationTest : ShippoTest { + public class CustomsDeclarationTest : ShippoTest + { [Test] public void TestValidCreate() { CustomsDeclaration testObject = CustomsDeclarationTest.getDefaultObject(); - Assert.AreEqual("VALID", testObject.ObjectState); + ClassicAssert.AreEqual( +"VALID", testObject.ObjectState); } [Test] @@ -25,36 +29,37 @@ public void testValidRetrieve() CustomsDeclaration testObject = CustomsDeclarationTest.getDefaultObject(); CustomsDeclaration retrievedObject; - retrievedObject = apiResource.RetrieveCustomsDeclaration((string) testObject.ObjectId); - Assert.AreEqual(testObject.ObjectId, retrievedObject.ObjectId); + retrievedObject = apiResource.RetrieveCustomsDeclaration((string)testObject.ObjectId); + ClassicAssert.AreEqual( +testObject.ObjectId, retrievedObject.ObjectId); } [Test] - public void testValidRetrieveWithAddressImporter () + public void testValidRetrieveWithAddressImporter() { CustomsDeclaration testObject = CustomsDeclarationTest.getDefaultObject_2(); CustomsDeclaration retrievedObject; - retrievedObject = apiResource.RetrieveCustomsDeclaration ((string)testObject.ObjectId); + retrievedObject = apiResource.RetrieveCustomsDeclaration((string)testObject.ObjectId); Console.Write(retrievedObject.AddressImporter.IsComplete); - Assert.AreEqual (testObject.ObjectId, retrievedObject.ObjectId); - Assert.IsNotNull(retrievedObject.AddressImporter); - Assert.AreEqual(testObject.AddressImporter.ObjectId, retrievedObject.AddressImporter.ObjectId); - Assert.AreEqual(true, retrievedObject.AddressImporter.IsComplete); - Assert.AreEqual("Undefault New Wu", retrievedObject.AddressImporter.Name); - Assert.AreEqual("Shippo", retrievedObject.AddressImporter.Company); - Assert.AreEqual("", retrievedObject.AddressImporter.StreetNo); - Assert.AreEqual("215 Clayton St", retrievedObject.AddressImporter.Street1); - Assert.AreEqual("", retrievedObject.AddressImporter.Street2); - Assert.AreEqual("", retrievedObject.AddressImporter.Street3); - Assert.AreEqual("San Francisco", retrievedObject.AddressImporter.City); - Assert.AreEqual("CA", retrievedObject.AddressImporter.State); - Assert.AreEqual("94117-1913", retrievedObject.AddressImporter.Zip); - Assert.AreEqual("US", retrievedObject.AddressImporter.Country); - Assert.AreEqual("0015553419393", retrievedObject.AddressImporter.Phone); - Assert.AreEqual("laura@goshipppo.com", retrievedObject.AddressImporter.Email); - Assert.AreEqual(true, retrievedObject.AddressImporter.IsResidential); - Assert.AreEqual(true, retrievedObject.AddressImporter.Test); + ClassicAssert.AreEqual(testObject.ObjectId, retrievedObject.ObjectId); + Assert.That(retrievedObject.AddressImporter != null); + ClassicAssert.AreEqual(testObject.AddressImporter.ObjectId, retrievedObject.AddressImporter.ObjectId); + ClassicAssert.AreEqual(true, retrievedObject.AddressImporter.IsComplete); + ClassicAssert.AreEqual("Undefault New Wu", retrievedObject.AddressImporter.Name); + ClassicAssert.AreEqual("Shippo", retrievedObject.AddressImporter.Company); + ClassicAssert.AreEqual("", retrievedObject.AddressImporter.StreetNo); + ClassicAssert.AreEqual("215 Clayton St", retrievedObject.AddressImporter.Street1); + ClassicAssert.AreEqual("", retrievedObject.AddressImporter.Street2); + ClassicAssert.AreEqual("", retrievedObject.AddressImporter.Street3); + ClassicAssert.AreEqual("San Francisco", retrievedObject.AddressImporter.City); + ClassicAssert.AreEqual("CA", retrievedObject.AddressImporter.State); + ClassicAssert.AreEqual("94117-1913", retrievedObject.AddressImporter.Zip); + ClassicAssert.AreEqual("US", retrievedObject.AddressImporter.Country); + ClassicAssert.AreEqual("0015553419393", retrievedObject.AddressImporter.Phone); + ClassicAssert.AreEqual("laura@goshipppo.com", retrievedObject.AddressImporter.Email); + ClassicAssert.AreEqual(true, retrievedObject.AddressImporter.IsResidential); + ClassicAssert.AreEqual(true, retrievedObject.AddressImporter.Test); } [Test] @@ -65,7 +70,7 @@ public void testListAll() parameters.Add("page", "1"); var parcels = apiResource.AllCustomsDeclarations(parameters); - Assert.AreNotEqual(0, parcels.Data.Count); + Assert.That(parcels.Data.Count > 0); } public static CustomsDeclaration getDefaultObject() @@ -87,43 +92,43 @@ public static CustomsDeclaration getDefaultObject() parameters.Add("certify_signer", "Laura Behrens Wu"); parameters.Add("disclaimer", ""); parameters.Add("incoterm", ""); - + JArray customsItems = new JArray(); - customsItems.Add((string) customsItem.ObjectId); + customsItems.Add((string)customsItem.ObjectId); parameters.Add("items", customsItems); parameters.Add("metadata", "Order ID #123123"); return getAPIResource().CreateCustomsDeclaration(parameters); } - public static CustomsDeclaration getDefaultObject_2 () + public static CustomsDeclaration getDefaultObject_2() { CustomsItem customsItem = CustomsItemTest.getDefaultObject(); Address addressImporter = AddressTest.getDefaultObject(); - Hashtable parameters = new Hashtable (); - parameters.Add ("exporter_reference", ""); - parameters.Add ("importer_reference", ""); - parameters.Add ("contents_type", "MERCHANDISE"); - parameters.Add ("contents_explanation", "T-Shirt purchase"); - parameters.Add ("invoice", "#123123"); - parameters.Add ("license", ""); - parameters.Add ("certificate", ""); - parameters.Add ("notes", ""); - parameters.Add ("eel_pfc", "NOEEI_30_37_a"); - parameters.Add ("aes_itn", ""); - parameters.Add ("non_delivery_option", "ABANDON"); - parameters.Add ("certify", true); - parameters.Add ("certify_signer", "Laura Behrens Wu"); - parameters.Add ("address_importer", addressImporter.ObjectId); - parameters.Add ("disclaimer", ""); - parameters.Add ("incoterm", ""); - - JArray customsItems = new JArray (); - customsItems.Add ((string)customsItem.ObjectId); - - parameters.Add ("items", customsItems); - parameters.Add ("metadata", "Order ID #123123"); - return getAPIResource ().CreateCustomsDeclaration (parameters); + Hashtable parameters = new Hashtable(); + parameters.Add("exporter_reference", ""); + parameters.Add("importer_reference", ""); + parameters.Add("contents_type", "MERCHANDISE"); + parameters.Add("contents_explanation", "T-Shirt purchase"); + parameters.Add("invoice", "#123123"); + parameters.Add("license", ""); + parameters.Add("certificate", ""); + parameters.Add("notes", ""); + parameters.Add("eel_pfc", "NOEEI_30_37_a"); + parameters.Add("aes_itn", ""); + parameters.Add("non_delivery_option", "ABANDON"); + parameters.Add("certify", true); + parameters.Add("certify_signer", "Laura Behrens Wu"); + parameters.Add("address_importer", addressImporter.ObjectId); + parameters.Add("disclaimer", ""); + parameters.Add("incoterm", ""); + + JArray customsItems = new JArray(); + customsItems.Add((string)customsItem.ObjectId); + + parameters.Add("items", customsItems); + parameters.Add("metadata", "Order ID #123123"); + return getAPIResource().CreateCustomsDeclaration(parameters); } } } diff --git a/ShippoTesting/CustomsItemTest.cs b/ShippoTesting/CustomsItemTest.cs index 2a3281e..6b49244 100644 --- a/ShippoTesting/CustomsItemTest.cs +++ b/ShippoTesting/CustomsItemTest.cs @@ -3,6 +3,7 @@ using System.Collections; using Shippo; +using NUnit.Framework.Legacy; namespace ShippoTesting { @@ -13,7 +14,8 @@ public class CustomsItemTest : ShippoTest { public void TestValidCreate() { CustomsItem testObject = CustomsItemTest.getDefaultObject(); - Assert.AreEqual("VALID", testObject.ObjectState); + ClassicAssert.AreEqual( +"VALID", testObject.ObjectState); } [Test] @@ -23,7 +25,8 @@ public void testValidRetrieve() CustomsItem retrievedObject; retrievedObject = apiResource.RetrieveCustomsItem((string) testObject.ObjectId); - Assert.AreEqual(testObject.ObjectId, retrievedObject.ObjectId); + ClassicAssert.AreEqual( +testObject.ObjectId, retrievedObject.ObjectId); } [Test] @@ -34,7 +37,7 @@ public void testListAll() parameters.Add("page", "1"); var parcels = apiResource.AllCustomsItems(parameters); - Assert.AreNotEqual(0, parcels.Data.Count); + Assert.That(parcels.Data.Count != 0); } public static CustomsItem getDefaultObject() diff --git a/ShippoTesting/DotEnv.cs b/ShippoTesting/DotEnv.cs new file mode 100644 index 0000000..f8b5352 --- /dev/null +++ b/ShippoTesting/DotEnv.cs @@ -0,0 +1,26 @@ +using System; +using System.IO; + +namespace ShippoTesting +{ + public static class DotEnv + { + public static void Load(string filePath) + { + if (!File.Exists(filePath)) + return; + + foreach (var line in File.ReadAllLines(filePath)) + { + var parts = line.Split( + '=', + StringSplitOptions.RemoveEmptyEntries); + + if (parts.Length != 2) + continue; + + Environment.SetEnvironmentVariable(parts[0], parts[1]); + } + } + } +} \ No newline at end of file diff --git a/ShippoTesting/ManifestTest.cs b/ShippoTesting/ManifestTest.cs index 1493dc4..379f921 100644 --- a/ShippoTesting/ManifestTest.cs +++ b/ShippoTesting/ManifestTest.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Shippo; +using NUnit.Framework.Legacy; namespace ShippoTesting @@ -18,27 +19,15 @@ public void TestInvalidCreate() Assert.That(() => ManifestTest.getInvalidObject(), Throws.TypeOf()); } - [Test] - public void testValidRetrieve() - { - Manifest testObject = ManifestTest.getDefaultObject(); - Manifest retrievedObject; - - retrievedObject = apiResource.RetrieveManifest((string) testObject.ObjectId); - Assert.AreEqual(testObject.ObjectId, retrievedObject.ObjectId); - } + // [Test] + // public void testValidRetrieve() + // { + // Manifest testObject = ManifestTest.getDefaultObject(); + // Manifest retrievedObject; - [Test] - public void testListAll() - { - Hashtable parameters = new Hashtable(); - parameters.Add("results", "1"); - parameters.Add("page", "1"); - - var Manifests = apiResource.AllManifests(parameters); - // Assert.AreEqual(0, Manifests.Data.Count); - // Kind of a none sensical test. Taking no account of previous test cases causing side effects - } + // retrievedObject = apiResource.RetrieveManifest((string) testObject.ObjectId); + // ClassicAssert.AreEqual(testObject.ObjectId, retrievedObject.ObjectId); + // } public static Manifest getDefaultObject() { @@ -52,7 +41,7 @@ public static Manifest getDefaultObject() parameters0.Add("shipment_date", now); parameters0.Add("insurance_amount", "30"); parameters0.Add("insurance_currency", "USD"); - parameters0.Add("extra", "{signature_confirmation: true}"); + // parameters0.Add("extra", "{signature_confirmation: true}"); parameters0.Add("customs_declaration", ""); parameters0.Add("metadata", "Customer ID 123456"); parameters0.Add("async", false); @@ -94,7 +83,7 @@ public static Manifest getInvalidObject() parameters0.Add("shipment_date", now); parameters0.Add("insurance_amount", "30"); parameters0.Add("insurance_currency", "USD"); - parameters0.Add("extra", "{signature_confirmation: true}"); + // parameters0.Add("extra", "{signature_confirmation: true}"); parameters0.Add("customs_declaration", ""); parameters0.Add("metadata", "Customer ID 123456"); parameters0.Add("async", false); diff --git a/ShippoTesting/ParcelTest.cs b/ShippoTesting/ParcelTest.cs index ee9da9b..bc47b90 100644 --- a/ShippoTesting/ParcelTest.cs +++ b/ShippoTesting/ParcelTest.cs @@ -3,17 +3,20 @@ using System.Collections; using Shippo; +using NUnit.Framework.Legacy; -namespace ShippoTesting { +namespace ShippoTesting +{ [TestFixture] - public class ParcelTest : ShippoTest { + public class ParcelTest : ShippoTest + { [Test] public void TestValidCreate() { Parcel testObject = ParcelTest.getDefaultObject(); - Assert.AreEqual("VALID", testObject.ObjectState); + ClassicAssert.AreEqual("VALID", testObject.ObjectState); } [Test] @@ -22,8 +25,8 @@ public void testValidRetrieve() Parcel testObject = ParcelTest.getDefaultObject(); Parcel retrievedObject; - retrievedObject = apiResource.RetrieveParcel((string) testObject.ObjectId); - Assert.AreEqual(testObject.ObjectId, retrievedObject.ObjectId); + retrievedObject = apiResource.RetrieveParcel((string)testObject.ObjectId); + ClassicAssert.AreEqual(testObject.ObjectId, retrievedObject.ObjectId); } [Test] @@ -34,7 +37,7 @@ public void testListAll() parameters.Add("page", "1"); var parcels = apiResource.AllParcels(parameters); - Assert.AreNotEqual(0, parcels.Data.Count); + Assert.That(parcels.Data.Count > 0); } public static Parcel getDefaultObject() diff --git a/ShippoTesting/RateTest.cs b/ShippoTesting/RateTest.cs index 0ae73f9..d283c4d 100644 --- a/ShippoTesting/RateTest.cs +++ b/ShippoTesting/RateTest.cs @@ -4,6 +4,7 @@ using System.Threading; using Shippo; +using System.Security.Cryptography.X509Certificates; namespace ShippoTesting { @@ -14,7 +15,7 @@ public class RateTest : ShippoTest { public void TestValidCreate() { ShippoCollection testObject = RateTest.getDefaultObject(); - Assert.IsNotNull(testObject.Data); + Assert.That(testObject.Data != null); } public static ShippoCollection getDefaultObject() diff --git a/ShippoTesting/ShipmentTest.cs b/ShippoTesting/ShipmentTest.cs index 2dd66d9..0301fc5 100644 --- a/ShippoTesting/ShipmentTest.cs +++ b/ShippoTesting/ShipmentTest.cs @@ -3,17 +3,21 @@ using System.Collections; using Shippo; +using NUnit.Framework.Legacy; -namespace ShippoTesting { +namespace ShippoTesting +{ [TestFixture] - public class ShipmentTest : ShippoTest { + public class ShipmentTest : ShippoTest + { [Test] public void TestValidCreate() { Shipment testObject = ShipmentTest.getDefaultObject(); - Assert.AreEqual("SUCCESS", testObject.Status); + ClassicAssert.AreEqual( +"SUCCESS", testObject.Status); } [Test] @@ -22,8 +26,8 @@ public void testValidRetrieve() Shipment testObject = ShipmentTest.getDefaultObject(); Shipment retrievedObject; - retrievedObject = apiResource.RetrieveShipment((string) testObject.ObjectId); - Assert.AreEqual(testObject.ObjectId, retrievedObject.ObjectId); + retrievedObject = apiResource.RetrieveShipment((string)testObject.ObjectId); + ClassicAssert.AreEqual(testObject.ObjectId, retrievedObject.ObjectId); } [Test] @@ -34,7 +38,7 @@ public void testListAll() parameters.Add("page", "1"); var parcels = apiResource.AllShipments(parameters); - Assert.AreNotEqual(0, parcels.Data.Count); + Assert.That(parcels.Data.Count != 0); } public static Shipment getDefaultObject() @@ -45,11 +49,11 @@ public static Shipment getDefaultObject() Parcel parcel = ParcelTest.getDefaultObject(); parameters.Add("address_from", addressFrom.ObjectId); parameters.Add("address_to", addressTo.ObjectId); - parameters.Add("parcels", new String[]{ parcel.ObjectId}); + parameters.Add("parcels", new String[] { parcel.ObjectId }); parameters.Add("shipment_date", now); parameters.Add("insurance_amount", "30"); parameters.Add("insurance_currency", "USD"); - parameters.Add("extra", "{signature_confirmation: true}"); + // parameters.Add("extra", "{signature_confirmation: true}"); parameters.Add("customs_declaration", ""); parameters.Add("metadata", "Customer ID 123456"); parameters.Add("async", false); diff --git a/ShippoTesting/ShippoTest.cs b/ShippoTesting/ShippoTest.cs index ef303b1..ee6c621 100644 --- a/ShippoTesting/ShippoTest.cs +++ b/ShippoTesting/ShippoTest.cs @@ -1,34 +1,47 @@ using NUnit.Framework; using System; using System.Collections; - using Shippo; +using System.IO; +using Microsoft.Extensions.Logging; - -namespace ShippoTesting { +namespace ShippoTesting +{ [TestFixture] - public class ShippoTest { - static internal APIResource apiResource; + public class ShippoTest + { + static internal APIResource apiResource; static internal APIResource liveAPI; static internal Boolean live; static internal String now; public APIResource staticAPIResource; - [SetUp] public void Init() + [SetUp] + public void Init() { + var root = Directory.GetCurrentDirectory(); + Console.WriteLine($"dir: {root}"); + + var dotenv = Path.Combine(root, ".env"); + DotEnv.Load(dotenv); + String token = Environment.GetEnvironmentVariable("Wrapper_Token"); - apiResource = new APIResource(token); - liveAPI = new APIResource(Environment.GetEnvironmentVariable("Live_Token")); + Console.WriteLine($"Token: {token}"); + using ILoggerFactory factory = LoggerFactory.Create(builder => builder.AddConsole()); + ILogger logger = factory.CreateLogger("Program"); + apiResource = new APIResource(logger, token); + liveAPI = new APIResource(logger, Environment.GetEnvironmentVariable("Live_Token")); now = DateTime.Now.ToString("yyyy-MM-dd HH':'mm':'ss"); live = false; } public static APIResource getAPIResource() { - return live?liveAPI:apiResource; + return live ? liveAPI : apiResource; } - public static void setLive(Boolean live_api=true){ + public static void setLive(Boolean live_api = true) + { live = live_api; } diff --git a/ShippoTesting/ShippoTesting.csproj b/ShippoTesting/ShippoTesting.csproj index 28009dc..e27ff07 100644 --- a/ShippoTesting/ShippoTesting.csproj +++ b/ShippoTesting/ShippoTesting.csproj @@ -1,67 +1,24 @@ - - + - Debug - AnyCPU - 8.0.30703 - 2.0 - {4AF39DE0-2FA9-43D1-9254-CF8546FF22C8} - Library - ShippoTesting - ShippoTesting - v4.5 + net7.0 + false - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - - - full - true - bin\Release - prompt - 4 - false - - - - - ..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll - - - ..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll - - + - - - - - - - - - - - - - - + - + - - {218CF4C2-C457-43E4-9D1B-0880D10181FF} - Shippo - + + + + + + - + + PreserveNewest + - + \ No newline at end of file diff --git a/ShippoTesting/TrackTest.cs b/ShippoTesting/TrackTest.cs index 7fee12c..d76f995 100644 --- a/ShippoTesting/TrackTest.cs +++ b/ShippoTesting/TrackTest.cs @@ -1,7 +1,7 @@ using NUnit.Framework; using System; using System.Collections; - +using NUnit.Framework.Legacy; using Shippo; @@ -17,9 +17,9 @@ public class TrackTest : ShippoTest public void TestValidGetStatus() { Track track = getAPIResource().RetrieveTracking(CARRIER, TRACKING_NO); - Assert.AreEqual(TRACKING_NO, track.TrackingNumber); - Assert.IsNotNull(track.TrackingStatus); - Assert.IsNotNull(track.TrackingHistory); + ClassicAssert.AreEqual(TRACKING_NO, track.TrackingNumber); + Assert.That(track.TrackingStatus!=null); + Assert.That(track.TrackingHistory!=null); } [Test] @@ -38,8 +38,8 @@ public void TestValidRegisterWebhook() parameters.Add("carrier", CARRIER); parameters.Add("tracking_number", track.TrackingNumber); Track register = getAPIResource().RegisterTrackingWebhook(parameters); - Assert.IsNotNull(register.TrackingNumber); - Assert.IsNotNull(register.TrackingHistory); + Assert.That(register.TrackingNumber !=null); + Assert.That(register.TrackingHistory!=null); } [Test] diff --git a/ShippoTesting/TransactionTest.cs b/ShippoTesting/TransactionTest.cs index e2f359a..1779ee7 100644 --- a/ShippoTesting/TransactionTest.cs +++ b/ShippoTesting/TransactionTest.cs @@ -15,7 +15,8 @@ public class TransactionTest : ShippoTest { public void TestValidCreate() { Transaction testObject = TransactionTest.getDefaultObject(); - Assert.AreEqual("VALID", testObject.ObjectState); + ClassicAssert.AreEqual( +"VALID", testObject.ObjectState); } [Test] @@ -25,7 +26,8 @@ public void testValidRetrieve() Transaction retrievedObject; retrievedObject = apiResource.RetrieveTransaction((string) testObject.ObjectId); - Assert.AreEqual(testObject.ObjectId, retrievedObject.ObjectId); + ClassicAssert.AreEqual( +testObject.ObjectId, retrievedObject.ObjectId); } */ [Test] @@ -36,7 +38,7 @@ public void testListAll() parameters.Add("page", "1"); var parcels = apiResource.AllTransactions(parameters); - Assert.AreNotEqual(0, parcels.Data.Count); + Assert.That(parcels.Data.Count > 0); } public static Transaction getDefaultObject()