Skip to content

Commit

Permalink
Fix naming scheme, property nullabilities (#321)
Browse files Browse the repository at this point in the history
- All properties are now TitleCased rather than snake_cased
- Some properties had to be renamed to avoid conflicts (look for "// X is the enclosing class name" comments)
- Removed Verify/VerifyStrict parameters from Address (naming conflict, parameters aren't actually part of the Address object, they're API call params)
- All properties are nullable (most if not all will NOT be null, but since they could be, to avoid compile complaints)
- Re-record all unit tests
- Remove old nullability warning suppressions from main namespace (add to EasyPost.Tests)
- Update CHANGELOG.md with info about nullable properties
- Stricter enforcement of naming style
- Fix some IDE suggestions, suppress others
  • Loading branch information
nwithan8 authored Sep 13, 2022
1 parent ada5bee commit ea2dd5a
Show file tree
Hide file tree
Showing 295 changed files with 4,648 additions and 5,402 deletions.
16 changes: 8 additions & 8 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ dotnet_naming_rule.camel_case_for_private_internal_fields_rule.severity = sugges
dotnet_naming_rule.camel_case_for_private_internal_fields_rule.style = lower_camel_case_style_1
dotnet_naming_rule.camel_case_for_private_internal_fields_rule.symbols = camel_case_for_private_internal_fields_symbols
dotnet_naming_rule.constants_rule.import_to_resharper = as_predefined
dotnet_naming_rule.constants_rule.severity = suggestion
dotnet_naming_rule.constants_rule.severity = warning
dotnet_naming_rule.constants_rule.style = upper_camel_case_style
dotnet_naming_rule.constants_rule.symbols = constants_symbols
dotnet_naming_rule.constant_fields_should_be_pascal_case_rule.import_to_resharper = True
dotnet_naming_rule.constant_fields_should_be_pascal_case_rule.resharper_description = constant_fields_should_be_pascal_case
dotnet_naming_rule.constant_fields_should_be_pascal_case_rule.resharper_guid = 5fc5b41a-b7a6-477d-9e78-cd35bb64828d
dotnet_naming_rule.constant_fields_should_be_pascal_case_rule.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case_rule.severity = warning
dotnet_naming_rule.constant_fields_should_be_pascal_case_rule.style = upper_camel_case_style
dotnet_naming_rule.constant_fields_should_be_pascal_case_rule.symbols = constant_fields_should_be_pascal_case_symbols
dotnet_naming_rule.method_rule.import_to_resharper = as_predefined
Expand Down Expand Up @@ -96,27 +96,27 @@ dotnet_naming_rule.public_fields_instance_override_rule_1.severity = suggestion
dotnet_naming_rule.public_fields_instance_override_rule_1.style = lower_camel_case_style_1
dotnet_naming_rule.public_fields_instance_override_rule_1.symbols = public_fields_instance_override_symbols_1
dotnet_naming_rule.public_fields_instance_override_rule_2.import_to_resharper = False
dotnet_naming_rule.public_fields_instance_override_rule_2.severity = suggestion
dotnet_naming_rule.public_fields_instance_override_rule_2.severity = warning
dotnet_naming_rule.public_fields_instance_override_rule_2.style = upper_camel_case_style
dotnet_naming_rule.public_fields_instance_override_rule_2.symbols = public_fields_instance_override_symbols_2
dotnet_naming_rule.public_fields_instance_rule.import_to_resharper = True
dotnet_naming_rule.public_fields_instance_rule.resharper_description = PublicFieldsInstance
dotnet_naming_rule.public_fields_instance_rule.resharper_guid = 2a9a0bae-89b4-4df6-a105-19c5f8e2e0dd
dotnet_naming_rule.public_fields_instance_rule.severity = suggestion
dotnet_naming_rule.public_fields_instance_rule.severity = warning
dotnet_naming_rule.public_fields_instance_rule.style = upper_camel_case_style
dotnet_naming_rule.public_fields_instance_rule.symbols = public_fields_instance_symbols
dotnet_naming_rule.public_fields_instance_rule_1.import_to_resharper = True
dotnet_naming_rule.public_fields_instance_rule_1.resharper_description = PublicFieldsInstance
dotnet_naming_rule.public_fields_instance_rule_1.resharper_guid = 805de0e3-9674-4c38-a95c-271ec44bc5df
dotnet_naming_rule.public_fields_instance_rule_1.severity = suggestion
dotnet_naming_rule.public_fields_instance_rule_1.severity = warning
dotnet_naming_rule.public_fields_instance_rule_1.style = upper_camel_case_style
dotnet_naming_rule.public_fields_instance_rule_1.symbols = public_fields_instance_symbols_1
dotnet_naming_rule.public_fields_rule.import_to_resharper = as_predefined
dotnet_naming_rule.public_fields_rule.severity = suggestion
dotnet_naming_rule.public_fields_rule.severity = warning
dotnet_naming_rule.public_fields_rule.style = upper_camel_case_style
dotnet_naming_rule.public_fields_rule.symbols = public_fields_symbols
dotnet_naming_rule.public_fields_static_override_rule.import_to_resharper = False
dotnet_naming_rule.public_fields_static_override_rule.severity = suggestion
dotnet_naming_rule.public_fields_static_override_rule.severity = warning
dotnet_naming_rule.public_fields_static_override_rule.style = upper_camel_case_style
dotnet_naming_rule.public_fields_static_override_rule.symbols = public_fields_static_override_symbols
dotnet_naming_rule.public_fields_static_rule.import_to_resharper = True
Expand Down Expand Up @@ -377,7 +377,7 @@ dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = warning
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
Expand Down
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
Loading

0 comments on commit ea2dd5a

Please sign in to comment.