Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix naming scheme, property nullabilities #321

Merged
merged 9 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@
- Static methods (i.e. create, retrieve, retrieve all of a resource) exist in services, accessed via property of the client (e.g. `myClient.Address.Create()`).
- Instance methods (i.e. update, delete) accessed on instance of a resource (i.e. `myShipment.Update()`).
- Library better supports different API versions (i.e. `v2`, `beta`).
- All objects now share a common base set of properties, including `id`, `created_at`, `updated_at`, and `mode`.
- Beta features accessed via, e.g. `myClient.Beta.EndShipper.Create()`.
- All properties are now title-cased rather than snake-cased to match standard .NET naming conventions.
- e.g. `myShipment.id` is now `myShipment.Id`, `myAddress.federal_tax_id` is now `myAddress.FederalTaxId`, `myTrackerCollection.has_more` is now `myTrackerCollection.HasMore`.
- Some properties have been renamed to avoid naming conflicts:
- `Rate.rate` is now `Rate.Price`
- `Message.message` is now `Message.Text`
- All properties are now nullable.
- Almost all properties will be assigned a value during JSON deserialization. This is mostly to address compiler warnings.
- Users can proceed with the assumption that any given property will not be null.
- All objects now share a common base set of properties, including `Id`, `CreatedAt`, `UpdatedAt`, and `Mode`.
- Under the hood improvements:
- Underlying `Request`-`Client`-`ClientConfiguration` relationship has been re-architected to allow for thread safety.
- Process of generating an API request has been standardized and simplified.
- Improved accessibility levels of internal functions, to prevent accidental use by end users.
- Files have been organized into a more logical structure.
- Methods and properties have been organized (e.g. methods ordered by CRUD, properties ordered alphabetically).
- Dependencies updated to latest versions, including `RestSharp` v108
- `EndShipper` moved from beta to general availability.
- Dependencies updated to latest versions, including `RestSharp` v108.

## v3.4.0 (2022-08-02)

Expand Down
26 changes: 13 additions & 13 deletions EasyPost.Tests/AddressTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public async Task TestCreate()
Address address = await CreateBasicAddress();

Assert.IsType<Address>(address);
Assert.StartsWith("adr_", address.id);
Assert.Equal("388 Townsend St", address.street1);
Assert.StartsWith("adr_", address.Id);
Assert.Equal("388 Townsend St", address.Street1);
}

[Fact]
Expand All @@ -38,8 +38,8 @@ public async Task TestCreateVerify()
Address address = await Client.Address.Create(addressData);

Assert.IsType<Address>(address);
Assert.StartsWith("adr_", address.id);
Assert.Equal("417 MONTGOMERY ST FL 5", address.street1);
Assert.StartsWith("adr_", address.Id);
Assert.Equal("417 MONTGOMERY ST FL 5", address.Street1);
}

[Fact]
Expand All @@ -54,8 +54,8 @@ public async Task TestCreateVerifyStrict()
Address address = await Client.Address.Create(addressData);

Assert.IsType<Address>(address);
Assert.StartsWith("adr_", address.id);
Assert.Equal("388 TOWNSEND ST APT 20", address.street1);
Assert.StartsWith("adr_", address.Id);
Assert.Equal("388 TOWNSEND ST APT 20", address.Street1);
}

[Fact]
Expand All @@ -65,9 +65,9 @@ public async Task TestAll()
UseVCR("all");

AddressCollection addressCollection = await Client.Address.All(new Dictionary<string, object> { { "page_size", Fixture.PageSize } });
List<Address> addresses = addressCollection.addresses;
List<Address> addresses = addressCollection.Addresses;

Assert.True(addressCollection.has_more);
Assert.True(addressCollection.HasMore);
Assert.True(addresses.Count <= Fixture.PageSize);
foreach (Address item in addresses)
{
Expand All @@ -83,7 +83,7 @@ public async Task TestRetrieve()

Address address = await Client.Address.Create(Fixture.BasicAddress);

Address retrievedAddress = await Client.Address.Retrieve(address.id);
Address retrievedAddress = await Client.Address.Retrieve(address.Id);

Assert.IsType<Address>(retrievedAddress);
Assert.Equal(address, retrievedAddress);
Expand All @@ -101,8 +101,8 @@ public async Task TestCreateAndVerify()
Address address = await Client.Address.CreateAndVerify(addressData);

Assert.IsType<Address>(address);
Assert.StartsWith("adr_", address.id);
Assert.Equal("388 TOWNSEND ST APT 20", address.street1);
Assert.StartsWith("adr_", address.Id);
Assert.Equal("388 TOWNSEND ST APT 20", address.Street1);
}

[Fact]
Expand All @@ -116,8 +116,8 @@ public async Task TestVerify()
address = await address.Verify();

Assert.IsType<Address>(address);
Assert.StartsWith("adr_", address.id);
Assert.Equal("388 TOWNSEND ST APT 20", address.street1);
Assert.StartsWith("adr_", address.Id);
Assert.Equal("388 TOWNSEND ST APT 20", address.Street1);
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions EasyPost.Tests/ApiKeyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public async Task TestAllApiKeys()

// API keys will be censored, so we'll just check for the existence of the list
Assert.NotNull(collection);
Assert.NotNull(collection.keys);
Assert.NotNull(collection.children);
Assert.NotNull(collection.Keys);
Assert.NotNull(collection.Children);
}

#endregion
Expand Down
32 changes: 21 additions & 11 deletions EasyPost.Tests/BatchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public async Task TestCreate()
Batch batch = await CreateBasicBatch();

Assert.IsType<Batch>(batch);
Assert.StartsWith("batch_", batch.id);
Assert.NotNull(batch.shipments);
Assert.StartsWith("batch_", batch.Id);
Assert.NotNull(batch.Shipments);
}

[Fact]
Expand All @@ -37,8 +37,8 @@ public async Task TestCreateAndBuy()
Batch batch = await Client.Batch.CreateAndBuy(new Dictionary<string, object> { { "shipments", new List<Dictionary<string, object>> { Fixture.OneCallBuyShipment } } });

Assert.IsType<Batch>(batch);
Assert.StartsWith("batch_", batch.id);
Assert.Equal(1, batch.num_shipments);
Assert.StartsWith("batch_", batch.Id);
Assert.Equal(1, batch.NumShipments);
}

[Fact]
Expand All @@ -49,9 +49,9 @@ public async Task TestAll()

BatchCollection batchCollection = await Client.Batch.All(new Dictionary<string, object> { { "page_size", Fixture.PageSize } });

List<Batch> batches = batchCollection.batches;
List<Batch> batches = batchCollection.Batches;

Assert.True(batchCollection.has_more);
Assert.True(batchCollection.HasMore);
Assert.True(batches.Count <= Fixture.PageSize);
foreach (Batch item in batches)
{
Expand All @@ -71,11 +71,11 @@ public async Task TestAddRemoveShipments()

batch = await batch.AddShipments(new List<Shipment> { shipment });

Assert.Equal(1, batch.num_shipments);
Assert.Equal(1, batch.NumShipments);

batch = await batch.RemoveShipments(new List<Shipment> { shipment });

Assert.Equal(0, batch.num_shipments);
Assert.Equal(0, batch.NumShipments);
}

[Fact]
Expand All @@ -89,7 +89,7 @@ public async Task TestBuy()
batch = await batch.Buy();

Assert.IsType<Batch>(batch);
Assert.Equal(1, batch.num_shipments);
Assert.Equal(1, batch.NumShipments);
}

[Fact]
Expand All @@ -100,6 +100,11 @@ public async Task TestCreateScanForm()

Batch batch = await CreateOneCallBuyBatch();

if (IsRecording()) // Yes, this is needed. Otherwise, the API says we can't modify a batch while it's being created.
{
Thread.Sleep(10000); // Wait enough time to process
}

batch = await batch.Buy();

if (IsRecording())
Expand All @@ -121,6 +126,11 @@ public async Task TestLabel()

Batch batch = await CreateOneCallBuyBatch();

if (IsRecording()) // Yes, this is needed. Otherwise, the API says we can't modify a batch while it's being created.
{
Thread.Sleep(10000); // Wait enough time to process
}

batch = await batch.Buy();

if (IsRecording())
Expand All @@ -142,11 +152,11 @@ public async Task TestRetrieve()

Batch batch = await CreateBasicBatch();

Batch retrievedBatch = await Client.Batch.Retrieve(batch.id);
Batch retrievedBatch = await Client.Batch.Retrieve(batch.Id);

Assert.IsType<Batch>(retrievedBatch);
// Must compare IDs since elements of batch (i.e. status) may be different
Assert.Equal(batch.id, retrievedBatch.id);
Assert.Equal(batch.Id, retrievedBatch.Id);
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions EasyPost.Tests/BillingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public async Task TestRetrievePaymentMethods()

PaymentMethodsSummary paymentMethodsSummary = await Client.Billing.RetrievePaymentMethodsSummary();

Assert.NotNull(paymentMethodsSummary.primary_payment_method);
Assert.NotNull(paymentMethodsSummary.secondary_payment_method);
Assert.NotNull(paymentMethodsSummary.PrimaryPaymentMethod);
Assert.NotNull(paymentMethodsSummary.SecondaryPaymentMethod);
}

[Fact(Skip = "Skipping due to the lack of an available real payment method in tests.")]
Expand Down
10 changes: 5 additions & 5 deletions EasyPost.Tests/CarrierAccountTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task TestCreate()
CarrierAccount carrierAccount = await CreateBasicCarrierAccount();

Assert.IsType<CarrierAccount>(carrierAccount);
Assert.StartsWith("ca_", carrierAccount.id);
Assert.StartsWith("ca_", carrierAccount.Id);
}

[Fact]
Expand All @@ -60,7 +60,7 @@ public async Task TestRetrieve()

CarrierAccount carrierAccount = await CreateBasicCarrierAccount();

CarrierAccount retrievedCarrierAccount = await Client.CarrierAccount.Retrieve(carrierAccount.id);
CarrierAccount retrievedCarrierAccount = await Client.CarrierAccount.Retrieve(carrierAccount.Id);

Assert.IsType<CarrierAccount>(retrievedCarrierAccount);
Assert.Equal(carrierAccount, retrievedCarrierAccount);
Expand Down Expand Up @@ -94,8 +94,8 @@ public async Task TestUpdate()
carrierAccount = await carrierAccount.Update(carrierAccountData);

Assert.IsType<CarrierAccount>(carrierAccount);
Assert.StartsWith("ca_", carrierAccount.id);
Assert.Equal(testDescription, carrierAccount.description);
Assert.StartsWith("ca_", carrierAccount.Id);
Assert.Equal(testDescription, carrierAccount.Description);
}

[Fact]
Expand All @@ -118,7 +118,7 @@ public async Task TestDelete()
private async Task<CarrierAccount> CreateBasicCarrierAccount()
{
CarrierAccount carrierAccount = await Client.CarrierAccount.Create(Fixture.BasicCarrierAccount);
CleanUpAfterTest(carrierAccount.id);
CleanUpAfterTest(carrierAccount.Id);

return carrierAccount;
}
Expand Down
6 changes: 3 additions & 3 deletions EasyPost.Tests/CustomsInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public async Task TestCreate()
CustomsInfo customsInfo = await CreateBasicCustomsInfo();

Assert.IsType<CustomsInfo>(customsInfo);
Assert.StartsWith("cstinfo_", customsInfo.id);
Assert.Equal("NOEEI 30.37(a)", customsInfo.eel_pfc);
Assert.StartsWith("cstinfo_", customsInfo.Id);
Assert.Equal("NOEEI 30.37(a)", customsInfo.EelPfc);
}

[Fact]
Expand All @@ -34,7 +34,7 @@ public async Task TestRetrieve()

CustomsInfo customsInfo = await CreateBasicCustomsInfo();

CustomsInfo retrievedCustomsInfo = await Client.CustomsInfo.Retrieve(customsInfo.id);
CustomsInfo retrievedCustomsInfo = await Client.CustomsInfo.Retrieve(customsInfo.Id);

Assert.IsType<CustomsInfo>(retrievedCustomsInfo);
Assert.Equal(customsInfo, retrievedCustomsInfo);
Expand Down
6 changes: 3 additions & 3 deletions EasyPost.Tests/CustomsItemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public async Task TestCreate()
CustomsItem customsItem = await CreateBasicCustomsItem();

Assert.IsType<CustomsItem>(customsItem);
Assert.StartsWith("cstitem_", customsItem.id);
Assert.Equal(23.0, customsItem.value);
Assert.StartsWith("cstitem_", customsItem.Id);
Assert.Equal(23.0, customsItem.Value);
}

[Fact]
Expand All @@ -34,7 +34,7 @@ public async Task TestRetrieve()

CustomsItem customsItem = await CreateBasicCustomsItem();

CustomsItem retrievedCustomsItem = await Client.CustomsItem.Retrieve(customsItem.id);
CustomsItem retrievedCustomsItem = await Client.CustomsItem.Retrieve(customsItem.Id);

Assert.IsType<CustomsItem>(retrievedCustomsItem);
Assert.Equal(customsItem, retrievedCustomsItem);
Expand Down
37 changes: 25 additions & 12 deletions EasyPost.Tests/EasyPost.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,50 @@
<Nullable>enable</Nullable>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<PropertyGroup>
<!-- Nullability and other warnings to suppress -->
<!-- CS8600: Converting null literal or possible null value to non-nullable type -->
<!-- CS8602: Possible null reference assignment -->
<!-- CS8603: Possible null reference return -->
<!-- CS8604: Possible null reference argument -->
<!-- CS8765: Uninitialized field(s) -->
<!-- CS8767: Nullable parameter -->
<!-- CS0659: Missing GetHashCode override -->
<!-- CS0618: Obselete method -->
<NoWarn>CS8600;CS8602;CS8603;CS8604;CS8765;CS8767;CS0659;CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyVCR" Version="[0.4.0, 1.0.0)"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[17.3.0, 18.0.0)"/>
<PackageReference Include="EasyVCR" Version="[0.4.0, 1.0.0)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[17.3.0, 18.0.0)" />
Comment on lines +31 to +32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tired of seeing these changes in PRs. Can we enforce SOME kind of style for these? They are always getting bumped one way then bumped back the very next commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to narrow down on what exactly does this

<PackageReference Include="coverlet.collector" Version="[3.1.2, 4.0.0)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel" Version="[14.0.0, 15.0.0)"/>
<PackageReference Include="NETStandard.Library" Version="[2.0.3, 3.0.0)"/>
<PackageReference Include="xunit" Version="[2.4.2, 3.0.0)"/>
<PackageReference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel" Version="[14.0.0, 15.0.0)" />
<PackageReference Include="NETStandard.Library" Version="[2.0.3, 3.0.0)" />
<PackageReference Include="xunit" Version="[2.4.2, 3.0.0)" />
<PackageReference Include="xunit.runner.visualstudio" Version="[2.4.5, 3.0.0)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="[13.0.1, 14.0.0)"/>
<PackageReference Include="RestSharp" Version="[108.0.1, 109.0.0)"/>
<PackageReference Include="Newtonsoft.Json" Version="[13.0.1, 14.0.0)" />
<PackageReference Include="RestSharp" Version="[108.0.1, 109.0.0)" />
<PackageReference Include="SecurityCodeScan.VS2019" Version="[5.6.6, 6.0.0)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EasyPost\EasyPost.csproj"/>
<ProjectReference Include="..\EasyPost\EasyPost.csproj" />
</ItemGroup>

<ItemGroup>
<None Remove="Microsoft.VisualStudio.UnitTesting"/>
<None Remove="RestSharp"/>
<None Remove="MSTest.TestFramework"/>
<None Remove="MSTest.TestAdapter"/>
<None Remove="Microsoft.VisualStudio.UnitTesting" />
<None Remove="RestSharp" />
<None Remove="MSTest.TestFramework" />
<None Remove="MSTest.TestAdapter" />
</ItemGroup>
</Project>
12 changes: 6 additions & 6 deletions EasyPost.Tests/EndShipperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public async Task TestCreate()
EndShipper endShipper = await CreateBasicEndShipper();

Assert.IsType<EndShipper>(endShipper);
Assert.StartsWith("es_", endShipper.id);
Assert.Equal("388 TOWNSEND ST APT 20", endShipper.street1);
Assert.StartsWith("es_", endShipper.Id);
Assert.Equal("388 TOWNSEND ST APT 20", endShipper.Street1);
}

[Fact]
Expand All @@ -49,10 +49,10 @@ public async Task TestRetrieve()

EndShipper endShipper = await CreateBasicEndShipper();

EndShipper retrievedEndShipper = await Client.Beta.EndShipper.Retrieve(endShipper.id);
EndShipper retrievedEndShipper = await Client.Beta.EndShipper.Retrieve(endShipper.Id);

Assert.IsType<EndShipper>(retrievedEndShipper);
Assert.Equal(endShipper.street1, retrievedEndShipper.street1);
Assert.Equal(endShipper.Street1, retrievedEndShipper.Street1);
}

[Fact]
Expand All @@ -71,8 +71,8 @@ public async Task TestUpdate()
endShipper = await endShipper.Update(endShipperData);

Assert.IsType<EndShipper>(endShipper);
Assert.StartsWith("es_", endShipper.id);
Assert.Equal(testName, endShipper.name);
Assert.StartsWith("es_", endShipper.Id);
Assert.Equal(testName, endShipper.Name);
}

#endregion
Expand Down
Loading