Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit 0ad3b4b

Browse files
committed
Added nullable to CarbonAware
1 parent fa98be2 commit 0ad3b4b

File tree

11 files changed

+19
-18
lines changed

11 files changed

+19
-18
lines changed

src/CarbonAware.DataSources/CarbonAware.DataSources.ElectricityMaps/mock/ElectricityMapDataSourceMocker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace CarbonAware.DataSources.ElectricityMaps.Mocks;
1212

1313
public class ElectricityMapsDataSourceMocker : IDataSourceMocker
1414
{
15-
private WireMockServer _server;
15+
private readonly WireMockServer _server;
1616
private const string ZONE_NAME = "eastus";
1717
private const string ZONE_KEY = "US-NE-ISNE";
1818
private static readonly JsonSerializerOptions _options = new JsonSerializerOptions(JsonSerializerDefaults.Web);

src/CarbonAware.DataSources/CarbonAware.DataSources.ElectricityMaps/src/ElectricityMapsDataSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private static EmissionsForecast ToEmissionsForecast(Location location, Forecast
6868
emissionsForecast.RequestedAt = requestedAt;
6969
emissionsForecast.ForecastData = emissionsForecast.ForecastData.Select(d =>
7070
{
71-
d.Location = location.Name;
71+
d.Location = location.Name ?? string.Empty;
7272
d.Duration = duration;
7373
return d;
7474
});

src/CarbonAware.DataSources/CarbonAware.DataSources.ElectricityMaps/test/Client/ElectricityMapsClientTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public void ClientInstantiation_FailsForInvalidConfig(string baseUrl)
5353
CreateBasicClient(TestData.GetZonesAllowedJsonString(), "{}");
5454
this.Configuration = new ElectricityMapsClientConfiguration()
5555
{
56-
APITokenHeader = null,
57-
APIToken = null,
56+
APITokenHeader = string.Empty,
57+
APIToken = string.Empty,
5858
BaseUrl = baseUrl,
5959
};
6060

src/CarbonAware.Tools/CarbonAware.Tools.AWSRegionTestDataGenerator/AWSRegionTestDataGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public List<EmissionsData> GenerateTestData(List<AwsRegionData> regionData)
4040
var e = new EmissionsData()
4141
{
4242
Time = DateTime.Now + TimeSpan.FromHours(i),
43-
Location = region.code,
43+
Location = region.code ?? string.Empty,
4444
Rating = ran.Next(100)
4545
};
4646
emData.Add(e);

src/CarbonAware.Tools/CarbonAware.Tools.AzureRegionTestDataGenerator/AzureRegionTestDataGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public List<EmissionsData> GenerateTestData(List<AzureRegionData> regionData)
4444
{
4545
// 3 times per day (8 hours apart), 365 days per year
4646
Time = DateTime.Now + TimeSpan.FromHours(8 * hours) + TimeSpan.FromDays(days),
47-
Location = region.name,
47+
Location = region.name ?? string.Empty,
4848
Rating = ran.Next(100)
4949
};
5050
emData.Add(e);

src/CarbonAware/src/CarbonAware.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
56
<ImplicitUsings>enable</ImplicitUsings>
67
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
78
<IsPackable>false</IsPackable>

src/CarbonAware/src/CarbonAwareVariablesConfiguration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ public class CarbonAwareVariablesConfiguration
2020
/// <summary>
2121
/// Gets or sets the forecast data source to use.
2222
/// </summary>
23-
public string ForecastDataSource { get; set; }
23+
public string ForecastDataSource { get; set; } = string.Empty;
2424

2525
/// <summary>
2626
/// Gets or sets the emissions data source to use.
2727
/// </summary>
28-
public string EmissionsDataSource { get; set; }
28+
public string EmissionsDataSource { get; set; } = string.Empty;
2929

30-
#nullable enable
30+
#nullable enable
3131
/// <summary>
3232
/// Gets or sets proxy information for making calls to the internet.
3333
/// </summary>

src/CarbonAware/src/Extensions/EmissionsDataExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static IEnumerable<EmissionsData> RollingAverage(this IEnumerable<Emissio
4848
var _data = data.GetEnumerator();
4949
_data.MoveNext();
5050
EmissionsData current = _data.Current;
51-
EmissionsData last = null;
51+
EmissionsData? last = null;
5252

5353
if (tickSize == default)
5454
{
@@ -151,7 +151,7 @@ public static double AverageOverPeriod(this IEnumerable<EmissionsData> data, Dat
151151
{
152152
double rating = 0.0;
153153
TimeSpan totalDuration = endTime - startTime;
154-
EmissionsData previous = null;
154+
EmissionsData? previous = null;
155155
(bool reverseChronology, bool emptyEnumerable) = GetChronologyDetails(data);
156156
bool startTimeCoverage = false;
157157
bool endTimeCoverage = false;
@@ -193,8 +193,8 @@ public static double AverageOverPeriod(this IEnumerable<EmissionsData> data, Dat
193193

194194
private static (bool reverseChronology, bool emptyEnumerable) GetChronologyDetails(IEnumerable<EmissionsData> data)
195195
{
196-
EmissionsData current = null;
197-
EmissionsData next = null;
196+
EmissionsData? current = null;
197+
EmissionsData? next = null;
198198
var _data = data.GetEnumerator();
199199

200200
if (_data.MoveNext())

src/CarbonAware/src/Model/EmissionsData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
public record EmissionsData
55
{
66
///<example> eastus </example>
7-
public string Location { get; set; }
7+
public string Location { get; set; } = string.Empty;
88
///<example> 01-01-2022 </example>
99
public DateTimeOffset Time { get; set; }
1010
///<example> 140.5 </example>

src/CarbonAware/src/Model/EmissionsForecast.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public record EmissionsForecast
4141
/// <summary>
4242
/// Gets or sets the optimal data points within the ForecastData set.
4343
/// </summary>
44-
public IEnumerable<EmissionsData> OptimalDataPoints { get; set; }
44+
public IEnumerable<EmissionsData> OptimalDataPoints { get; set; } = new List<EmissionsData>();
4545

4646

4747
public void Validate()

src/CarbonAware/src/WebProxyConfiguration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ public class WebProxyConfiguration
1111
/// <summary>
1212
/// Gets or sets the proxy url
1313
/// </summary>
14-
public string Url { get; set; }
14+
public string Url { get; set; } = string.Empty;
1515

1616
/// <summary>
1717
/// Sets the proxy username
1818
/// </summary>
19-
public string Username { get; set; }
19+
public string Username { get; set; } = string.Empty;
2020

2121
/// <summary>
2222
/// Sets the proxy password
2323
/// </summary>
24-
public string Password { get; set; }
24+
public string Password { get; set; } = string.Empty;
2525
}

0 commit comments

Comments
 (0)