using System.Linq; using NUnit.Framework; using ShareeBike.Repository; using ShareeBike.Repository.Response; namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.Connector.Request { [TestFixture] public class TestCopriCallsStatic { [Test] public void TestDeserializeObjectBikesAvailableValidResponse() { const string VALID_RESPONSE = @" { ""shareejson"": { ""authcookie"": 0, ""apiserver"": ""https://tinkwwp.copri-bike.de"", ""response"": ""bikes_available"", ""bikes"": { ""3399"": { ""description"": ""Cargo Trike"", ""bike"": ""26"", ""state"": ""available"", ""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" }, ""station"" : ""4"" }, }, ""response_state"": ""OK"", ""copri_version"" : ""4.1.0.0"" } } "; // Ensure that answer holds a valid bike. var l_oBike = CopriCallsStatic.DeserializeResponse(VALID_RESPONSE).bikes.FirstOrDefault().Value; Assert.That(l_oBike, Is.Not.Null, "Response must contain at leas one bike."); Assert.That(l_oBike.description.Length, Is.GreaterThan(0), "Bike description must never be empty."); Assert.That("26", Is.EqualTo(l_oBike.bike)); Assert.That( l_oBike.station, Is.EqualTo("4"), "Station index must never be negative"); Assert.That(l_oBike.state, Is.EqualTo("available")); Assert.That(l_oBike.gps, Is.Not.Null, "Gps position must never be empty."); } [Test] public void TestDeserializeObjectBikesAvailableValidResponse_NoDescription() { const string INVALID_RESPONSE = @" { ""shareejson"": { ""authcookie"": 0, ""apiserver"": ""https://tinkwwp.copri-bike.de"", ""response"": ""bikes_available"", ""bikes"": { ""3399"": { ""bike"": 26, ""state"": ""available"", ""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" }, ""station"" : 4 }, }, ""response_state"": ""OK"", ""copri_version"" : ""4.1.0.0"", } } "; // Ensure that answer holds a valid bike. var l_oBike = CopriCallsStatic.DeserializeResponse(INVALID_RESPONSE).bikes.FirstOrDefault().Value; Assert.That(l_oBike, Is.Not.Null, "Response must contain at leas one bike."); Assert.That(l_oBike.description, Is.Null); Assert.That(l_oBike.bike, Is.Not.Null); Assert.That(l_oBike.station, Is.Not.Null); Assert.That(l_oBike.state, Is.EqualTo("available")); Assert.That(l_oBike.gps, Is.Not.Null, "Gps position must never be empty."); } [Test] public void TestDeserializeObjectBikesAvailableValidResponse_NoBikeId() { const string VALID_RESPONSE = @" { ""shareejson"": { ""authcookie"": 0, ""apiserver"": ""https://tinkwwp.copri-bike.de"", ""response"": ""bikes_available"", ""bikes"": { ""3399"": { ""description"": ""Cargo Trike"", ""state"": ""available"", ""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" }, ""station"" : ""4"" }, }, ""response_state"": ""OK"", ""copri_version"" : ""4.1.0.0"", } }"; // Ensure that answer holds a valid bike. var l_oBike = CopriCallsStatic.DeserializeResponse(VALID_RESPONSE).bikes.FirstOrDefault().Value; Assert.That(l_oBike, Is.Not.Null, "Response must contain at leas one bike."); Assert.That(l_oBike.description.Length, Is.GreaterThan(0), "Bike description must never be empty."); Assert.That(l_oBike.bike, Is.Null); Assert.That(l_oBike.station, Is.Not.Null); Assert.That(l_oBike.state, Is.EqualTo("available")); Assert.That(l_oBike.gps, Is.Not.Null, "Gps position must never be empty."); } [Test] public void TestDeserializeObjectBikesOccupiedValidResponse() { const string VALID_RESPONSE = @" { ""shareejson"": { ""response_state"": ""OK"", ""bikes_occupied"": { ""87781"": { ""timeCode"": ""3630"", ""state"": ""occupied"", ""station"" : ""5"", ""description"": ""Cargo Long"", ""start_time"": ""2017-11-28 11:01:51.637747+01"", ""bike"": ""8"" }, ""87782"": { ""timeCode"": ""2931"", ""state"": ""occupied"", ""station"" : ""4"", ""description"": ""Cargo Long"", ""start_time"": ""2017-11-28 13:06:55.147368+01"", ""bike"": ""7"" } }, ""authcookie"": ""b76b97e43a2d76b8499f32e6dd597af8"", ""response"": ""user_bikes_occupied"", ""apiserver"": ""https://tinkwwp.copri-bike.de"", ""copri_version"" : ""4.1.0.0"", } }"; // Ensure that answer holds a valid bike. var l_oBike = CopriCallsStatic.DeserializeResponse(VALID_RESPONSE).bikes_occupied.FirstOrDefault().Value; Assert.That(l_oBike, Is.Not.Null, "Response must contain at leas one bike."); Assert.That(l_oBike.description.Length, Is.GreaterThan(0), "Bike description must never be empty."); Assert.That(l_oBike.bike, Is.Not.Null); Assert.That(l_oBike.station, Is.Not.Null); Assert.That(l_oBike.state.Length, Is.GreaterThan(0), "State info must never be null or empty."); // Todo: Requested bikes do not have a gps position. What is about booked bikes? // Assert.Greater(l_oBike.gps.Length, 0, "Gps position must never be empty."); Assert.That(l_oBike.start_time.Length, Is.GreaterThan(0), "Time when request/ booking was performed must never be null or empty."); Assert.That(l_oBike.timeCode.Length, Is.GreaterThan(0), "Booking code must never be null or empty."); } } }