Skip to content

Commit 93aa101

Browse files
authored
Merge pull request #633 from EasyPost/client_cleanup
chore: remove unecessary dispose logic, instantiate services inline
2 parents 4fdbc7c + 5f210ab commit 93aa101

File tree

20 files changed

+170
-368
lines changed

20 files changed

+170
-368
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
- Adds support for `UspsShipAccount`
66
- Adds `Tracker.RetrieveBatch` function
77
- Adds `VerifyCarrier` address param
8-
- Disposes of Luma service after use
98

109
## v7.2.0 (2025-06-18)
1110

EasyPost.Tests/ClientTest.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ public void TestThreadSafety()
7070

7171
private const string FakeApikey = "fake_api_key";
7272

73-
[Fact]
74-
public void TestClientDisposal()
75-
{
76-
Client client = new(new ClientConfiguration(FakeApikey));
77-
CustomAssertions.DoesNotThrow(() => client.Dispose());
78-
}
79-
8073
[Fact]
8174
public void TestBaseUrlOverride()
8275
{

EasyPost.Tests/Fixture.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,22 @@ internal static ParameterSets.Tracker.All All(Dictionary<string, object>? fixtur
801801
Carrier = fixture.GetOrNull<string>("carrier"),
802802
};
803803
}
804+
805+
internal static ParameterSets.Tracker.Batch Batch(Dictionary<string, object>? fixture)
806+
{
807+
fixture ??= new Dictionary<string, object>();
808+
809+
return new ParameterSets.Tracker.Batch
810+
{
811+
PageSize = fixture.GetOrNullInt("page_size"),
812+
BeforeId = fixture.GetOrNull<string>("before_id"),
813+
AfterId = fixture.GetOrNull<string>("after_id"),
814+
StartDatetime = fixture.GetOrNull<string>("start_datetime"),
815+
EndDatetime = fixture.GetOrNull<string>("end_datetime"),
816+
TrackingCodes = fixture.GetOrNull<List<string>>("tracking_codes"),
817+
Carrier = fixture.GetOrNull<string>("carrier"),
818+
};
819+
}
804820
}
805821

806822
internal static class Users

EasyPost.Tests/HttpTests/ClientConfigurationTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class ClientConfigurationTest
1313
public void TestClientConfigurationDisposal()
1414
{
1515
ClientConfiguration configuration = new("not_a_real_api_key");
16-
CustomAssertions.DoesNotThrow(() => configuration.Dispose());
1716
}
1817

1918
[Fact]

EasyPost.Tests/HttpTests/RequestTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class RequestTest
1515
public void TestRequestDisposal()
1616
{
1717
Request request = new("https://example.com", "not_a_real_endpoint", Method.Get, ApiVersion.V2, new Dictionary<string, object> { { "key", "value" } }, new Dictionary<string, string> { { "header_key", "header_value" } });
18-
CustomAssertions.DoesNotThrow(() => request.Dispose());
1918
}
2019

2120
[Fact]

EasyPost.Tests/ServicesTests/ServiceTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public void TestServiceDisposal()
2929
Client client = new(new ClientConfiguration("not_a_real_api_key"));
3030

3131
AddressService addressService = client.Address;
32-
CustomAssertions.DoesNotThrow(() => addressService.Dispose());
3332
}
3433

3534
/// <summary>

EasyPost.Tests/ServicesTests/TrackerServiceTest.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -147,26 +147,6 @@ public async Task TestRetrieve()
147147
Assert.Equal(tracker.Id, retrievedTracker.Id);
148148
}
149149

150-
[Fact]
151-
[CrudOperations.Read]
152-
[Testing.Function]
153-
public async Task TestRetrieveBatch()
154-
{
155-
UseVCR("retrieve_batch");
156-
157-
Tracker tracker = await Client.Tracker.Create(Fixtures.Usps, "EZ1000000001");
158-
159-
List<string> trackingCodes = new() { tracker.TrackingCode };
160-
TrackerCollection trackerCollection = await Client.Tracker.RetrieveBatch(new Dictionary<string, object> { { "tracking_codes", trackingCodes } });
161-
162-
List<Tracker> trackers = trackerCollection.Trackers;
163-
164-
foreach (Tracker singleTracker in trackers)
165-
{
166-
Assert.IsType<Tracker>(singleTracker);
167-
}
168-
}
169-
170150
#endregion
171151

172152
#endregion

EasyPost.Tests/ServicesTests/WithParameters/TrackerServiceTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,28 @@ public async Task TestAllParameterHandOff()
9292
Assert.Equal(filters.Carrier, ((Parameters.Tracker.All)trackerCollection.Filters!).Carrier);
9393
}
9494

95+
[Fact]
96+
[CrudOperations.Read]
97+
[Testing.Function]
98+
public async Task TestRetrieveBatch()
99+
{
100+
UseVCR("retrieve_batch");
101+
102+
Tracker tracker = await Client.Tracker.Create(Fixtures.Usps, "EZ1000000001");
103+
104+
Dictionary<string, object> data = new Dictionary<string, object>() { { "tracking_codes", new List<string> { tracker.TrackingCode } } };
105+
Parameters.Tracker.Batch parameters = Fixtures.Parameters.Trackers.Batch(data);
106+
107+
TrackerCollection trackerCollection = await Client.Tracker.RetrieveBatch(parameters);
108+
109+
List<Tracker> trackers = trackerCollection.Trackers;
110+
111+
foreach (Tracker singleTracker in trackers)
112+
{
113+
Assert.IsType<Tracker>(singleTracker);
114+
}
115+
}
116+
95117
#endregion
96118

97119
#endregion

EasyPost.Tests/_Utilities/UnitTest.cs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace EasyPost.Tests._Utilities
99
/// Base class for all unit tests.
1010
/// Sets up all available client versions for VCR and non-VCR requests.
1111
/// </summary>
12-
public class UnitTest : IDisposable
12+
public class UnitTest
1313
{
1414
private readonly TestUtils.VCR? _vcr;
1515

@@ -32,38 +32,6 @@ public class UnitTest : IDisposable
3232
protected UnitTest(string groupName, TestUtils.ApiKey apiKey = TestUtils.ApiKey.Test) => _vcr = new TestUtils.VCR(groupName, apiKey);
3333
#pragma warning restore CS8618
3434

35-
/// <summary>
36-
/// Called automatically by xUnit after each unit test is run.
37-
/// Executes the CleanupFunction (passes in the _cleanupId) if set.
38-
/// </summary>
39-
/// <exception cref="Exception">Could not execute the declared clean-up function.</exception>
40-
public void Dispose()
41-
{
42-
if (CleanupFunction == null)
43-
{
44-
return;
45-
}
46-
47-
if (_cleanupId == null)
48-
{
49-
return;
50-
}
51-
52-
try
53-
{
54-
CleanupFunction.Invoke(_cleanupId).GetAwaiter().GetResult();
55-
_cleanupId = null;
56-
}
57-
catch
58-
{
59-
#pragma warning disable CA2201
60-
throw new Exception("Could not execute clean-up function.");
61-
#pragma warning restore CA2201
62-
}
63-
64-
GC.SuppressFinalize(this);
65-
}
66-
6735
/// <summary>
6836
/// Set the ID that will be passed into the CleanupFunction after each unit test
6937
/// </summary>

EasyPost.Tests/cassettes/net/tracker_service/retrieve_batch.json renamed to EasyPost.Tests/cassettes/net/tracker_service_with_parameters/retrieve_batch.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)