Skip to content

Commit b02c569

Browse files
authored
Refactor all test classes to implement IDisposable and ensure proper resource cleanup. (#124)
1 parent 5ad88f8 commit b02c569

File tree

6 files changed

+349
-286
lines changed

6 files changed

+349
-286
lines changed
Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,50 @@
1-
using NUnit.Framework;
2-
using Solcast.Clients;
3-
using System.Threading.Tasks;
4-
5-
namespace Solcast.Tests
6-
{
7-
[TestFixture]
8-
public class AggregationClientTests
9-
{
10-
private AggregationClient _aggregationClient;
11-
12-
[SetUp]
13-
public void Setup()
14-
{
15-
_aggregationClient = new AggregationClient();
16-
}
17-
18-
[Test]
19-
public async Task GetLiveAggregation_ShouldReturnValidData()
20-
{
21-
var response = await _aggregationClient.GetLiveAggregations(
22-
collectionId: "country_total",
23-
aggregationId: "it_total"
24-
);
25-
Assert.IsNotNull(response);
26-
}
27-
28-
[Test]
29-
public async Task GetForecastAggregation_ShouldReturnValidData()
30-
{
31-
var response = await _aggregationClient.GetForecastAggregations(
32-
collectionId: "country_total",
33-
aggregationId: "it_total",
34-
outputParameters: ["percentage", "pv_estimate"]
35-
);
36-
Assert.IsNotNull(response);
37-
}
38-
}
39-
}
1+
using NUnit.Framework;
2+
using Solcast.Clients;
3+
using System;
4+
using System.Threading.Tasks;
5+
6+
namespace Solcast.Tests
7+
{
8+
[TestFixture]
9+
public class AggregationClientTests : IDisposable
10+
{
11+
private AggregationClient _aggregationClient;
12+
private bool _disposed = false;
13+
14+
[SetUp]
15+
public void Setup()
16+
{
17+
_aggregationClient = new AggregationClient();
18+
}
19+
20+
[Test]
21+
public async Task GetLiveAggregation_ShouldReturnValidData()
22+
{
23+
var response = await _aggregationClient.GetLiveAggregations(
24+
collectionId: "country_total",
25+
aggregationId: "it_total"
26+
);
27+
Assert.IsNotNull(response);
28+
}
29+
30+
[Test]
31+
public async Task GetForecastAggregation_ShouldReturnValidData()
32+
{
33+
var response = await _aggregationClient.GetForecastAggregations(
34+
collectionId: "country_total",
35+
aggregationId: "it_total",
36+
outputParameters: ["percentage", "pv_estimate"]
37+
);
38+
Assert.IsNotNull(response);
39+
}
40+
41+
public void Dispose()
42+
{
43+
if (!_disposed)
44+
{
45+
_aggregationClient?.Dispose();
46+
_disposed = true;
47+
}
48+
}
49+
}
50+
}

tests/Solcast.Tests/ForecastClientTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
namespace Solcast.Tests
88
{
99
[TestFixture]
10-
public class ForecastClientTests
10+
public class ForecastClientTests : IDisposable
1111
{
1212
private ForecastClient _forecastClient;
1313
private string _originalApiKey;
14+
private bool _disposed = false;
1415

1516
[OneTimeSetUp]
1617
public void OneTimeSetup()
@@ -100,5 +101,14 @@ public void OneTimeTearDown()
100101
// Restore the original API key after all tests
101102
Environment.SetEnvironmentVariable("SOLCAST_API_KEY", _originalApiKey);
102103
}
104+
105+
public void Dispose()
106+
{
107+
if (!_disposed)
108+
{
109+
_forecastClient?.Dispose();
110+
_disposed = true;
111+
}
112+
}
103113
}
104114
}

0 commit comments

Comments
 (0)