Skip to content

Commit 1b3192d

Browse files
authored
Prep for v5.6.0 release (#514)
- Add additional unit test confirming parameter set reuse/re-serialization accounts for alterations
1 parent 28dbb2b commit 1b3192d

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## v5.6.0 (2023-08-31)
4+
5+
- Add ability to compare an EasyPost object to a parameter set object via `Matches` function
6+
- Users can define a custom `Matches` function on any parameter set class
7+
- Fix parameter set serialization that was causing issues when altering and reusing parameter sets
8+
39
## v5.5.0 (2023-08-29)
410

511
- Add custom parameter sets (`CreateFedEx`, `CreateUps`) for carrier account creation API calls

EasyPost.Tests/ParametersTests/ParametersTest.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,43 @@ public void TestParametersToDictionaryWithSubDictionary()
108108
Assert.Equal(streetB, addressData["street1"]);
109109
}
110110

111+
/// <summary>
112+
/// 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.
113+
/// </summary>
114+
[Fact]
115+
[Testing.Logic]
116+
public void TestReusingParameterSets()
117+
{
118+
var parameters = new Parameters.Shipment.All
119+
{
120+
BeforeId = null,
121+
};
122+
123+
// null values should not be serialized
124+
var parametersDictionary = parameters.ToDictionary();
125+
Assert.False(parametersDictionary.ContainsKey("before_id"));
126+
127+
parameters.BeforeId = "1";
128+
129+
// now that the property has a value, it should be serialized
130+
parametersDictionary = parameters.ToDictionary();
131+
Assert.True(parametersDictionary.ContainsKey("before_id"));
132+
Assert.Equal("1", parametersDictionary["before_id"]);
133+
134+
parameters.BeforeId = "2";
135+
136+
// the new value should be serialized
137+
parametersDictionary = parameters.ToDictionary();
138+
Assert.True(parametersDictionary.ContainsKey("before_id"));
139+
Assert.Equal("2", parametersDictionary["before_id"]);
140+
141+
parameters.BeforeId = null;
142+
143+
// null values should not be serialized
144+
parametersDictionary = parameters.ToDictionary();
145+
Assert.False(parametersDictionary.ContainsKey("before_id"));
146+
}
147+
111148
[Fact]
112149
[Testing.Exception]
113150
public void TestRequiredAndOptionalParameterValidation()

EasyPost.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<metadata>
44
<id>EasyPost-Official</id>
55
<title>EasyPost (Official)</title>
6-
<version>5.5.0</version>
6+
<version>5.6.0</version>
77
<authors>EasyPost</authors>
88
<owners>EasyPost</owners>
99
<projectUrl>https://www.easypost.com</projectUrl>

EasyPost/Parameters/BaseParameters.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public virtual Dictionary<string, object> ToDictionary()
5858
// 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
5959
// 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
6060

61+
_parameterDictionary = new Dictionary<string, object?>();
62+
6163
// Construct the dictionary of all parameters
6264
PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Instance |
6365
BindingFlags.NonPublic |
@@ -106,6 +108,8 @@ public virtual Dictionary<string, object> ToDictionary()
106108
/// <returns><see cref="Dictionary{TKey,TValue}" /> of parameters.</returns>
107109
public virtual Dictionary<string, object> ToSubDictionary(Type parentParameterObjectType)
108110
{
111+
_parameterDictionary = new Dictionary<string, object?>();
112+
109113
// Construct the dictionary of all parameters
110114
PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Instance |
111115
BindingFlags.NonPublic |

EasyPost/Properties/VersionInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
// Version information for an assembly must follow semantic versioning
44
// When releasing a release candidate, append a 4th digit being the number of the release candidate
5-
[assembly: AssemblyVersion("5.5.0")]
6-
[assembly: AssemblyFileVersion("5.5.0")]
7-
[assembly: AssemblyInformationalVersion("5.5.0")]
5+
[assembly: AssemblyVersion("5.6.0")]
6+
[assembly: AssemblyFileVersion("5.6.0")]
7+
[assembly: AssemblyInformationalVersion("5.6.0")]

0 commit comments

Comments
 (0)