Skip to content

Commit

Permalink
remove some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
eoinobrien committed Jun 30, 2024
1 parent c8f3a9a commit 8d7fb64
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions LuasAPI.NET.Tests/Models/StationForcastTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ namespace LuasAPI.NET.Tests.Models
{
using System;
using System.IO;
using System.Text;
using System.Xml.Serialization;
using LuasAPI.NET.Models;
using LuasAPI.NET.Models.RpaApiXml;
Expand All @@ -14,34 +13,34 @@ public class StationForecastTests
[Fact]
public void CreateStationForecastFromRealTimeInfo_RealTimeInfoIsNull_ThrowsArgumentException()
{
RealTimeInfo realTimeInfoXml = null;
Stations stations = new Stations(new UnitTestStationInformationLoader());
RealTimeInfo? realTimeInfoXml = null;
var stations = new Stations(new UnitTestStationInformationLoader());

Assert.Throws<ArgumentException>(() => StationForecast.CreateStationForecastFromRealTimeInfo(realTimeInfoXml, stations));
}

[Fact]
public void CreateStationForecastFromRealTimeInfo_StationsIsNull_ThrowsArgumentException()
{
RealTimeInfo realTimeInfoXml = new RealTimeInfo();
Stations stations = null;
var realTimeInfoXml = new RealTimeInfo();
Stations? stations = null;

Assert.Throws<ArgumentException>(() => StationForecast.CreateStationForecastFromRealTimeInfo(realTimeInfoXml, stations));
}

[Fact]
public void CreateStationForecastFromRealTimeInfo_1()
{
UnitTestStationInformationLoader loader = new UnitTestStationInformationLoader();
var loader = new UnitTestStationInformationLoader();
loader.AddStations(new Station() { Abbreviation = "STS", Name = "St. Stephen's Green", IsInUse = true });
loader.AddStations(new Station() { Abbreviation = "PAR", Name = "Parnell", IsInUse = true });
loader.AddStations(new Station() { Abbreviation = "SAN", Name = "Sandyford", IsInUse = true });

Stations stations = new Stations(loader);
var stations = new Stations(loader);

RealTimeInfo realTimeInfo = CreateRealTimeInfoFromXml("<stopInfo created=\"2019-12-31T12:00:00\" stop=\"St. Stephen's Green\" stopAbv=\"STS\"><message>Green Line services operating normally</message><direction name=\"Inbound\"><tram destination=\"Parnell\" dueMins=\"1\" /></direction><direction name=\"Outbound\"><tram dueMins=\"6\" destination=\"Sandyford\" /></direction></stopInfo>");

StationForecast forecast = StationForecast.CreateStationForecastFromRealTimeInfo(realTimeInfo, stations);
var forecast = StationForecast.CreateStationForecastFromRealTimeInfo(realTimeInfo, stations);

Assert.Equal(realTimeInfo.Stop, forecast.Station.Name);
Assert.Single(forecast.InboundTrams);
Expand All @@ -51,16 +50,16 @@ public void CreateStationForecastFromRealTimeInfo_1()
[Fact]
public void CreateStationForecastFromRealTimeInfo_2()
{
UnitTestStationInformationLoader loader = new UnitTestStationInformationLoader();
var loader = new UnitTestStationInformationLoader();
loader.AddStations(new Station() { Abbreviation = "STI", Name = "Stillorgan", IsInUse = true });
loader.AddStations(new Station() { Abbreviation = "BRI", Name = "Brides Glen", IsInUse = true });
loader.AddStations(new Station() { Abbreviation = "SAN", Name = "Sandyford", IsInUse = true });

Stations stations = new Stations(loader);
var stations = new Stations(loader);

RealTimeInfo realTimeInfo = CreateRealTimeInfoFromXml("<stopInfo created = \"2024-06-25T00:47:32\" stop=\"Stillorgan\" stopAbv=\"STI\"><message>Green Line services operating normally</message><direction name = \"Inbound\"><tram destination=\"No trams forecast\" dueMins=\"\" /></direction><direction name = \"Outbound\"><tram dueMins=\"12\" destination=\"Brides Glen\" /></direction></stopInfo>");

StationForecast forecast = StationForecast.CreateStationForecastFromRealTimeInfo(realTimeInfo, stations);
var forecast = StationForecast.CreateStationForecastFromRealTimeInfo(realTimeInfo, stations);

Assert.Equal(realTimeInfo.Stop, forecast.Station.Name);
Assert.Empty(forecast.InboundTrams);
Expand All @@ -69,12 +68,9 @@ public void CreateStationForecastFromRealTimeInfo_2()

private RealTimeInfo CreateRealTimeInfoFromXml(string xml)
{
XmlSerializer serializer = new XmlSerializer(typeof(RealTimeInfo));
var serializer = new XmlSerializer(typeof(RealTimeInfo));

using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
{
return (RealTimeInfo)serializer.Deserialize(stream);
}
return (RealTimeInfo)serializer.Deserialize(new StringReader(xml));
}
}
}

0 comments on commit 8d7fb64

Please sign in to comment.