2022-08-30 15:42:25 +02:00
|
|
|
|
using System;
|
2021-07-12 21:31:46 +02:00
|
|
|
|
using System.Linq;
|
2022-08-30 15:42:25 +02:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
|
2021-07-12 21:31:46 +02:00
|
|
|
|
using TINK.Model.Connector;
|
|
|
|
|
using TINK.Repository.Exception;
|
|
|
|
|
using TINK.Repository.Response;
|
|
|
|
|
using JsonConvertRethrow = TINK.Repository.Response.JsonConvertRethrow;
|
|
|
|
|
|
|
|
|
|
namespace TestTINKLib.Fixtures.Connector
|
|
|
|
|
{
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[TestFixture]
|
|
|
|
|
public class TestTextToTypeHelper
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetWheelType_InvalidDescription()
|
|
|
|
|
{
|
|
|
|
|
var l_oInfo = new BikeInfoBase();
|
|
|
|
|
|
|
|
|
|
// Verify prerequisites
|
|
|
|
|
Assert.IsNull(l_oInfo.description);
|
|
|
|
|
|
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.IsNull(TextToTypeHelper.GetWheelType(l_oInfo));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetWheelType()
|
|
|
|
|
{
|
|
|
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""bike"" : ""2"",
|
|
|
|
|
""bike_group"" : [ ""TINK"" ],
|
|
|
|
|
""description"" : ""Cargo Long"",
|
2022-08-30 15:42:25 +02:00
|
|
|
|
""bike_type"": {
|
|
|
|
|
""category"": ""cargo"",
|
|
|
|
|
""wheels"": ""2""
|
|
|
|
|
},
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""gps"" : { ""latitude"": ""47.6612083333"", ""longitude"": ""9.16637533333"" },
|
|
|
|
|
""station"" : ""9"",
|
|
|
|
|
""state"" : ""available""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.AreEqual(WheelType.Two, TextToTypeHelper.GetWheelType(l_oInfo));
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""bike"" : ""11"",
|
|
|
|
|
""bike_group"" : [ ""TINK"" ],
|
|
|
|
|
""description"" : ""Cargo Trike"",
|
2022-08-30 15:42:25 +02:00
|
|
|
|
""bike_type"": {
|
|
|
|
|
""category"": ""cargo"",
|
|
|
|
|
""wheels"": ""3""
|
|
|
|
|
},
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""gps"" : { ""latitude"": ""47.665051"", ""longitude"": ""9.174096"" },
|
|
|
|
|
""station"" : ""1"",
|
|
|
|
|
""state"" : ""available""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.AreEqual(WheelType.Trike, TextToTypeHelper.GetWheelType(l_oInfo));
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""bike"" : ""51"",
|
|
|
|
|
""bike_group"" : [ ""Konrad"" ],
|
|
|
|
|
""description"" : ""Demo Stadtrad"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
|
|
|
|
""station"" : ""8"",
|
|
|
|
|
""state"" : ""available""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.That(TextToTypeHelper.GetWheelType(l_oInfo), Is.Null); // Was WheelType.Two up to 3.0.322
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""bike"" : ""51"",
|
|
|
|
|
""bike_group"" : [ ""Konrad"" ],
|
|
|
|
|
""description"" : ""Stadtrad"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
|
|
|
|
""station"" : ""8"",
|
|
|
|
|
""state"" : ""available""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.That(TextToTypeHelper.GetWheelType(l_oInfo), Is.Null); // Was WheelType.Two up to 3.0.322
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetTypeOfBike_InvalidDescription()
|
|
|
|
|
{
|
|
|
|
|
var l_oInfo = new BikeInfoBase();
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify prerequisites
|
|
|
|
|
Assert.IsNull(l_oInfo.description);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.IsNull(TextToTypeHelper.GetTypeOfBike(l_oInfo));
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetTypeOfBike()
|
|
|
|
|
{
|
|
|
|
|
var info = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""bike"" : ""2"",
|
|
|
|
|
""bike_group"" : [ ""TINK"" ],
|
|
|
|
|
""description"" : ""Cargo Long"",
|
2022-08-30 15:42:25 +02:00
|
|
|
|
""bike_type"": {
|
|
|
|
|
""category"": ""cargo"",
|
|
|
|
|
""wheels"": ""2""
|
|
|
|
|
},
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""gps"" : { ""latitude"": ""47.6612083333"", ""longitude"": ""9.16637533333"" },
|
|
|
|
|
""station"" : ""9"",
|
|
|
|
|
""state"" : ""available""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.AreEqual(TypeOfBike.Cargo, TextToTypeHelper.GetTypeOfBike(info));
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
info = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""bike"" : ""11"",
|
|
|
|
|
""bike_group"" : [ ""TINK"" ],
|
|
|
|
|
""description"" : ""Cargo Trike"",
|
2022-08-30 15:42:25 +02:00
|
|
|
|
""bike_type"": {
|
|
|
|
|
""category"": ""cargo"",
|
|
|
|
|
""wheels"": ""2""
|
|
|
|
|
},
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""gps"" : { ""latitude"": ""47.665051"", ""longitude"": ""9.174096"" },
|
|
|
|
|
""station"" : ""1"",
|
|
|
|
|
""state"" : ""available""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.AreEqual(TypeOfBike.Cargo, TextToTypeHelper.GetTypeOfBike(info));
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
info = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""bike"" : ""51"",
|
|
|
|
|
""bike_group"" : [ ""Konrad"" ],
|
|
|
|
|
""description"" : ""Demo Stadtrad"",
|
2022-08-30 15:42:25 +02:00
|
|
|
|
""bike_type"": {
|
|
|
|
|
""category"": ""city"",
|
|
|
|
|
""wheels"": ""2""
|
|
|
|
|
},
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
|
|
|
|
""station"" : ""8"",
|
|
|
|
|
""state"" : ""available""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.AreEqual(TypeOfBike.City, TextToTypeHelper.GetTypeOfBike(info));
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
info = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""bike"" : ""51"",
|
|
|
|
|
""bike_group"" : [ ""Konrad"" ],
|
|
|
|
|
""description"" : ""Stadtrad"",
|
2022-08-30 15:42:25 +02:00
|
|
|
|
""bike_type"": {
|
|
|
|
|
},
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
|
|
|
|
""station"" : ""8"",
|
|
|
|
|
""state"" : ""available""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.That(
|
|
|
|
|
TextToTypeHelper.GetTypeOfBike(info),
|
|
|
|
|
Is.Null); // Version up to 3.0.322 considered this bike to be a city bike to to description "Stadtrad"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetStateAvailable()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"available\" }").GetState(),
|
|
|
|
|
Is.EqualTo(TINK.Model.State.InUseStateEnum.Disposable));
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetStateAvailableCase()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"availablE \" }").GetState(),
|
|
|
|
|
Is.EqualTo(TINK.Model.State.InUseStateEnum.Disposable));
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetStateReserved()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"requested\" }").GetState(),
|
|
|
|
|
Is.EqualTo(TINK.Model.State.InUseStateEnum.Reserved));
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetStateReservedCase()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \" reQuested\" }").GetState(),
|
|
|
|
|
Is.EqualTo(TINK.Model.State.InUseStateEnum.Reserved));
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetStateOccupied()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"occupied\" }").GetState(),
|
|
|
|
|
Is.EqualTo(TINK.Model.State.InUseStateEnum.Booked));
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetStateOccupiedCase()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"occuPied\" }").GetState(),
|
|
|
|
|
Is.EqualTo(TINK.Model.State.InUseStateEnum.Booked));
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetStateBikeInfoAvailableDisposable()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ \"state\" : \"available\" }").GetState(),
|
|
|
|
|
Is.EqualTo(TINK.Model.State.InUseStateEnum.Disposable));
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetStateBikeInfoAvailableFeedbackPending()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ \"state\" : \"available\", \"co2saving\" : \"\" }").GetState(),
|
|
|
|
|
Is.EqualTo(TINK.Model.State.InUseStateEnum.FeedbackPending));
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetState_InvalidDescription()
|
|
|
|
|
{
|
|
|
|
|
var info = new BikeInfoBase();
|
|
|
|
|
|
|
|
|
|
// Verify prerequisites
|
|
|
|
|
Assert.IsNull(info.state);
|
|
|
|
|
|
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.Throws<InvalidResponseException<BikeInfoBase>>(() => TextToTypeHelper.GetState(info));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetIsDemo()
|
|
|
|
|
{
|
|
|
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""bike"" : ""2"",
|
|
|
|
|
""bike_group"" : [ ""TINK"" ],
|
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.6612083333"", ""longitude"": ""9.16637533333"" },
|
|
|
|
|
""station"" : ""9"",
|
|
|
|
|
""state"" : ""available""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.IsFalse(TextToTypeHelper.GetIsDemo(l_oInfo));
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""bike"" : ""11"",
|
|
|
|
|
""bike_group"" : [ ""TINK"" ],
|
|
|
|
|
""description"" : ""Cargo Trike"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.665051"", ""longitude"": ""9.174096"" },
|
|
|
|
|
""station"" : ""1"",
|
|
|
|
|
""state"" : ""available""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.IsFalse(TextToTypeHelper.GetIsDemo(l_oInfo));
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""bike"" : ""51"",
|
|
|
|
|
""bike_group"" : [ ""Konrad"" ],
|
|
|
|
|
""description"" : ""Demo Stadtrad"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
|
|
|
|
""station"" : ""8"",
|
|
|
|
|
""state"" : ""available""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.IsTrue(TextToTypeHelper.GetIsDemo(l_oInfo));
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""bike"" : ""51"",
|
|
|
|
|
""bike_group"" : [ ""Konrad"" ],
|
|
|
|
|
""description"" : ""Stadtrad"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
|
|
|
|
""station"" : ""8"",
|
|
|
|
|
""state"" : ""available""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Verify behaviour of member.
|
|
|
|
|
Assert.IsFalse(TextToTypeHelper.GetIsDemo(l_oInfo));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetPosition()
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual(1.234d, TextToTypeHelper.GetPosition(JsonConvert.DeserializeObject<Position>("{ \"latitude\" : \"1.234\", \"longitude\" : \"5.678\"}")).Latitude);
|
|
|
|
|
Assert.AreEqual(5.678d, TextToTypeHelper.GetPosition(JsonConvert.DeserializeObject<Position>("{ \"latitude\" : \"1.234\", \"longitude\" : \"5.678\"}")).Longitude);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestMapSpan()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvertRethrow.DeserializeObject<ResponseBase>(@"
|
2022-01-22 18:16:10 +01:00
|
|
|
|
{
|
|
|
|
|
""init_map"": {
|
|
|
|
|
""radius"": ""2.9"",
|
|
|
|
|
""center"": {
|
|
|
|
|
""longitude"": ""7.825490"",
|
|
|
|
|
""latitude"": ""47.976634""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
TextToTypeHelper.GetMapSpan(response.init_map).Radius,
|
|
|
|
|
Is.EqualTo(2.9));
|
|
|
|
|
}
|
2022-01-22 18:16:10 +01:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestMapSpan_EmptyRadius()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvertRethrow.DeserializeObject<ResponseBase>(@"
|
2022-01-22 18:16:10 +01:00
|
|
|
|
{
|
|
|
|
|
""init_map"": {
|
|
|
|
|
""radius"": """",
|
|
|
|
|
""center"": {
|
|
|
|
|
""longitude"": ""7.825490"",
|
|
|
|
|
""latitude"": ""47.976634""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
TextToTypeHelper.GetMapSpan(response.init_map).IsValid,
|
|
|
|
|
Is.False);
|
|
|
|
|
}
|
2022-01-22 18:16:10 +01:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestMapSpan_EmptyPos()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvertRethrow.DeserializeObject<ResponseBase>(@"
|
2022-01-22 18:16:10 +01:00
|
|
|
|
{
|
|
|
|
|
""init_map"": {
|
|
|
|
|
""radius"": """",
|
|
|
|
|
""center"": {
|
|
|
|
|
""longitude"": """",
|
|
|
|
|
""latitude"": ""47.976634""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
TextToTypeHelper.GetMapSpan(response.init_map).IsValid,
|
|
|
|
|
Is.False);
|
|
|
|
|
}
|
2022-01-22 18:16:10 +01:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestMapSpan_Empty()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvertRethrow.DeserializeObject<ResponseBase>(@"
|
2022-01-22 18:16:10 +01:00
|
|
|
|
{
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
TextToTypeHelper.GetMapSpan(response.init_map).IsValid,
|
|
|
|
|
Is.False);
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetStationGroup_Invalid()
|
|
|
|
|
{
|
|
|
|
|
var l_oStation = JsonConvertRethrow.DeserializeObject<StationsAvailableResponse.StationInfo>(
|
|
|
|
|
@"{
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""station"" : ""4"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" }
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// From COPRI version v4.1 no more exception thrown.
|
|
|
|
|
Assert.That(l_oStation.GetGroup().Count(), Is.EqualTo(0));
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetStationGroup_TINK()
|
|
|
|
|
{
|
|
|
|
|
var l_oStation = JsonConvertRethrow.DeserializeObject<StationsAvailableResponse.StationInfo>(
|
|
|
|
|
@"{
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""station"" : ""4"",
|
|
|
|
|
""station_group"" : [ ""TINK"" ],
|
|
|
|
|
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" }
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual("TINK", string.Join(",", l_oStation.GetGroup().ToArray()));
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetStationGroup_TINKAndKonrad()
|
|
|
|
|
{
|
|
|
|
|
var l_oStation = JsonConvertRethrow.DeserializeObject<StationsAvailableResponse.StationInfo>(
|
|
|
|
|
@"{
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""station"" : ""4"",
|
|
|
|
|
""station_group"": [ ""TINK"", ""Konrad"" ],
|
|
|
|
|
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" }
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual("TINK,Konrad", string.Join(",", l_oStation.GetGroup().ToArray()));
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetBikeGroup_TINK()
|
|
|
|
|
{
|
|
|
|
|
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
|
|
|
|
@"{
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""state"" : ""available"",
|
|
|
|
|
""bike"" : ""18"",
|
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""bike_group"" : [ ""TINK"" ],
|
|
|
|
|
""station"" : ""13"",
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual("TINK", string.Join(",", l_oBike.GetGroup().ToArray()));
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetBikeGroup_TINKCopri()
|
|
|
|
|
{
|
|
|
|
|
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
|
|
|
|
@"{
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""state"" : ""available"",
|
|
|
|
|
""bike"" : ""18"",
|
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""bike_group"" : [ ""TINK"" ],
|
|
|
|
|
""system"" : ""BC"",
|
|
|
|
|
""station"" : ""13"",
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual("TINK", string.Join(",", l_oBike.GetGroup().ToArray()));
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetBikeGroup_TINKSMS()
|
|
|
|
|
{
|
|
|
|
|
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
|
|
|
|
@"{
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""state"" : ""available"",
|
|
|
|
|
""bike"" : ""18"",
|
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""bike_group"" : [ ""TINK"" ],
|
|
|
|
|
""system"" : ""Lock"",
|
|
|
|
|
""station"" : ""13"",
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual("TINK", string.Join(",", l_oBike.GetGroup().ToArray()));
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetBikeGroup_Konrad()
|
|
|
|
|
{
|
|
|
|
|
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
|
|
|
|
@"{
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""state"" : ""available"",
|
|
|
|
|
""bike"" : ""18"",
|
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""bike_group"" : [ ""Konrad"" ],
|
|
|
|
|
""station"" : ""13"",
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual("Konrad", string.Join(",", l_oBike.GetGroup().ToArray()));
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetBikeGroup_Null()
|
|
|
|
|
{
|
|
|
|
|
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
|
|
|
|
@"{
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""state"" : ""available"",
|
|
|
|
|
""bike"" : ""18"",
|
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""station"" : ""13"",
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual(0, l_oBike.GetGroup().ToArray().Length);
|
|
|
|
|
}
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetAuthGroup()
|
|
|
|
|
{
|
|
|
|
|
// User group was of format [ ""TINK"", ""Konrad"" ] in early day...
|
|
|
|
|
// Since COPRI 4.1 use group is no more used.
|
|
|
|
|
// Groups are of format <OperatorId>_<BikeType> for this user group would be like below if it would be used.
|
|
|
|
|
var response = JsonConvertRethrow.DeserializeObject<AuthorizationResponse>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""response"" : ""authorization"",
|
|
|
|
|
""authcookie"" : ""4da3044c8657a04ba60e2eaa753bc51a"",
|
2021-11-14 23:27:29 +01:00
|
|
|
|
""user_group"" : [ ""KN_300102"", ""KN_300101"" ],
|
2021-07-12 21:31:46 +02:00
|
|
|
|
""response_state"" : ""OK"",
|
|
|
|
|
""apiserver"" : ""https://tinkwwp.copri-bike.de""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual(2, response.GetGroup().ToList().Count);
|
|
|
|
|
Assert.AreEqual($"KN_300102", response.GetGroup().ToList()[0]);
|
|
|
|
|
Assert.AreEqual($"KN_300101", response.GetGroup().ToList()[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetGroupString()
|
|
|
|
|
{
|
|
|
|
|
// From COPRI version v4.1 no more exception thrown.
|
|
|
|
|
Assert.That(TextToTypeHelper.GetGroup(new string[0]).Count(), Is.EqualTo(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetGroupString_Null()
|
|
|
|
|
{
|
|
|
|
|
// From COPRI version v4.1 no more exception thrown.
|
|
|
|
|
Assert.That(TextToTypeHelper.GetGroup((string[])null).Count(), Is.EqualTo(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetGroupString_Roundtrip()
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual("Tunk,Unk", TextToTypeHelper.GetGroup(TextToTypeHelper.GetGroup(new[] { "Tunk", "Unk" })));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetUserKey()
|
|
|
|
|
{
|
|
|
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""total_price"": ""0.00"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.6586133"", ""longitude"": ""9.16864"" },
|
|
|
|
|
""unit_price"": ""3.00"",
|
|
|
|
|
""K_u"": ""[99, 104, 120, 121, 63, 99, -10, -110, 94, 70, 15, -112, -6, 101, 117, -90, -113, -54, -90, -95, 0, 0, 0, 0]"",
|
|
|
|
|
""tariff_description"": {""name"" : ""TINK Basic""},
|
|
|
|
|
""end_time"": ""2020-04-07 16:55:18"",
|
|
|
|
|
""K_seed"": ""[-18, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
|
|
|
|
""system"": ""Ilockit"",
|
|
|
|
|
""bike"": ""16"",
|
|
|
|
|
""computed_hours"": ""0"",
|
|
|
|
|
""request_time"": ""2020-04-07 16:55:06.823436+02"",
|
|
|
|
|
""bike_group"" : [ ""TINK"" ],
|
|
|
|
|
""K_a"": ""[-19, 29, -60, 29, 35, -121, -69, 93, 27, -122, 107, -127, -30, 74, 82, 12, 4, -20, 40, 16, 0, 0, 0, 0]"",
|
|
|
|
|
""state"": ""occupied"",
|
|
|
|
|
""real_hours"": ""0"",
|
|
|
|
|
""station"" : ""7"",
|
|
|
|
|
""start_time"": ""2020-04-07 16:55:17.786551+02"",
|
|
|
|
|
""description"": ""Cargo Long""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
99,
|
|
|
|
|
TextToTypeHelper.GetUserKey(l_oInfo)[0]);
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
104,
|
|
|
|
|
TextToTypeHelper.GetUserKey(l_oInfo)[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetAdminKey()
|
|
|
|
|
{
|
|
|
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""total_price"": ""0.00"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.6586133"", ""longitude"": ""9.16864"" },
|
|
|
|
|
""unit_price"": ""3.00"",
|
|
|
|
|
""K_u"": ""[99, 104, 120, 121, 63, 99, -10, -110, 94, 70, 15, -112, -6, 101, 117, -90, -113, -54, -90, -95, 0, 0, 0, 0]"",
|
|
|
|
|
""tariff_description"": {""name"" : ""TINK Basic""},
|
|
|
|
|
""end_time"": ""2020-04-07 16:55:18"",
|
|
|
|
|
""K_seed"": ""[-18, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
|
|
|
|
""system"": ""Ilockit"",
|
|
|
|
|
""bike"": ""16"",
|
|
|
|
|
""computed_hours"": ""0"",
|
|
|
|
|
""request_time"": ""2020-04-07 16:55:06.823436+02"",
|
|
|
|
|
""bike_group"" : [ ""TINK"" ],
|
|
|
|
|
""K_a"": ""[-19, 29, -60, 29, 35, -121, -69, 93, 27, -122, 107, -127, -30, 74, 82, 12, 4, -20, 40, 16, 0, 0, 0, 0]"",
|
|
|
|
|
""state"": ""occupied"",
|
|
|
|
|
""real_hours"": ""0"",
|
|
|
|
|
""station"" : ""7"",
|
|
|
|
|
""start_time"": ""2020-04-07 16:55:17.786551+02"",
|
|
|
|
|
""description"": ""Cargo Long""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
237,
|
|
|
|
|
TextToTypeHelper.GetAdminKey(l_oInfo)[0]);
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
29,
|
|
|
|
|
TextToTypeHelper.GetAdminKey(l_oInfo)[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetSeed()
|
|
|
|
|
{
|
|
|
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""total_price"": ""0.00"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.6586133"", ""longitude"": ""9.16864"" },
|
|
|
|
|
""unit_price"": ""3.00"",
|
|
|
|
|
""K_u"": ""[99, 104, 120, 121, 63, 99, -10, -110, 94, 70, 15, -112, -6, 101, 117, -90, -113, -54, -90, -95, 0, 0, 0, 0]"",
|
|
|
|
|
""tariff_description"": {""name"" : ""TINK Basic""},
|
|
|
|
|
""end_time"": ""2020-04-07 16:55:18"",
|
|
|
|
|
""K_seed"": ""[-18, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
|
|
|
|
""system"": ""Ilockit"",
|
|
|
|
|
""bike"": ""16"",
|
|
|
|
|
""computed_hours"": ""0"",
|
|
|
|
|
""request_time"": ""2020-04-07 16:55:06.823436+02"",
|
|
|
|
|
""bike_group"" : [ ""TINK"" ],
|
|
|
|
|
""K_a"": ""[-19, 29, -60, 29, 35, -121, -69, 93, 27, -122, 107, -127, -30, 74, 82, 12, 4, -20, 40, 16, 0, 0, 0, 0]"",
|
|
|
|
|
""state"": ""occupied"",
|
|
|
|
|
""real_hours"": ""0"",
|
|
|
|
|
""station"" : ""7"",
|
|
|
|
|
""start_time"": ""2020-04-07 16:55:17.786551+02"",
|
|
|
|
|
""description"": ""Cargo Long""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
238,
|
|
|
|
|
TextToTypeHelper.GetSeed(l_oInfo)[0]);
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
176,
|
|
|
|
|
TextToTypeHelper.GetSeed(l_oInfo)[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetSeedUserKeyAdminKey_Invalid()
|
|
|
|
|
{
|
|
|
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""total_price"": ""0.00"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.6586133"", ""longitude"": ""9.16864"" },
|
|
|
|
|
""unit_price"": ""3.00"",
|
|
|
|
|
""K_u"": ""[]"",
|
|
|
|
|
""tariff_description"": {""name"" : ""TINK Basic""},
|
|
|
|
|
""end_time"": ""2020-04-07 16:55:18"",
|
|
|
|
|
""K_seed"": ""[-18a, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
|
|
|
|
""system"": ""Ilockit"",
|
|
|
|
|
""bike"": ""16"",
|
|
|
|
|
""computed_hours"": ""0"",
|
|
|
|
|
""request_time"": ""2020-04-07 16:55:06.823436+02"",
|
|
|
|
|
""bike_group"" : [ ""TINK"" ],
|
|
|
|
|
""K_a"": ""{-19, 29, -60, 29, 35, -121, -69, 93, 27, -122, 107, -127, -30, 74, 82, 12, 4, -20, 40, 16, 0, 0, 0, 0}"",
|
|
|
|
|
""state"": ""occupied"",
|
|
|
|
|
""real_hours"": ""0"",
|
|
|
|
|
""station"" : ""7"",
|
|
|
|
|
""start_time"": ""2020-04-07 16:55:17.786551+02"",
|
|
|
|
|
""description"": ""Cargo Long""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
0,
|
|
|
|
|
TextToTypeHelper.GetSeed(l_oInfo).Length);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
0,
|
|
|
|
|
TextToTypeHelper.GetUserKey(l_oInfo).Length);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
0,
|
|
|
|
|
TextToTypeHelper.GetAdminKey(l_oInfo).Length);
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetBluetoothLockId_FromBikeInfo_Invalid()
|
|
|
|
|
{
|
|
|
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual(0, TextToTypeHelper.GetBluetoothLockId(l_oInfo));
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""Ilockit_ID"": """"
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual(0, TextToTypeHelper.GetBluetoothLockId(l_oInfo));
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetBluetoothLockId_FromBikeInfo()
|
|
|
|
|
{
|
|
|
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""Ilockit_ID"": ""ISHAREIT-132""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
132,
|
|
|
|
|
TextToTypeHelper.GetBluetoothLockId(l_oInfo));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetBluetoothLockId_FromString_Invalid()
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual(0, TextToLockItTypeHelper.GetBluetoothLockId((string)null));
|
|
|
|
|
Assert.AreEqual(0, TextToLockItTypeHelper.GetBluetoothLockId(""));
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(0, TextToLockItTypeHelper.GetBluetoothLockId("HubbaBubba"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetBluetoothLockId_FromString()
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
132,
|
|
|
|
|
TextToLockItTypeHelper.GetBluetoothLockId("ISHAREIT-132"));
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
132,
|
|
|
|
|
TextToLockItTypeHelper.GetBluetoothLockId("ISHAREIT+132"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetCopriVersion()
|
|
|
|
|
{
|
|
|
|
|
var version = JsonConvertRethrow.DeserializeObject<CopriVersion>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""copri_version"": ""4.3.2.1""
|
|
|
|
|
}");
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
version.GetCopriVersion(),
|
|
|
|
|
Is.EqualTo(new Version(4, 3, 2, 1)));
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetCopriVersion_Invald()
|
|
|
|
|
{
|
|
|
|
|
var version = JsonConvertRethrow.DeserializeObject<CopriVersion>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
""copri_version"": ""hellO""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
() => version.GetCopriVersion(),
|
|
|
|
|
Throws.InstanceOf<InvalidResponseException>());
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetCopriVersion_Null()
|
|
|
|
|
{
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
() => TextToTypeHelper.GetCopriVersion(null),
|
|
|
|
|
Throws.InstanceOf<InvalidResponseException>());
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetCopriVersion_NotContained()
|
|
|
|
|
{
|
|
|
|
|
var version = JsonConvertRethrow.DeserializeObject<CopriVersion>(@"
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
() => version.GetCopriVersion(),
|
|
|
|
|
Throws.InstanceOf<InvalidResponseException>());
|
|
|
|
|
}
|
2022-01-04 18:59:16 +01:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetIsAgbAcknowledged()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvertRethrow.DeserializeObject<AuthorizationResponse>(@"
|
2022-01-04 18:59:16 +01:00
|
|
|
|
{
|
|
|
|
|
""agb_checked"" : ""1""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
() => response.GetIsAgbAcknowledged(),
|
|
|
|
|
Is.True);
|
|
|
|
|
}
|
2022-01-04 18:59:16 +01:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetIsAgbAcknowledged_No()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvertRethrow.DeserializeObject<AuthorizationResponse>(@"
|
2022-01-04 18:59:16 +01:00
|
|
|
|
{
|
|
|
|
|
""agb_checked"" : ""0""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
() => response.GetIsAgbAcknowledged(),
|
|
|
|
|
Is.False);
|
|
|
|
|
}
|
2022-01-04 18:59:16 +01:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetIsAgbAcknowledged_Invalid()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvertRethrow.DeserializeObject<AuthorizationResponse>(@"
|
2022-01-04 18:59:16 +01:00
|
|
|
|
{
|
|
|
|
|
""agb_checked"" : ""ä""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
() => response.GetIsAgbAcknowledged(),
|
|
|
|
|
Is.False);
|
|
|
|
|
}
|
2022-01-04 18:59:16 +01:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetIsAgbAcknowledged_Empty()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvertRethrow.DeserializeObject<AuthorizationResponse>(@"
|
2022-01-04 18:59:16 +01:00
|
|
|
|
{
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
() => response.GetIsAgbAcknowledged(),
|
|
|
|
|
Is.False);
|
|
|
|
|
}
|
2022-04-25 22:15:15 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetLockModelBluetooth()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
|
|
|
@"{
|
2022-04-25 22:15:15 +02:00
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""state"" : ""available"",
|
|
|
|
|
""bike"" : ""1"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
|
|
|
""station"" : ""9"",
|
|
|
|
|
""system"" : ""Ilockit""
|
|
|
|
|
}");
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
response.GetLockModel(),
|
|
|
|
|
Is.EqualTo(LockModel.ILockIt));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetLockModelSigo()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
|
|
|
@"{
|
2022-04-25 22:15:15 +02:00
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""state"" : ""available"",
|
|
|
|
|
""bike"" : ""1"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
|
|
|
""station"" : ""9"",
|
|
|
|
|
""system"" : ""SIGO""
|
|
|
|
|
}");
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
response.GetLockModel(),
|
|
|
|
|
Is.EqualTo(LockModel.Sigo));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetLockModelBordComputer()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
|
|
|
@"{
|
2022-04-25 22:15:15 +02:00
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""state"" : ""available"",
|
|
|
|
|
""bike"" : ""1"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
|
|
|
""station"" : ""9"",
|
|
|
|
|
""system"" : ""LOCK""
|
|
|
|
|
}");
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
response.GetLockModel(),
|
|
|
|
|
Is.EqualTo(LockModel.BordComputer));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetLockModelUnknown()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
|
|
|
@"{
|
2022-04-25 22:15:15 +02:00
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""state"" : ""available"",
|
|
|
|
|
""bike"" : ""1"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
|
|
|
""station"" : ""9"",
|
|
|
|
|
""system"" : """"
|
|
|
|
|
}");
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
response.GetLockModel(),
|
|
|
|
|
Is.Null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetCopriLockingStateClosed()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
|
|
|
@"{
|
2022-04-25 22:15:15 +02:00
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""state"" : ""available"",
|
|
|
|
|
""bike"" : ""1"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
|
|
|
""station"" : ""9"",
|
|
|
|
|
""system"" : """",
|
|
|
|
|
""lock_state"" : ""locked""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
TextToTypeHelper.GetCopriLockingState(response),
|
|
|
|
|
Is.EqualTo(TINK.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Closed));
|
|
|
|
|
}
|
2022-04-25 22:15:15 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetCopriLockingStateClosing()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
|
|
|
@"{
|
2022-04-25 22:15:15 +02:00
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""state"" : ""available"",
|
|
|
|
|
""bike"" : ""1"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
|
|
|
""station"" : ""9"",
|
|
|
|
|
""system"" : """",
|
|
|
|
|
""lock_state"" : ""locking""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
TextToTypeHelper.GetCopriLockingState(response),
|
|
|
|
|
Is.EqualTo(TINK.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Closing));
|
|
|
|
|
}
|
2022-04-25 22:15:15 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetCopriLockingStateOpen()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
|
|
|
@"{
|
2022-04-25 22:15:15 +02:00
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""state"" : ""available"",
|
|
|
|
|
""bike"" : ""1"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
|
|
|
""station"" : ""9"",
|
|
|
|
|
""system"" : """",
|
|
|
|
|
""lock_state"" : ""unlocked""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
TextToTypeHelper.GetCopriLockingState(response),
|
|
|
|
|
Is.EqualTo(TINK.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Open));
|
|
|
|
|
}
|
2022-04-25 22:15:15 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetCopriLockingStateOpening()
|
|
|
|
|
{
|
|
|
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
|
|
|
@"{
|
2022-04-25 22:15:15 +02:00
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
|
""state"" : ""available"",
|
|
|
|
|
""bike"" : ""1"",
|
|
|
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
|
|
|
""station"" : ""9"",
|
|
|
|
|
""system"" : """",
|
|
|
|
|
""lock_state"" : ""unlocking""
|
|
|
|
|
}");
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
TextToTypeHelper.GetCopriLockingState(response),
|
|
|
|
|
Is.EqualTo(TINK.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Opening));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetIsFeedbackPendingIsPendingValue()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ \"co2saving\" : \"Tonns\" }").GetIsFeedbackPending(),
|
|
|
|
|
Is.True);
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetIsFeedbackPendingIsPending()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ \"co2saving\" : \"\" }").GetIsFeedbackPending(),
|
|
|
|
|
Is.True);
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetIsFeedbackPendingNot()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ }").GetIsFeedbackPending(),
|
|
|
|
|
Is.False);
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetTypeOfBikeCity()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"category\" : \"city\" } }").GetTypeOfBike(),
|
|
|
|
|
Is.EqualTo(TypeOfBike.City));
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetTypeOfBikeCargo()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"category\" : \"cargo\" } }").GetTypeOfBike(),
|
|
|
|
|
Is.EqualTo(TypeOfBike.Cargo));
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetTypeOfBikeNull()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { } }").GetTypeOfBike(),
|
|
|
|
|
Is.Null);
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetWheelTypeTrike()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"wheels\" : \"3\" } }").GetWheelType(),
|
|
|
|
|
Is.EqualTo(WheelType.Trike));
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetWheelTypeQuad()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"wheels\" : \"4\" } }").GetWheelType(),
|
|
|
|
|
Is.EqualTo(WheelType.Quad));
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetWheelTypeTow()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"wheels\" : \"2\" } }").GetWheelType(),
|
|
|
|
|
Is.EqualTo(WheelType.Two));
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetWheelTypeNull()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { } }").GetWheelType(),
|
|
|
|
|
Is.Null);
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetFrom()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
2022-08-30 15:42:25 +02:00
|
|
|
|
{
|
|
|
|
|
""start_time"" : ""2022-7-16"",
|
|
|
|
|
}").GetFrom(),
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Is.EqualTo(new DateTime(2022, 7, 16)));
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetFromInvalid()
|
|
|
|
|
=> Assert.That(
|
|
|
|
|
JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
2022-08-30 15:42:25 +02:00
|
|
|
|
{
|
|
|
|
|
}").GetFrom(),
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Is.EqualTo(DateTime.MinValue));
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
}
|