diff --git a/CHANGELOG.md b/CHANGELOG.md index ade0c1784..b8d330783 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## v5.6.0 (2023-08-31) + +- Add ability to compare an EasyPost object to a parameter set object via `Matches` function + - Users can define a custom `Matches` function on any parameter set class +- Fix parameter set serialization that was causing issues when altering and reusing parameter sets + ## v5.5.0 (2023-08-29) - Add custom parameter sets (`CreateFedEx`, `CreateUps`) for carrier account creation API calls diff --git a/EasyPost.Tests/ParametersTests/ParametersTest.cs b/EasyPost.Tests/ParametersTests/ParametersTest.cs index 0f47c9282..8ee9ea065 100644 --- a/EasyPost.Tests/ParametersTests/ParametersTest.cs +++ b/EasyPost.Tests/ParametersTests/ParametersTest.cs @@ -108,6 +108,43 @@ public void TestParametersToDictionaryWithSubDictionary() Assert.Equal(streetB, addressData["street1"]); } + /// + /// This test proves that you can reuse a parameter object, and that re-serializing it will take into account any changes made to its properties since the last serialization. + /// + [Fact] + [Testing.Logic] + public void TestReusingParameterSets() + { + var parameters = new Parameters.Shipment.All + { + BeforeId = null, + }; + + // null values should not be serialized + var parametersDictionary = parameters.ToDictionary(); + Assert.False(parametersDictionary.ContainsKey("before_id")); + + parameters.BeforeId = "1"; + + // now that the property has a value, it should be serialized + parametersDictionary = parameters.ToDictionary(); + Assert.True(parametersDictionary.ContainsKey("before_id")); + Assert.Equal("1", parametersDictionary["before_id"]); + + parameters.BeforeId = "2"; + + // the new value should be serialized + parametersDictionary = parameters.ToDictionary(); + Assert.True(parametersDictionary.ContainsKey("before_id")); + Assert.Equal("2", parametersDictionary["before_id"]); + + parameters.BeforeId = null; + + // null values should not be serialized + parametersDictionary = parameters.ToDictionary(); + Assert.False(parametersDictionary.ContainsKey("before_id")); + } + [Fact] [Testing.Exception] public void TestRequiredAndOptionalParameterValidation() diff --git a/EasyPost.nuspec b/EasyPost.nuspec index 178793370..fe599e975 100644 --- a/EasyPost.nuspec +++ b/EasyPost.nuspec @@ -3,7 +3,7 @@ EasyPost-Official EasyPost (Official) - 5.5.0 + 5.6.0 EasyPost EasyPost https://www.easypost.com diff --git a/EasyPost/Parameters/BaseParameters.cs b/EasyPost/Parameters/BaseParameters.cs index 36892740b..a3e09b5d2 100644 --- a/EasyPost/Parameters/BaseParameters.cs +++ b/EasyPost/Parameters/BaseParameters.cs @@ -58,6 +58,8 @@ public virtual Dictionary ToDictionary() // Bad stuff could happen if we allow end-users to convert a parameter object to a dictionary themselves and try to use it in the normal functions // In particular, a lot of the normal functions do additional wrapping of their dictionaries, which would result in invalid JSON schemas being sent to the API + _parameterDictionary = new Dictionary(); + // Construct the dictionary of all parameters PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | @@ -106,6 +108,8 @@ public virtual Dictionary ToDictionary() /// of parameters. public virtual Dictionary ToSubDictionary(Type parentParameterObjectType) { + _parameterDictionary = new Dictionary(); + // Construct the dictionary of all parameters PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | diff --git a/EasyPost/Properties/VersionInfo.cs b/EasyPost/Properties/VersionInfo.cs index cb00bc913..85fe7ac34 100644 --- a/EasyPost/Properties/VersionInfo.cs +++ b/EasyPost/Properties/VersionInfo.cs @@ -2,6 +2,6 @@ // Version information for an assembly must follow semantic versioning // When releasing a release candidate, append a 4th digit being the number of the release candidate -[assembly: AssemblyVersion("5.5.0")] -[assembly: AssemblyFileVersion("5.5.0")] -[assembly: AssemblyInformationalVersion("5.5.0")] +[assembly: AssemblyVersion("5.6.0")] +[assembly: AssemblyFileVersion("5.6.0")] +[assembly: AssemblyInformationalVersion("5.6.0")]