Skip to content

Commit

Permalink
Prep for v5.6.0 release (#514)
Browse files Browse the repository at this point in the history
- Add additional unit test confirming parameter set reuse/re-serialization accounts for alterations
  • Loading branch information
nwithan8 authored Aug 31, 2023
1 parent 28dbb2b commit 1b3192d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
37 changes: 37 additions & 0 deletions EasyPost.Tests/ParametersTests/ParametersTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,43 @@ public void TestParametersToDictionaryWithSubDictionary()
Assert.Equal(streetB, addressData["street1"]);
}

/// <summary>
/// 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.
/// </summary>
[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()
Expand Down
2 changes: 1 addition & 1 deletion EasyPost.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>EasyPost-Official</id>
<title>EasyPost (Official)</title>
<version>5.5.0</version>
<version>5.6.0</version>
<authors>EasyPost</authors>
<owners>EasyPost</owners>
<projectUrl>https://www.easypost.com</projectUrl>
Expand Down
4 changes: 4 additions & 0 deletions EasyPost/Parameters/BaseParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public virtual Dictionary<string, object> 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<string, object?>();

// Construct the dictionary of all parameters
PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Instance |
BindingFlags.NonPublic |
Expand Down Expand Up @@ -106,6 +108,8 @@ public virtual Dictionary<string, object> ToDictionary()
/// <returns><see cref="Dictionary{TKey,TValue}" /> of parameters.</returns>
public virtual Dictionary<string, object> ToSubDictionary(Type parentParameterObjectType)
{
_parameterDictionary = new Dictionary<string, object?>();

// Construct the dictionary of all parameters
PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Instance |
BindingFlags.NonPublic |
Expand Down
6 changes: 3 additions & 3 deletions EasyPost/Properties/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit 1b3192d

Please sign in to comment.