sharee.bike-App/TestShareeLib/Model/Connector/TestBikeInfoFactory.cs
Anja Müller-Meißner 573fe77e12 Version 3.0.337
2022-08-30 15:42:25 +02:00

326 lines
14 KiB
C#

using Newtonsoft.Json;
using NUnit.Framework;
using TINK.Model.Connector.Updater;
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.Bikes.BikeInfoNS.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.Bikes.BikeInfoNS.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.Bikes.BikeInfoNS.CopriLock.BikeInfo)));
}
[Test]
public void TestCreate_Available_CorpiLock_FeedbackPending()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoAvailable>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : ""SIGO"",
""co2saving"" : ""You saved tonns of co2!"",
""user_miniquery"" : {
""footer"" : ""Herzlichen Dank und viel Spaß bei der nächsten Fahrt!"",
""subtitle"" : ""Ihre drei Antworten werden anonym gespeichert."",
""title"" : ""Bitte unterstützen Sie unsere Begleitforschung"",
""questions"" : {
""q1"" : {
""quest_text"" : ""1. Was war der Hauptzweck dieser Ausleihe?"",
""type"" : ""check_one"",
""query"" : {
""opt5"" : ""e. Ausprobieren"",
""opt3"" : ""c. Lastentransport"",
""opt6"" : ""f. Sonstiges"",
""opt1"" : ""a. Einkauf"",
""opt4"" : ""d. Freizeit"",
""opt2"" : ""b. Kinderbeförderung""
}
},
""q2"" : {
""type"" : ""check_one"",
""quest_text"" : ""2. Welches Verkehrsmittel hätten Sie ansonsten benutzt?"",
""query"" : {
""opt1"" : ""a. Auto"",
""opt7"" : ""g. Sonstige"",
""opt2"" : ""b. Motorrad oder Motorroller"",
""opt4"" : ""d. Eigenes Fahrrad"",
""opt6"" : ""f. Keines (ich hätte die Fahrt sonst nicht gemacht)"",
""opt5"" : ""e. Zu Fuß"",
""opt3"" : ""c. Bus oder Bahn""
},
},
""q3"" : {
""type"" : ""text"",
""quest_text"" : ""3. Haben Sie Anmerkungen oder Anregungen?"",
""query"" : {
""opt1"" : """"
},
},
},
}
}");
var bike = BikeInfoFactory.Create(bikeInfoResponse) as TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo;
Assert.That(
bike,
Is.Not.Null);
}
[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.Bikes.BikeInfoNS.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.Bikes.BikeInfoNS.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.Bikes.BikeInfoNS.CopriLock.BikeInfo)));
}
[Test]
public void TestCreate_Available_CopriLock_FeedBackRequied()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoAvailable>(
@"{
""rental_description"": {
""reserve_timerange"": ""30 Min"",
""name"": ""Lastenrad"",
""rental_info"": {
""2"": [
""AGB"",
""Mit der Mietrad Anmietung wird folgender Betreiber <a href='https://shareeapp-wue.copri.eu/site/agb.html' target='_blank'>AGB</a> zugestimmt (als Demo sharee AGB).""
],
""1"": [
""Tracking"",
""Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!""
]
},
""id"": ""5523"",
""tarif_elements"": {
""1"": [
""Mietgebühr"",
""3,00 € / 1 Std ""
],
""6"": [
""Gratis Mietzeit"",
""30 Min / Tag""
],
""4"": [
""Max. Gebühr"",
""15.00 € / Tag""
]
}
},
""uri_operator"": ""https://shareeapp-wue.copri.eu"",
""state"": ""available"",
""bike"": ""WUE5529"",
""authed"": ""1"",
""bike_group"": [
""WUE300101""
],
""gps"": {
""longitude"": null,
""latitude"": null
},
""system"": ""sigo"",
""tariff_description"": {
""free_hours"": ""0.50"",
""number"": ""5523"",
""max_eur_per_day"": ""15.00"",
""name"": ""Lastenrad"",
""eur_per_hour"": ""3.00""
},
""station"": ""WUE9301"",
""description"": ""sigolaster Bay"",
""lock_state"": ""locked"",
""co2saving"" : """"
}");
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse)?.State?.Value,
Is.EqualTo(TINK.Model.State.InUseStateEnum.FeedbackPending),
"Bikes with state booking state available in ");
}
}
}