public async Task GetSeries_WithSeriesId_ReturnsSeriesInstanceAsync() { // Arrange var jsonString = await File.ReadAllTextAsync(Path.Join("TestFiles", "EIAResponse.json")); var eiaResponseObject = EIAResponse.FromJson(jsonString); var mockClient = new Mock <IEIARestClient>(); mockClient.Setup(client => client.GetSeries(It.IsAny <string>(), null, null)) .ReturnsAsync(eiaResponseObject); var controller = new EIASeriesController(mockClient.Object); // Act var result = await controller.GetSeries("EBA.TVA-ALL.D.H"); // Assert Assert.Equal("EBA.TVA-ALL.D.H", result.SeriesId); Assert.True(!string.IsNullOrWhiteSpace(result.Name)); Assert.True(!string.IsNullOrWhiteSpace(result.Description)); Assert.Equal("megawatthours", result.Units); Assert.True(result.Start > DateTime.MinValue); Assert.True(result.End > DateTime.MinValue); Assert.True(result.Updated > DateTime.MinValue); Assert.Equal(19, result.Samples.Count); Assert.True(result.Samples[0].Time > DateTime.MinValue); Assert.True(result.Samples[0].Value > 0); }
public void EIAResponse_ToJson_WithValidInstance_Success() { var eiaResponseObject = new EIAResponse { Request = new Request { Command = "series", SeriesId = "EBA.TVA-ALL.D.H" }, Series = new[] { new Series { Name = "EBA.TVA-ALL.D.H", Data = new[] { new[] { new Datum { String = "20200915T18Z" }, new Datum { Integer = 20000 } } } } } }; var jsonString = eiaResponseObject.ToJson(); Assert.NotEmpty(jsonString); }
public void EIAResponse_FromJson_WithValidJsonString_Success() { var jsonString = File.ReadAllText(Path.Join("TestFiles", "EIAResponse.json")); var eiaResponseObject = EIAResponse.FromJson(jsonString); Assert.Equal("EBA.TVA-ALL.D.H", eiaResponseObject.Request.SeriesId); }
public static Series FromEIAResponse(EIAResponse eiaResponse) { var series = new Series { SeriesId = eiaResponse.Series[0].SeriesId, Name = eiaResponse.Series[0].Name, Units = eiaResponse.Series[0].Units, Description = eiaResponse.Series[0].Description, Start = GetDateTimeFromEIADateString(eiaResponse.Series[0].Start), End = GetDateTimeFromEIADateString(eiaResponse.Series[0].End), Updated = DateTime.Parse(eiaResponse.Series[0].Updated), Samples = new List <Sample>() }; foreach (var item in eiaResponse.Series[0].Data) { var sample = new Sample { Time = GetDateTimeFromEIADateString(item[0].String), Value = item[1].Integer ?? 0 }; series.Samples.Add(sample); } return(series); }
public async Task <EIAResponse> GetSeries(string seriesId, string start = null, string end = null) { var requestUrl = BuildRequestUrl($"/series/?series_id={seriesId}"); if (start != null) { requestUrl += $"&start={start}"; } if (end != null) { requestUrl += $"&end={end}"; } var jsonString = await _httpClient.GetStringAsync(requestUrl); return(EIAResponse.FromJson(jsonString)); }