-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Many tests reworked, a few to go. Consolidated a lot of the hand crafted json objects into objects that get serialized as the purist JsonObject format was prone to errors - in some cases tests were passing even with bad typing.
- Loading branch information
1 parent
92f8dbc
commit 39e45a6
Showing
13 changed files
with
164 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 93 additions & 48 deletions
141
src/CarbonAware.DataSources/CarbonAware.DataSources.WattTime/test/Client/TestData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,126 @@ | ||
using CarbonAware.DataSources.WattTime.Constants; | ||
using CarbonAware.DataSources.WattTime.Model; | ||
using System; | ||
using System.Text.Json.Nodes; | ||
using System.Collections.Generic; | ||
using System.Text.Json; | ||
|
||
namespace CarbonAware.DataSources.WattTime.Client.Tests; | ||
|
||
internal static class TestData | ||
{ | ||
internal static string GetGridDataJsonString() | ||
public class TestDataConstants | ||
{ | ||
var json = new JsonArray( | ||
new JsonObject | ||
{ | ||
["ba"] = "ba", | ||
["datatype"] = "dt", | ||
["frequency"] = 300, | ||
["market"] = "mkt", | ||
["point_time"] = new DateTimeOffset(2099, 1, 1, 0, 0, 0, TimeSpan.Zero), | ||
["value"] = 999.99, | ||
["version"] = "1.0" | ||
} | ||
); | ||
public const string Region = "TEST_REGION"; | ||
public const string RegionFullName = "Test Region Full Name"; | ||
public const string Market = "mkt"; | ||
public static DateTimeOffset GeneratedAt = new DateTimeOffset(2099, 1, 1, 0, 0, 0, TimeSpan.Zero); | ||
public static DateTimeOffset PointTime = new DateTimeOffset(2099, 1, 1, 0, 0, 0, TimeSpan.Zero); | ||
public static DateTime Date = new DateTime(2099, 1, 1, 0, 0, 0); | ||
public const float Value = 999.99f; | ||
public const string Version = "1.0"; | ||
} | ||
|
||
internal static string GetGridDataResponseJsonString() | ||
{ | ||
return JsonSerializer.Serialize(_GetGridDataResponse()); | ||
} | ||
private static GridEmissionsDataResponse _GetGridDataResponse() | ||
{ | ||
var gridEmissionDataResponse = new GridEmissionsDataResponse() | ||
{ | ||
Meta = _GetGridDataMetaResponse(), | ||
Data = _GetGridEmissionDataPoints() | ||
}; | ||
return gridEmissionDataResponse; | ||
} | ||
|
||
private static GridEmissionsMetaData _GetGridDataMetaResponse() | ||
{ | ||
var gridEmissionsMetaData = new GridEmissionsMetaData() | ||
{ | ||
Region = TestDataConstants.Region, | ||
GeneratedAt = TestDataConstants.GeneratedAt, | ||
GeneratedAtPeriodSeconds = 30, | ||
Model = new GridEmissionsModelData() | ||
{ | ||
Date = TestDataConstants.Date, | ||
Type = SignalTypes.co2_moer | ||
}, | ||
DataPointPeriodSeconds = 30, | ||
SignalType = SignalTypes.co2_moer, | ||
Units = "co2_moer" | ||
}; | ||
|
||
return gridEmissionsMetaData; | ||
} | ||
private static List<GridEmissionDataPoint> _GetGridEmissionDataPoints() | ||
{ | ||
return new List<GridEmissionDataPoint>() | ||
{ | ||
_GetGridEmissionDataPoint() | ||
}; | ||
} | ||
|
||
return json.ToString(); | ||
private static GridEmissionDataPoint _GetGridEmissionDataPoint() | ||
{ | ||
return new GridEmissionDataPoint() | ||
{ | ||
Frequency = 300, | ||
Market = TestDataConstants.Market, | ||
PointTime = TestDataConstants.PointTime, | ||
Value = TestDataConstants.Value, | ||
Version = TestDataConstants.Version | ||
}; | ||
} | ||
|
||
internal static string GetCurrentForecastJsonString() | ||
{ | ||
return JsonSerializer.Serialize(_GetCurrentForecastEmissionsDataResponse()); | ||
} | ||
|
||
var json = new JsonObject | ||
private static ForecastEmissionsDataResponse _GetCurrentForecastEmissionsDataResponse() | ||
{ | ||
return new ForecastEmissionsDataResponse() | ||
{ | ||
["generated_at"] = new DateTimeOffset(2099, 1, 1, 0, 0, 0, TimeSpan.Zero), | ||
["forecast"] = new JsonArray | ||
{ | ||
new JsonObject | ||
{ | ||
["ba"] = "ba", | ||
["point_time"] = new DateTimeOffset(2099, 1, 1, 0, 0, 0, TimeSpan.Zero), | ||
["value"] = 999.99, | ||
["version"] = "1.0" | ||
} | ||
} | ||
Data = _GetGridEmissionDataPoints(), | ||
Meta = _GetGridDataMetaResponse() | ||
}; | ||
} | ||
|
||
|
||
return json.ToString(); | ||
internal static string GetHistoricalForecastDataJsonString() | ||
{ | ||
return JsonSerializer.Serialize(_GetHistoricalForecastEmissionsDataResponse()); | ||
} | ||
|
||
internal static string GetForecastByDateJsonString() | ||
private static HistoricalForecastEmissionsDataResponse _GetHistoricalForecastEmissionsDataResponse() | ||
{ | ||
var json = new JsonArray | ||
return new HistoricalForecastEmissionsDataResponse() | ||
{ | ||
new JsonObject | ||
Meta = _GetGridDataMetaResponse(), | ||
Data = new List<HistoricalEmissionsData> | ||
{ | ||
["generated_at"] = new DateTimeOffset(2099, 1, 1, 0, 0, 0, TimeSpan.Zero), | ||
["forecast"] = new JsonArray | ||
new HistoricalEmissionsData() | ||
{ | ||
new JsonObject | ||
{ | ||
["ba"] = "ba", | ||
["point_time"] = new DateTimeOffset(2099, 1, 1, 0, 0, 0, TimeSpan.Zero), | ||
["value"] = 999.99, | ||
["version"] = "1.0" | ||
} | ||
Forecast = _GetGridEmissionDataPoints(), | ||
GeneratedAt = TestDataConstants.GeneratedAt | ||
} | ||
} | ||
}; | ||
} | ||
|
||
return json.ToString(); | ||
internal static string GetRegionJsonString() | ||
{ | ||
return JsonSerializer.Serialize(_GetRegion()); | ||
} | ||
|
||
internal static string GetBalancingAuthorityJsonString() | ||
private static RegionResponse _GetRegion() | ||
{ | ||
var json = new JsonObject | ||
return new RegionResponse() | ||
{ | ||
["id"] = "12345", | ||
["abbrev"] = "TEST_BA", | ||
["name"] = "Test Balancing Authority" | ||
Region = TestDataConstants.Region, | ||
RegionFullName = TestDataConstants.RegionFullName, | ||
SignalType = SignalTypes.co2_moer | ||
}; | ||
|
||
return json.ToString(); | ||
} | ||
} |
Oops, something went wrong.