sharee.bike-App/TestShareeLib/Model/Connector/TestBikeInfoFactory.cs
2022-04-25 22:15:15 +02:00

201 lines
7.5 KiB
C#

using Newtonsoft.Json;
using NUnit.Framework;
using TINK.Model.Connector;
using TINK.Repository.Response;
namespace TestShareeLib.Model.Connector
{
[TestFixture]
public class TestBikeInfoFactory
{
[Test]
public void TestCreate_Available_NoBc()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoAvailable>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : ""LOCK""
}");
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse),
Is.Null,
"BC- bikes (\"system\" : \"LOCK\") are no more supported.");
}
[Test]
public void TestCreate_Available_InvalidState()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoAvailable>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""reserved"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : ""Ilockit""
}");
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse),
Is.Null,
"Invalid (\"state\" : \"reserved\") detected.");
}
[Test]
public void TestCreate_Available_NoStation()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoAvailable>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : """",
""system"" : ""Ilockit""
}");
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse),
Is.Null,
"Station must not be null.");
}
[Test]
public void TestCreate_Available_DefaultLock()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoAvailable>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : """"
}");
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse).GetType(),
Is.EqualTo( typeof(TINK.Model.Bike.CopriLock.BikeInfo)),
"Default lock by is BackendLock.");
}
[Test]
public void TestCreate_Available_BluetoothLock()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoAvailable>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : ""Ilockit""
}");
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse).GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.BluetoothLock.BikeInfo)));
}
[Test]
public void TestCreate_Available_SigoLock()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoAvailable>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : ""SIGO""
}");
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse).GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.CopriLock.BikeInfo)));
}
[Test]
public void TestCreate_ReservedOrBooked_NoBc()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoReservedOrBooked>(
@"{
""station"" : ""2"",
""state"" : ""occupied"",
""bike"" : ""20"",
""description"" : ""Cargo Long"",
""start_time"" : ""2017-12-01 22:21:57.740069+01"",
""timeCode"" : ""6603"",
""system"" : ""LOCK""
}");
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse, "a@b", () => new System.DateTime()),
Is.Null,
"BC- bikes (\"system\" : \"LOCK\") are no more supported.");
}
[Test]
public void TestCreate_ReservedOrBooked_DefaultLock()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoReservedOrBooked>(
@"{
""station"" : ""2"",
""state"" : ""occupied"",
""bike"" : ""20"",
""description"" : ""Cargo Long"",
""start_time"" : ""2017-12-01 22:21:57.740069+01"",
""timeCode"" : ""6603"",
""system"" : """"
}");
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse, "a@b", () => new System.DateTime()).GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.CopriLock.BikeInfo)));
}
[Test]
public void TestCreate_ReservedOrBooked_BluetoothLock()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoReservedOrBooked>(
@"{
""station"" : ""2"",
""state"" : ""occupied"",
""bike"" : ""20"",
""description"" : ""Cargo Long"",
""start_time"" : ""2017-12-01 22:21:57.740069+01"",
""timeCode"" : ""6603"",
""system"" : ""Ilockit""
}");
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse, "a@b", () => new System.DateTime()).GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.BluetoothLock.BikeInfo)));
}
[Test]
public void TestCreate_ReservedOrBooked_SigoLock()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoReservedOrBooked>(
@"{
""station"" : ""2"",
""state"" : ""occupied"",
""bike"" : ""20"",
""description"" : ""Cargo Long"",
""start_time"" : ""2017-12-01 22:21:57.740069+01"",
""timeCode"" : ""6603"",
""system"" : ""SIGO""
}");
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse, "a@b", () => new System.DateTime()).GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.CopriLock.BikeInfo)));
}
}
}