mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-21 04:26:29 +02:00
Version 3.0.337
This commit is contained in:
parent
fd0e63cf10
commit
573fe77e12
2336 changed files with 33688 additions and 86082 deletions
|
@ -0,0 +1,259 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.Connector.Updater;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
|
||||
namespace TestShareeLib.Model.Connector.Updater
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestBookingFinishedModelFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// COPRI response shortened, part not belonging to user_miniquery discarded.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCreateMiniSurvey_Co2Saving()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<ResponseContainer<DoReturnResponse>>(@"
|
||||
{
|
||||
""shareejson"" : {
|
||||
""co2saving"" : ""Einsparung: 1,95 kg CO2 und 3,00 EUR bei einer Strecke von 10 KM""
|
||||
}
|
||||
}");
|
||||
|
||||
var bookingFinshed = response.shareejson.Create();
|
||||
|
||||
Assert.That(
|
||||
bookingFinshed.Co2Saving,
|
||||
Is.EqualTo("Einsparung: 1,95 kg CO2 und 3,00 EUR bei einer Strecke von 10 KM"));
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// COPRI response shortened, part not belonging to user_miniquery discarded.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCreateMiniSurvey()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<ResponseContainer<DoReturnResponse>>(@"
|
||||
{
|
||||
""shareejson"" : {
|
||||
""user_miniquery"" : {
|
||||
""title"" : ""Bitte unterstützen Sie unsere Begleitforschung"",
|
||||
""footer"" : ""Herzlichen Dank und viel Spaß bei der nächsten Fahrt!"",
|
||||
""questions"" : {
|
||||
""q3"" : {
|
||||
""quest_text"" : ""3. Haben Sie Anmerkungen oder Anregungen?"",
|
||||
""type"" : ""text"",
|
||||
""query"" : {
|
||||
""opt1"" : """"
|
||||
}
|
||||
},
|
||||
""q1"" : {
|
||||
""type"" : ""check_one"",
|
||||
""quest_text"" : ""1. Was war der Hauptzweck dieser Ausleihe?"",
|
||||
""query"" : {
|
||||
""opt2"" : ""b. Kinderbeförderung"",
|
||||
""opt5"" : ""e. Ausprobieren"",
|
||||
""opt4"" : ""d. Freizeit"",
|
||||
""opt1"" : ""a. Einkauf"",
|
||||
""opt3"" : ""c. Lastentransport"",
|
||||
""opt6"" : ""f. Sonstiges""
|
||||
}
|
||||
},
|
||||
""q2"" : {
|
||||
""type"" : ""check_one"",
|
||||
""quest_text"" : ""2. Welches Verkehrsmittel hätten Sie ansonsten benutzt?"",
|
||||
""query"" : {
|
||||
""opt6"" : ""f. Keines (ich hätte die Fahrt sonst nicht gemacht)"",
|
||||
""opt3"" : ""c. Bus oder Bahn"",
|
||||
""opt1"" : ""a. Auto"",
|
||||
""opt2"" : ""b. Motorrad oder Motorroller"",
|
||||
""opt7"" : ""g. Sonstige"",
|
||||
""opt4"" : ""d. Eigenes Fahrrad"",
|
||||
""opt5"" : ""e. Zu Fuß""
|
||||
}
|
||||
}
|
||||
},
|
||||
""subtitle"" : ""Ihre drei Antworten werden anonym gespeichert.""
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
|
||||
var bookingFinished = response.shareejson.Create();
|
||||
|
||||
Assert.That(
|
||||
bookingFinished,
|
||||
Is.Not.Null);
|
||||
|
||||
Assert.That(
|
||||
bookingFinished.MiniSurvey.Title,
|
||||
Is.EqualTo("Bitte unterstützen Sie unsere Begleitforschung"));
|
||||
|
||||
Assert.That(
|
||||
bookingFinished.MiniSurvey.Subtitle,
|
||||
Is.EqualTo("Ihre drei Antworten werden anonym gespeichert."));
|
||||
|
||||
Assert.That(
|
||||
bookingFinished.MiniSurvey.Footer,
|
||||
Is.EqualTo("Herzlichen Dank und viel Spaß bei der nächsten Fahrt!"));
|
||||
|
||||
Assert.That(
|
||||
bookingFinished.MiniSurvey.Questions.Count,
|
||||
Is.EqualTo(3));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// COPRI response shortened, part not belonging to user_miniquery discarded.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCreateMiniSurvey_Null()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<ResponseContainer<DoReturnResponse>>(@"
|
||||
{
|
||||
""shareejson"" : {
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
|
||||
var bookingFinshed = response.shareejson.Create();
|
||||
|
||||
Assert.That(
|
||||
bookingFinshed,
|
||||
Is.Not.Null);
|
||||
|
||||
Assert.That(
|
||||
bookingFinshed.MiniSurvey.Questions.Count,
|
||||
Is.EqualTo(0));
|
||||
|
||||
Assert.That(
|
||||
bookingFinshed.MiniSurvey.Title,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
bookingFinshed.MiniSurvey.Subtitle,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
bookingFinshed.MiniSurvey.Footer,
|
||||
Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// COPRI response shortened, part not belonging to user_miniquery discarded.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCreateMiniSurvey_EmptyQuery()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<ResponseContainer<DoReturnResponse>>(@"
|
||||
{
|
||||
""shareejson"" : {
|
||||
""user_miniquery"" : {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
|
||||
var bookingFinished = response.shareejson.Create();
|
||||
|
||||
Assert.That(
|
||||
bookingFinished,
|
||||
Is.Not.Null);
|
||||
|
||||
Assert.That(
|
||||
bookingFinished.MiniSurvey.Title,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
bookingFinished.MiniSurvey.Subtitle,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
bookingFinished.MiniSurvey.Footer,
|
||||
Is.Null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// COPRI response shortened, part not belonging to user_miniquery discarded.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCreateMiniSurvey_InvalidQuestion_KeyNull()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<ResponseContainer<DoReturnResponse>>(@"
|
||||
{
|
||||
""shareejson"" : {
|
||||
""user_miniquery"" : {
|
||||
""title"" : ""Bitte unterstützen Sie unsere Begleitforschung"",
|
||||
""footer"" : ""Herzlichen Dank und viel Spaß bei der nächsten Fahrt!"",
|
||||
""questions"" : {
|
||||
"""" : {
|
||||
""type"" : ""check_one"",
|
||||
""quest_text"" : ""1. Was war der Hauptzweck dieser Ausleihe?"",
|
||||
""query"" : {
|
||||
""opt2"" : ""b. Kinderbeförderung"",
|
||||
""opt5"" : ""e. Ausprobieren"",
|
||||
""opt4"" : ""d. Freizeit"",
|
||||
""opt1"" : ""a. Einkauf"",
|
||||
""opt3"" : ""c. Lastentransport"",
|
||||
""opt6"" : ""f. Sonstiges""
|
||||
}
|
||||
},
|
||||
},
|
||||
""subtitle"" : ""Ihre drei Antworten werden anonym gespeichert.""
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
|
||||
var bookingFinised = response.shareejson.Create();
|
||||
|
||||
Assert.That(
|
||||
bookingFinised,
|
||||
Is.Not.Null);
|
||||
|
||||
Assert.That(
|
||||
bookingFinised.MiniSurvey.Questions.Count,
|
||||
Is.EqualTo(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// COPRI response shortened, part not belonging to user_miniquery discarded.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCreateMiniSurvey_InvalidQuestion_ValueNull()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<ResponseContainer<DoReturnResponse>>(@"
|
||||
{
|
||||
""shareejson"" : {
|
||||
""user_miniquery"" : {
|
||||
""title"" : ""Bitte unterstützen Sie unsere Begleitforschung"",
|
||||
""footer"" : ""Herzlichen Dank und viel Spaß bei der nächsten Fahrt!"",
|
||||
""questions"" : {
|
||||
""q1"" : {
|
||||
},
|
||||
},
|
||||
""subtitle"" : ""Ihre drei Antworten werden anonym gespeichert.""
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
");
|
||||
|
||||
var bookingFinished = response.shareejson.Create();
|
||||
|
||||
Assert.That(
|
||||
bookingFinished,
|
||||
Is.Not.Null);
|
||||
|
||||
Assert.That(
|
||||
bookingFinished.MiniSurvey.Questions.Count,
|
||||
Is.EqualTo(0));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
208
TestShareeLib/Model/Connector/Updater/TestDriveFactory.cs
Normal file
208
TestShareeLib/Model/Connector/Updater/TestDriveFactory.cs
Normal file
|
@ -0,0 +1,208 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
|
||||
using TINK.Model.Connector.Updater;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TestShareeLib.Model.Connector.Updater
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestDriveFactory
|
||||
{
|
||||
[Test]
|
||||
public void TestEmpty()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<BikeType>(@"");
|
||||
|
||||
Assert.That(
|
||||
response.Create().Type,
|
||||
Is.EqualTo(DriveType.SoleHumanPowered));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Engine.Manufacturer,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.CurrentChargePercent,
|
||||
Is.NaN);
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.CurrentChargeBars,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.MaxChargeBars,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.IsBackendAccessible,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.IsHidden,
|
||||
Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEmptyEngine()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<BikeType>(@"
|
||||
{
|
||||
""category"" : ""cargo"",
|
||||
""wheels"" : ""2"",
|
||||
""engine"" : {
|
||||
}
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
response.Create().Type,
|
||||
Is.EqualTo(DriveType.SoleHumanPowered));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Engine.Manufacturer,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.CurrentChargePercent,
|
||||
Is.NaN);
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.CurrentChargeBars,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.MaxChargeBars,
|
||||
Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEngine()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<BikeType>(@"
|
||||
{
|
||||
""category"" : ""cargo"",
|
||||
""wheels"" : ""2"",
|
||||
""engine"" : {
|
||||
""manufacturer"" : ""dummy""
|
||||
}
|
||||
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
response.Create().Type,
|
||||
Is.EqualTo(DriveType.Pedelec));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Engine.Manufacturer,
|
||||
Is.EqualTo("dummy"));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.CurrentChargePercent,
|
||||
Is.NaN);
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.CurrentChargeBars,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.MaxChargeBars,
|
||||
Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBatteryValues1()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<BikeType>(@"
|
||||
{
|
||||
""category"" : ""cargo"",
|
||||
""wheels"" : ""2"",
|
||||
""engine"" : {
|
||||
""manufacturer"" : ""dummy""
|
||||
},
|
||||
""battery"" : {
|
||||
""charge_current_bars"" : ""4"",
|
||||
""charge_max_bars"" : ""5"",
|
||||
""charge_current_percent"" : ""70"",
|
||||
""backend_accessible"" : ""0"",
|
||||
""hidden"" : ""0"",
|
||||
}
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
response.Create().Type,
|
||||
Is.EqualTo(DriveType.Pedelec));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Engine.Manufacturer,
|
||||
Is.EqualTo("dummy"));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.CurrentChargePercent,
|
||||
Is.EqualTo(70.0));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.CurrentChargeBars,
|
||||
Is.EqualTo(4));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.MaxChargeBars,
|
||||
Is.EqualTo(5));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.IsBackendAccessible,
|
||||
Is.False);
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.IsHidden,
|
||||
Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBatteryValues2()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<BikeType>(@"
|
||||
{
|
||||
""category"" : ""cargo"",
|
||||
""wheels"" : ""2"",
|
||||
""engine"" : {
|
||||
""manufacturer"" : ""dummy2""
|
||||
},
|
||||
""battery"" : {
|
||||
""charge_current_bars"" : ""1"",
|
||||
""charge_max_bars"" : ""6"",
|
||||
""charge_current_percent"" : ""70.3"",
|
||||
""backend_accessible"" : ""1"",
|
||||
""hidden"" : ""1"",
|
||||
}
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
response.Create().Type,
|
||||
Is.EqualTo(DriveType.Pedelec));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Engine.Manufacturer,
|
||||
Is.EqualTo("dummy2"));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.CurrentChargePercent,
|
||||
Is.EqualTo(70.3));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.CurrentChargeBars,
|
||||
Is.EqualTo(1));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.MaxChargeBars,
|
||||
Is.EqualTo(6));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.IsBackendAccessible,
|
||||
Is.True);
|
||||
|
||||
Assert.That(
|
||||
response.Create().Battery.IsHidden,
|
||||
Is.True);
|
||||
}
|
||||
}
|
||||
}
|
200
TestShareeLib/Model/Connector/Updater/TestRentalDescription.cs
Normal file
200
TestShareeLib/Model/Connector/Updater/TestRentalDescription.cs
Normal file
|
@ -0,0 +1,200 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.Connector.Updater;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
|
||||
namespace TestShareeLib.Model.Connector.Updater
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestRentalDescription
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void TestCreateRentalDescriptionEmpyJson()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<RentalDescription>(@"");
|
||||
|
||||
Assert.That(
|
||||
response.Create().Name,
|
||||
Is.Empty);
|
||||
|
||||
Assert.That(
|
||||
response.Create().TariffEntries.Count,
|
||||
Is.EqualTo(0));
|
||||
|
||||
Assert.That(
|
||||
response.Create().InfoEntries.Count,
|
||||
Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateRentalDescription()
|
||||
{
|
||||
var response = JsonConvertRethrow.DeserializeObject<RentalDescription>(
|
||||
@"{
|
||||
""id"": ""1"",
|
||||
""tarif_elements"" : {
|
||||
""6"": [
|
||||
""Gratis Mietzeit"",
|
||||
""30 Min / Tag""
|
||||
],
|
||||
""1"": [
|
||||
""Mietgebühr"",
|
||||
""2,00 € / 1 Std""
|
||||
],
|
||||
""4"": [
|
||||
""Max. Gebühr"",
|
||||
""40.00 € / Tag""
|
||||
]
|
||||
},
|
||||
""name"": ""REN E-Bike"",
|
||||
""rental_info"" : {
|
||||
""9"" : [
|
||||
""AGB"",
|
||||
""Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt""
|
||||
],
|
||||
""8"" : [
|
||||
""Tracking"",
|
||||
""Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!""
|
||||
]
|
||||
}
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
response.Create().Name,
|
||||
Is.EqualTo("REN E-Bike"));
|
||||
|
||||
Assert.That(
|
||||
response.Create().Id,
|
||||
Is.EqualTo(1));
|
||||
|
||||
Assert.That(
|
||||
response.Create().TariffEntries.Count,
|
||||
Is.EqualTo(3));
|
||||
|
||||
Assert.That(
|
||||
response.Create().InfoEntries.Count,
|
||||
Is.EqualTo(2));
|
||||
|
||||
Assert.That(
|
||||
response.Create().TariffEntries["1"].Description,
|
||||
Is.EqualTo("Mietgebühr"));
|
||||
|
||||
Assert.That(
|
||||
response.Create().TariffEntries["1"].Value,
|
||||
Is.EqualTo("2,00 € / 1 Std"));
|
||||
|
||||
Assert.That(
|
||||
response.Create().TariffEntries["4"].Description,
|
||||
Is.EqualTo("Max. Gebühr"));
|
||||
|
||||
Assert.That(
|
||||
response.Create().TariffEntries["4"].Value,
|
||||
Is.EqualTo("40.00 € / Tag"));
|
||||
|
||||
Assert.That(
|
||||
response.Create().TariffEntries["6"].Description,
|
||||
Is.EqualTo("Gratis Mietzeit"));
|
||||
|
||||
Assert.That(
|
||||
response.Create().TariffEntries["6"].Value,
|
||||
Is.EqualTo("30 Min / Tag"));
|
||||
|
||||
Assert.That(
|
||||
response.Create().InfoEntries["8"].Key,
|
||||
Is.EqualTo("Tracking"));
|
||||
|
||||
Assert.That(
|
||||
response.Create().InfoEntries["8"].Value,
|
||||
Is.EqualTo("Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!"));
|
||||
|
||||
Assert.That(
|
||||
response.Create().InfoEntries["9"].Key,
|
||||
Is.EqualTo("AGB"));
|
||||
|
||||
Assert.That(
|
||||
response.Create().InfoEntries["9"].Value,
|
||||
Is.EqualTo("Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt"));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestCreateRentalDescriptionDupeTarifElements()
|
||||
{
|
||||
var response = JsonConvertRethrow.DeserializeObject<RentalDescription>(
|
||||
@"{
|
||||
""id"": ""1"",
|
||||
""tarif_elements"" : {
|
||||
""6"": [
|
||||
""Gratis Mietzeit"",
|
||||
""30 Min / Tag""
|
||||
],
|
||||
""6"": [
|
||||
""Mietgebühr"",
|
||||
""2,00 € / 1 Std""
|
||||
],
|
||||
""4"": [
|
||||
""Max. Gebühr"",
|
||||
""40.00 € / Tag""
|
||||
]
|
||||
}
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
response.Create().TariffEntries.Count,
|
||||
Is.EqualTo(2));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateRentalDescriptionDupeInfoElements()
|
||||
{
|
||||
var response = JsonConvertRethrow.DeserializeObject<RentalDescription>(
|
||||
@"{
|
||||
""rental_info"" : {
|
||||
""9"" : [
|
||||
""AGB"",
|
||||
""Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt""
|
||||
],
|
||||
""9"" : [
|
||||
""Tracking"",
|
||||
""Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!""
|
||||
]
|
||||
}
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
response.Create().InfoEntries.Count,
|
||||
Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateRentalDescriptionsNoTariffElements()
|
||||
{
|
||||
var response = JsonConvertRethrow.DeserializeObject<RentalDescription>(
|
||||
@"{
|
||||
""rental_info"" : {
|
||||
}
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
response.Create().TariffEntries,
|
||||
Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateRentalDescriptionsNoInfoElements()
|
||||
{
|
||||
var response = JsonConvertRethrow.DeserializeObject<RentalDescription>(
|
||||
@"{
|
||||
""rental_info"" : {
|
||||
}
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
response.Create().InfoEntries,
|
||||
Is.Not.Null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,224 @@
|
|||
using NUnit.Framework;
|
||||
using TINK.Model.Connector.Updater;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
|
||||
namespace TestShareeLib.Model.Connector.Updater
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestTariffDescriptionFactory
|
||||
{
|
||||
[Test]
|
||||
public void TestCreateTariffDescription()
|
||||
{
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.50"",
|
||||
""abo_eur_per_month"" : ""920.99"",
|
||||
""free_hours"" : ""1.50"",
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().Name,
|
||||
Is.EqualTo("Tester Basic"));
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().Id,
|
||||
Is.EqualTo(5494));
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().TariffEntries["1"].Value, // Free time per session
|
||||
Is.EqualTo("1.50 hour(s)/day")); // Did not contain unit before switching signature from TariffDescription to TariffDescription2.
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().TariffEntries["2"].Value, // FeeEuroPerHour
|
||||
Is.EqualTo("10.50 €/hour")); // Did not contain unit before switching signature from TariffDescription to TariffDescription2.
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().TariffEntries["4"].Value, // Abo euro per month
|
||||
Is.EqualTo("920.99 €/month"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_Name()
|
||||
{
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.50"",
|
||||
""abo_eur_per_month"" : ""920.99"",
|
||||
""free_hours"" : ""1.50"",
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().Name,
|
||||
Is.EqualTo("Tester Basic"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_Number()
|
||||
{
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.50"",
|
||||
""abo_eur_per_month"" : ""920.99"",
|
||||
""free_hours"" : ""1.50"",
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().Id,
|
||||
Is.EqualTo(5494));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_FreeTimePerSession()
|
||||
{
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.50"",
|
||||
""abo_eur_per_month"" : ""920.99"",
|
||||
""free_hours"" : ""1.50"",
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().TariffEntries["1"].Value, // Free time per session
|
||||
Is.EqualTo("1.50 hour(s)/day")); // Did not contain unit before switching signature from TariffDescription to TariffDescription2.
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_FeeEuroPerHour()
|
||||
{
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.50"",
|
||||
""abo_eur_per_month"" : ""920.99"",
|
||||
""free_hours"" : ""1.50"",
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().TariffEntries["2"].Value, // FeeEuroPerHour
|
||||
Is.EqualTo("10.50 €/hour")); // Did not contain unit before switching signature from TariffDescription to TariffDescription2.
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_AboEuroPerMonth()
|
||||
{
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.50"",
|
||||
""abo_eur_per_month"" : ""920.99"",
|
||||
""free_hours"" : ""1.50"",
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().TariffEntries["4"].Value, // Abo euro per month
|
||||
Is.EqualTo("920.99 €/month"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_Name_Empty()
|
||||
{
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().Name,
|
||||
Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_Number_Empty()
|
||||
{
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().Id,
|
||||
Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_FreeTimePerSession_Empty()
|
||||
{
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().TariffEntries.ContainsKey("1"), // Free time per session
|
||||
Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_FeeEuroPerHour_Empty()
|
||||
{
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().TariffEntries.ContainsKey("2"), // FeeEuroPerHour
|
||||
Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_AboEuroPerMonth_Empty()
|
||||
{
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().TariffEntries.ContainsKey("4"), // Abo euro per month
|
||||
Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_Name_Null()
|
||||
{
|
||||
Assert.That(
|
||||
TariffDescriptionFactory.Create(null).Name,
|
||||
Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_Number_Null()
|
||||
{
|
||||
Assert.That(
|
||||
TariffDescriptionFactory.Create(null).Id,
|
||||
Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_FreeTimePerSession_Null()
|
||||
{
|
||||
Assert.That(
|
||||
TariffDescriptionFactory.Create(null).TariffEntries.ContainsKey("1"), // Free time per session
|
||||
Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_FeeEuroPerHour_Null()
|
||||
{
|
||||
Assert.That(
|
||||
TariffDescriptionFactory.Create(null).TariffEntries.ContainsKey("2"), // FeeEuroPerHour
|
||||
Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_AboEuroPerMonth_Null()
|
||||
{
|
||||
Assert.That(
|
||||
TariffDescriptionFactory.Create(null).TariffEntries.ContainsKey("4"), // Abo euro per month
|
||||
Is.False);
|
||||
}
|
||||
}
|
||||
}
|
809
TestShareeLib/Model/Connector/Updater/TestUpdaterJSON.cs
Normal file
809
TestShareeLib/Model/Connector/Updater/TestUpdaterJSON.cs
Normal file
|
@ -0,0 +1,809 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
|
||||
using TINK.Model.Connector.Updater;
|
||||
using TINK.Model.State;
|
||||
using TINK.Model.User.Account;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Response;
|
||||
using Xamarin.Forms;
|
||||
using static TINK.Repository.CopriCallsMemory;
|
||||
|
||||
namespace TestShareeLib.Model.Connector.Updater
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestUpdaterJSON
|
||||
{
|
||||
[Test]
|
||||
public void TestGetAllStations()
|
||||
{
|
||||
var l_oStationsTarget = new CopriCallsMemory("MyMerchId", SampleSets.Set2, 1).GetStationsAsync().Result.GetStationsAllMutable();
|
||||
|
||||
Assert.AreEqual(9, l_oStationsTarget.Count);
|
||||
|
||||
// Check first entry.
|
||||
Assert.NotNull(l_oStationsTarget.GetById("4"));
|
||||
Assert.AreEqual("TINK", string.Join(",", l_oStationsTarget.GetById("4").Group.ToArray()));
|
||||
Assert.AreEqual("4", l_oStationsTarget.GetById("4").Id);
|
||||
Assert.AreEqual(47.6586936667, l_oStationsTarget.GetById("4").Position.Latitude);
|
||||
Assert.AreEqual(9.16863116667, l_oStationsTarget.GetById("4").Position.Longitude);
|
||||
|
||||
Assert.NotNull(l_oStationsTarget.GetById("14"));
|
||||
Assert.AreEqual("Konrad", string.Join(",", l_oStationsTarget.GetById("14").Group.ToArray()));
|
||||
|
||||
Assert.NotNull(l_oStationsTarget.GetById("31"));
|
||||
Assert.AreEqual("TINK,Konrad", string.Join(",", l_oStationsTarget.GetById("31").Group.ToArray()));
|
||||
Assert.AreEqual("Südstadt Station", l_oStationsTarget.GetById("31").StationName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetAllStations_OperatorData()
|
||||
{
|
||||
var stations = JsonConvert.DeserializeObject<ResponseContainer<StationsAvailableResponse>>(STATIONS_AVAILABLE_LOGGEDIN_20210720).shareejson.GetStationsAllMutable();
|
||||
|
||||
var station = stations.FirstOrDefault(x => x.Id == "LV_3");
|
||||
Assert.That(
|
||||
station,
|
||||
Is.Not.Null,
|
||||
"Station LV_3 must exist.");
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.Color,
|
||||
Is.EqualTo(Color.FromHex("#006269")));
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.Hours,
|
||||
Is.EqualTo(string.Empty));
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.Name,
|
||||
Is.EqualTo("LastenVelo Freiburg"));
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.MailAddressText,
|
||||
Is.EqualTo("info@lastenvelofreiburg.de"));
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.PhoneNumberText,
|
||||
Is.EqualTo(string.Empty));
|
||||
|
||||
station = stations.FirstOrDefault(x => x.Id == "FR_105");
|
||||
Assert.That(
|
||||
station,
|
||||
Is.Not.Null,
|
||||
"Station FR_105 must exist.");
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.Color,
|
||||
Is.EqualTo(Color.FromHex("#009699")));
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.Hours,
|
||||
Is.EqualTo("B<>rozeiten: Montag, Mittwoch, Freitag 9-12 Uhr"));
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.Name,
|
||||
Is.EqualTo("sharee.bike | TeilRad GmbH"));
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.MailAddressText,
|
||||
Is.EqualTo("hotline@sharee.bike"));
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.PhoneNumberText,
|
||||
Is.EqualTo("+49 761 45370097"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetAllStations_OperatorData_NoOperatorData()
|
||||
{
|
||||
var stations = JsonConvert.DeserializeObject<ResponseContainer<StationsAvailableResponse>>(@"
|
||||
{
|
||||
""shareejson"": {
|
||||
""lang"": ""DE"",
|
||||
""impress_html"": ""site/impress.html"",
|
||||
""tariff_info_html"": ""site/tariff_info_1.html"",
|
||||
""debuglevel"": ""1"",
|
||||
""user_tour"": [
|
||||
null,
|
||||
""""
|
||||
],
|
||||
""response"": ""stations_available"",
|
||||
""user_id"": ""ohauff@posteo.de"",
|
||||
""stations"": {
|
||||
""LV_3"": {
|
||||
""service_tour"": ""LV_1"",
|
||||
""uri_operator"": ""https://shareeapp-lv.copri.eu"",
|
||||
""authed"": ""1"",
|
||||
""station"": ""LV_3"",
|
||||
""gps"": {
|
||||
""latitude"": ""47.9973"",
|
||||
""longitude"": ""7.8585""
|
||||
},
|
||||
""gps_radius"": ""100"",
|
||||
""description"": ""Katholische Akademie"",
|
||||
""state"": ""available"",
|
||||
""station_group"": [
|
||||
""LV_300005""
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
}").shareejson.GetStationsAllMutable();
|
||||
|
||||
var station = stations.FirstOrDefault(x => x.Id == "LV_3");
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.Color,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.Hours,
|
||||
Is.EqualTo(string.Empty));
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.Name,
|
||||
Is.EqualTo(string.Empty));
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.MailAddressText,
|
||||
Is.EqualTo(string.Empty));
|
||||
|
||||
Assert.That(
|
||||
station.OperatorData.PhoneNumberText,
|
||||
Is.EqualTo(string.Empty));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUpdateBikesAvailable_BikeNr5GetBooked()
|
||||
{
|
||||
// Bike 5 is availalbe.
|
||||
var l_oBikesTarget = GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 1).GetBikesAvailable(
|
||||
);
|
||||
|
||||
Assert.AreEqual(12, l_oBikesTarget.Count, "Bike 5 is available an must be part of available bikes collection");
|
||||
|
||||
// Verify state of bike 5.
|
||||
Assert.NotNull(l_oBikesTarget.GetById("5"));
|
||||
Assert.AreEqual("5", l_oBikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, l_oBikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, l_oBikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikesTarget.GetById("5").State.Value);
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5").State.Code);
|
||||
|
||||
// Bike 5 is reserved.
|
||||
// Count of bikes must decrease and bike #5 no more in list of bikes.
|
||||
l_oBikesTarget = GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 2).GetBikesAvailable(
|
||||
);
|
||||
|
||||
Assert.AreEqual(11, l_oBikesTarget.Count, "One bike (nr. 5) got reserved");
|
||||
Assert.Null(l_oBikesTarget.GetById("5"), "Bike 5 got requested and must not be part of available bikes collection");
|
||||
|
||||
// Bike 5 is booked.
|
||||
// Count of bikes must decrease and bike #5 no more in list of bikes.
|
||||
l_oBikesTarget = GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 3).GetBikesAvailable(
|
||||
);
|
||||
|
||||
Assert.Null(l_oBikesTarget.GetById("5"), "Bike 5 got booked and must not be part of available bikes collection");
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUpdateBikesOccupied_BikeNr5GetBooked()
|
||||
{
|
||||
var l_oBikesTarget = GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 1).GetBikesOccupied(
|
||||
"a@B",
|
||||
() => new DateTime(2017, 11, 28, 14, 8, 14)); // Date time now for bikes which are reserved
|
||||
|
||||
// Check initial count of bikes.
|
||||
Assert.AreEqual(
|
||||
2,
|
||||
l_oBikesTarget.Count);
|
||||
|
||||
// Bike 5 is reserved
|
||||
l_oBikesTarget = GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 2).GetBikesOccupied(
|
||||
"a@B",
|
||||
() => new DateTime(2017, 11, 28, 14, 08, 36).Add(new TimeSpan(0, 2, 0))); // Date time now for bikes which are reserved
|
||||
|
||||
Assert.AreEqual(3, l_oBikesTarget.Count, "One bike (nr. 5) got reserved");
|
||||
|
||||
Assert.NotNull(l_oBikesTarget.GetById("5"));
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oBikesTarget.GetById("5").State.Value);
|
||||
Assert.AreEqual("5", l_oBikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, l_oBikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, l_oBikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(DateTime.Parse("2017-11-28 14:07:13.745568+01"), l_oBikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
|
||||
|
||||
// Bike 5 is booked
|
||||
l_oBikesTarget = GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 3).GetBikesOccupied(
|
||||
"a@B",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(3, l_oBikesTarget.Count, "One bike (nr. 5) got booked");
|
||||
|
||||
Assert.IsNotNull(l_oBikesTarget.GetById("5"));
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oBikesTarget.GetById("5").State.Value);
|
||||
Assert.AreEqual("5", l_oBikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, l_oBikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, l_oBikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(DateTime.Parse("2017 -11-28 14:08:32.756368+01"), l_oBikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
}
|
||||
|
||||
public void TestGetBikesAvailable_BikeNr5GetBooked()
|
||||
{
|
||||
// Bike 5 is availalbe.
|
||||
var l_oBikesTarget = GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 1).GetBikesAvailable();
|
||||
|
||||
Assert.AreEqual(11, l_oBikesTarget.Count, "Bike 5 is available an must be part of available bikes collection");
|
||||
|
||||
// Verify state of bike 5.
|
||||
Assert.NotNull(l_oBikesTarget.GetById("5"));
|
||||
Assert.AreEqual(5, l_oBikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, l_oBikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, l_oBikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikesTarget.GetById("5").State.Value);
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5").State.Code);
|
||||
|
||||
// Bike 5 is reserved.
|
||||
// Count of bikes must decrease and bike #5 no more in list of bikes.
|
||||
l_oBikesTarget = GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 2).GetBikesAvailable();
|
||||
|
||||
Assert.AreEqual(10, l_oBikesTarget.Count, "One bike (nr. 5) got reserved");
|
||||
Assert.Null(l_oBikesTarget.GetById("5"), "Bike 5 got requested and must not be part of available bikes collection");
|
||||
|
||||
// Bike 5 is booked.
|
||||
// Count of bikes must decrease and bike #5 no more in list of bikes.
|
||||
l_oBikesTarget = GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 3).GetBikesAvailable();
|
||||
|
||||
Assert.Null(l_oBikesTarget.GetById("5"), "Bike 5 got booked and must not be part of available bikes collection");
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesOccupied_BC_BikeNr5GetBooked()
|
||||
{
|
||||
var bikesTarget = GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 1).GetBikesOccupied(
|
||||
"a@B",
|
||||
() => new DateTime(2017, 11, 28, 14, 8, 14)); // Date time now for bikes which are reserved
|
||||
|
||||
// Check initial count of bikes.
|
||||
Assert.AreEqual(2, bikesTarget.Count);
|
||||
|
||||
// Bike 5 is reserved
|
||||
bikesTarget = GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 2).GetBikesOccupied(
|
||||
"a@B",
|
||||
() => new DateTime(2017, 11, 28, 14, 08, 36).Add(new TimeSpan(0, 2, 0))); // Date time now for bikes which are reserved
|
||||
|
||||
Assert.AreEqual(3, bikesTarget.Count, "One bike (nr. 5) got reserved");
|
||||
|
||||
Assert.NotNull(bikesTarget.GetById("5"));
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, bikesTarget.GetById("5").State.Value);
|
||||
Assert.AreEqual("5", bikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual("Cargo Long", bikesTarget.GetById("5").Description);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, bikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, bikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(DateTime.Parse("2017-11-28 14:07:13.745568+01"), bikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
|
||||
// Bike 5 is booked
|
||||
bikesTarget = GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 3).GetBikesOccupied(
|
||||
"a@B",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(3, bikesTarget.Count, "One bike (nr. 5) got booked");
|
||||
|
||||
Assert.IsNotNull(bikesTarget.GetById("5"));
|
||||
Assert.AreEqual(InUseStateEnum.Booked, bikesTarget.GetById("5").State.Value);
|
||||
Assert.AreEqual("5", bikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual("Cargo Long", bikesTarget.GetById("5").Description);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, bikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, bikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(DateTime.Parse("2017 -11-28 14:08:32.756368+01"), bikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesOccupied_Bt_BikeNr5GetBooked()
|
||||
{
|
||||
var bikesTarget = GetBikesOccupied("5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH", SampleSets.ShareeFr01_Set1, 1).GetBikesOccupied(
|
||||
"a@B",
|
||||
() => new DateTime(2017, 11, 28, 14, 8, 14)); // Date time now for bikes which are reserved
|
||||
|
||||
// Check initial count of bikes.
|
||||
Assert.AreEqual(2, bikesTarget.Count);
|
||||
|
||||
// Bike 5 is reserved
|
||||
bikesTarget = GetBikesOccupied("5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH", SampleSets.ShareeFr01_Set1, 2).GetBikesOccupied(
|
||||
"a@B",
|
||||
() => new DateTime(2017, 11, 28, 14, 08, 36).Add(new TimeSpan(0, 2, 0))); // Date time now for bikes which are reserved
|
||||
|
||||
Assert.AreEqual(3, bikesTarget.Count, "One bike (nr. 5) got reserved");
|
||||
|
||||
var btBikeReserved = bikesTarget.GetById("FR_1004") as TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo;
|
||||
Assert.NotNull(btBikeReserved);
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, bikesTarget.GetById("FR_1004").State.Value);
|
||||
Assert.AreEqual("FR_1004", btBikeReserved.Id);
|
||||
Assert.AreEqual("Tester-bike Oliver 2", btBikeReserved.Description);
|
||||
Assert.That(btBikeReserved.TypeOfBike, Is.Null);
|
||||
Assert.That(btBikeReserved.WheelType, Is.Null);
|
||||
Assert.AreEqual(DateTime.Parse("2021-07-04 17:46:36.237404+02"), btBikeReserved.State.From); // Sommer/ Winterzeit!
|
||||
Assert.That(btBikeReserved.State.Code, Is.EqualTo(string.Empty), "Not needed for bt bikes.");
|
||||
Assert.That(
|
||||
btBikeReserved.TariffDescription.TariffEntries["2"].Value, // FeeEuroPerHour
|
||||
Is.EqualTo("3.00 €/hour"));
|
||||
Assert.That(
|
||||
btBikeReserved.TariffDescription.TariffEntries["3"].Value, // MaxFeeEuroPerDay
|
||||
Is.EqualTo("10.00 €/day"));
|
||||
Assert.That(btBikeReserved.TariffDescription.Id, Is.EqualTo(5494));
|
||||
Assert.That(btBikeReserved.TariffDescription.Name, Is.EqualTo("Tester Basic"));
|
||||
Assert.That(btBikeReserved.StationId, Is.EqualTo("FR_103"));
|
||||
Assert.That(btBikeReserved.LockInfo.Id, Is.EqualTo(2302373));
|
||||
Assert.That(btBikeReserved.OperatorUri.AbsoluteUri, Does.Contain("https://shareeapp-fr01.copri.eu"));
|
||||
Assert.That(btBikeReserved.Group.Count, Is.EqualTo(1));
|
||||
Assert.That(btBikeReserved.Group.ToArray()[0], Is.EqualTo("FR_300029"));
|
||||
|
||||
// Bike 5 is booked
|
||||
var btBikeRented = bikesTarget.GetById("1537") as TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo;
|
||||
|
||||
Assert.IsNotNull(btBikeRented);
|
||||
Assert.AreEqual(InUseStateEnum.Booked, btBikeRented.State.Value);
|
||||
Assert.AreEqual("1537", btBikeRented.Id);
|
||||
Assert.AreEqual("Oliver (Ilockit)", btBikeRented.Description);
|
||||
Assert.That(btBikeRented.TypeOfBike, Is.Null);
|
||||
Assert.That(btBikeRented.WheelType, Is.Null);
|
||||
Assert.AreEqual(DateTime.Parse("2020-10-12 08:38:30.401679+02"), btBikeRented.State.From); // Sommer/ Winterzeit!
|
||||
Assert.AreEqual(string.Empty, btBikeRented.State.Code, "Not needed for bt bikes.");
|
||||
Assert.That(
|
||||
btBikeRented.TariffDescription.TariffEntries["2"].Value, // FeeEuroPerHour
|
||||
Is.EqualTo("2.50 €/hour"));
|
||||
Assert.That(
|
||||
btBikeRented.TariffDescription.TariffEntries["3"].Value, // MaxFeeEuroPerDay
|
||||
Is.EqualTo("10.00 €/day"));
|
||||
Assert.That(btBikeRented.TariffDescription.Id, Is.EqualTo(5494));
|
||||
Assert.That(btBikeRented.TariffDescription.Name, Is.EqualTo("Tester Basic"));
|
||||
Assert.That(btBikeRented.StationId, Is.EqualTo("103"));
|
||||
Assert.That(btBikeRented.LockInfo.Id, Is.EqualTo(2200537));
|
||||
Assert.That(btBikeRented.OperatorUri.AbsoluteUri, Does.Contain("https://shareeapp-fr01.copri.eu"));
|
||||
Assert.That(btBikeRented.Group.Count, Is.EqualTo(1));
|
||||
Assert.That(btBikeRented.Group.ToArray()[0], Is.EqualTo("300029"));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAvailable()
|
||||
{
|
||||
var bikesTarget = GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 1).GetBikesAvailable(
|
||||
);
|
||||
|
||||
// Verify count of bikes
|
||||
Assert.AreEqual(12, bikesTarget.Count);
|
||||
|
||||
// Verify properties of bike 5
|
||||
Assert.NotNull(bikesTarget.GetById("5"));
|
||||
Assert.AreEqual("5", bikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual("TINK", bikesTarget.GetById("5").Group.ToArray()[0]);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, bikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, bikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, bikesTarget.GetById("5").State.Value);
|
||||
Assert.IsNull(bikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
Assert.IsNull(bikesTarget.GetById("5").State.Code);
|
||||
|
||||
// Verify properties of bike 52
|
||||
Assert.NotNull(bikesTarget.GetById("52"));
|
||||
Assert.AreEqual("52", bikesTarget.GetById("52").Id);
|
||||
Assert.AreEqual("Konrad", bikesTarget.GetById("52").Group.ToArray()[0]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesOccupied()
|
||||
{
|
||||
var l_oBikesTarget = GetBikesOccupied(TinkApp.MerchantId, SampleSets.Set2, 1).GetBikesOccupied(
|
||||
"a@b",
|
||||
() => DateTime.Now);
|
||||
|
||||
// Verify count of bikes
|
||||
Assert.AreEqual(2, l_oBikesTarget.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAll_BikesAvaialbleResponse()
|
||||
{
|
||||
var availableResponse = JsonConvert.DeserializeObject<BikesAvailableResponse>(
|
||||
@"{
|
||||
""bikes"" : {
|
||||
""2352"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
||||
""station"" : ""9"",
|
||||
""system"" : ""Ilockit""
|
||||
},
|
||||
""2379"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""19"",
|
||||
""gps"" : { ""latitude"": ""47.6597846667"", ""longitude"": ""9.177439"" },
|
||||
""station"" : ""3""
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var bikes = UpdaterJSON.GetBikesAll(
|
||||
availableResponse?.bikes?.Values,
|
||||
null,
|
||||
"Heinz.Mustermann@posteo.de",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(
|
||||
2,
|
||||
bikes.Count);
|
||||
|
||||
Assert.AreEqual(
|
||||
1,
|
||||
bikes.Where(x => x is TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo).Count(),
|
||||
"There must be one ILockitBike and one BC bike (BikeInfo class).");
|
||||
}
|
||||
[Test]
|
||||
public void TestGetBikesAll_BikesAvaialbleResponse_InvalidState()
|
||||
{
|
||||
var availableResponse = JsonConvert.DeserializeObject<BikesAvailableResponse>(
|
||||
@"{
|
||||
""bikes"" : {
|
||||
""2352"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""reserved"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
||||
""station"" : ""9""
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var bikes = UpdaterJSON.GetBikesAll(
|
||||
availableResponse?.bikes?.Values,
|
||||
null,
|
||||
"Heinz.Mustermann@posteo.de",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
bikes.Count,
|
||||
"State of a element of BikesAvailableResponse must never be reserved.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAll_BikesAvaialbleResponse_InvalidStation()
|
||||
{
|
||||
var availableResponse = JsonConvert.DeserializeObject<BikesAvailableResponse>(
|
||||
@"{
|
||||
""bikes"" : {
|
||||
""2352"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
||||
""station"" : """"
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var bikes = UpdaterJSON.GetBikesAll(
|
||||
availableResponse?.bikes?.Values,
|
||||
null,
|
||||
"Heinz.Mustermann@posteo.de",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
bikes.Count,
|
||||
"Station of a element of BikesAvailableResponse must always be defined.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAll_BikesAvaialbleResponse_DuplicateId()
|
||||
{
|
||||
var availableResponse = JsonConvert.DeserializeObject<BikesAvailableResponse>(
|
||||
@"{
|
||||
""bikes"" : {
|
||||
""2352"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
||||
""station"" : ""9""
|
||||
},
|
||||
""2379"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.6597846667"", ""longitude"": ""9.177439"" },
|
||||
""station"" : ""3""
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var bikes = UpdaterJSON.GetBikesAll(
|
||||
availableResponse?.bikes?.Values,
|
||||
null,
|
||||
"Heinz.Mustermann@posteo.de",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
bikes.Count,
|
||||
"Ids of a elements of BikesAvailableResponse must be unique.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAll_BikesReservedOccupiedResponse_DuplicateId()
|
||||
{
|
||||
var reservedOccupiedResponse = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(
|
||||
@"{
|
||||
""bikes_occupied"" : {
|
||||
""87785"" : {
|
||||
""station"" : ""2"",
|
||||
""state"" : ""occupied"",
|
||||
""bike"" : ""20"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""start_time"" : ""2017-12-01 22:21:57.740069+01"",
|
||||
""timeCode"" : ""6603""
|
||||
},
|
||||
""87782"" : {
|
||||
""station"" : ""4"",
|
||||
""state"" : ""occupied"",
|
||||
""bike"" : ""20"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""start_time"" : ""2017-11-28 13:06:55.147368+01"",
|
||||
""timeCode"" : ""2931""
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var bikes = UpdaterJSON.GetBikesAll(
|
||||
null,
|
||||
reservedOccupiedResponse?.bikes_occupied?.Values,
|
||||
"Heinz.Mustermann@posteo.de",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
bikes.Count,
|
||||
"Ids of a elements of BikesAvailableResponse must be unique.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAll_BikesReservedOccupiedResponse()
|
||||
{
|
||||
var reservedOccupiedResponse = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(
|
||||
@"{
|
||||
""bikes_occupied"" : {
|
||||
""87785"" : {
|
||||
""station"" : ""2"",
|
||||
""state"" : ""occupied"",
|
||||
""bike"" : ""20"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""start_time"" : ""2017-12-01 22:21:57.740069+01"",
|
||||
""timeCode"" : ""6603"",
|
||||
""system"" : ""Ilockit""
|
||||
},
|
||||
""87782"" : {
|
||||
""station"" : ""4"",
|
||||
""state"" : ""occupied"",
|
||||
""bike"" : ""7"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""start_time"" : ""2017-11-28 13:06:55.147368+01"",
|
||||
""timeCode"" : ""2931""
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var bikes = UpdaterJSON.GetBikesAll(
|
||||
null,
|
||||
reservedOccupiedResponse?.bikes_occupied?.Values,
|
||||
"Heinz.Mustermann@posteo.de",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(
|
||||
2,
|
||||
bikes.Count,
|
||||
"Ids of a elements of BikesAvailableResponse must be unique.");
|
||||
|
||||
Assert.AreEqual(
|
||||
1,
|
||||
bikes.Where(x => x is TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo).Count(),
|
||||
"There must be one ILockitBike and one BC bike (BikeInfo class).");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLoad_Reserved_CalculateAuthKeys()
|
||||
{
|
||||
// Construct requested bike.
|
||||
var bike = new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfoMutable(new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo(
|
||||
new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("17", LockModel.ILockIt),
|
||||
new Drive(),
|
||||
22,
|
||||
new Guid("0000f00d-1212-efde-1523-785fef13d123"),
|
||||
new[] { (byte)1, (byte)3, (byte)4 },
|
||||
new[] { (byte)11, (byte)3, (byte)1 },
|
||||
new[] { (byte)12, (byte)7, (byte)4 },
|
||||
DateTime.Now,
|
||||
"a@b",
|
||||
"1",
|
||||
null,
|
||||
null,
|
||||
() => DateTime.Now,
|
||||
false, /*isDemo*/
|
||||
null /*group*/),
|
||||
"My Station Name");
|
||||
|
||||
var response = JsonConvert.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
||||
{
|
||||
""Ilockit_ID"": ""ISHAREIT+0815"",
|
||||
""state"": ""requested"",
|
||||
""start_time"": ""2018-01-27 17:33:00.989464+01"",
|
||||
""K_seed"": ""[-18, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
||||
""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]"",
|
||||
}");
|
||||
|
||||
// Update from new auth keys.
|
||||
bike.Load(response, "a@b");
|
||||
|
||||
// Verify that keys are correctly updated.
|
||||
Assert.IsTrue(new byte[] { 256 - 18, 256 - 80, 20, 256 - 90, 3, 69, 96, 4, 256 - 35, 75, 256 - 95, 102, 7, 121, 256 - 122, 15 }.SequenceEqual(bike.LockInfo.Seed));
|
||||
Assert.IsTrue(new byte[] { 99, 104, 120, 121, 63, 99, 256 - 10, 256 - 110, 94, 70, 15, 256 - 112, 256 - 6, 101, 117, 256 - 90, 256 - 113, 256 - 54, 256 - 90, 256 - 95, 0, 0, 0, 0 }.SequenceEqual(bike.LockInfo.UserKey));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLoad_Booked_CalculateAuthKeys()
|
||||
{
|
||||
// Construct occupied bike.
|
||||
var bike = new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfoMutable(new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo(
|
||||
new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("17", LockModel.ILockIt), new Drive(),
|
||||
22,
|
||||
new Guid("0000f00d-1212-efde-1523-785fef13d123"),
|
||||
new[] { (byte)1, (byte)3, (byte)4 },
|
||||
new[] { (byte)11, (byte)3, (byte)1 },
|
||||
new[] { (byte)12, (byte)7, (byte)4 },
|
||||
DateTime.Now,
|
||||
"a@b",
|
||||
"1",
|
||||
null /*operator uri*/),
|
||||
"My Station Name");
|
||||
|
||||
var response = JsonConvert.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
||||
{
|
||||
""Ilockit_ID"": ""ISHAREIT+0815"",
|
||||
""state"": ""occupied"",
|
||||
""start_time"": ""2018-01-27 17:33:00.989464+01"",
|
||||
""K_seed"": ""[-18, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
||||
""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]"",
|
||||
}");
|
||||
|
||||
// Update from new auth keys.
|
||||
bike.Load(response, "a@b");
|
||||
|
||||
// Verify that keys are correctly updated.
|
||||
Assert.IsTrue(new byte[] { 256 - 18, 256 - 80, 20, 256 - 90, 3, 69, 96, 4, 256 - 35, 75, 256 - 95, 102, 7, 121, 256 - 122, 15 }.SequenceEqual(bike.LockInfo.Seed));
|
||||
Assert.IsTrue(new byte[] { 99, 104, 120, 121, 63, 99, 256 - 10, 256 - 110, 94, 70, 15, 256 - 112, 256 - 6, 101, 117, 256 - 90, 256 - 113, 256 - 54, 256 - 90, 256 - 95, 0, 0, 0, 0 }.SequenceEqual(bike.LockInfo.UserKey));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLoad_Reserved_DoBook()
|
||||
{
|
||||
// Construct requested bike.
|
||||
var bike = new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfoMutable(new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo(
|
||||
new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("17", LockModel.ILockIt),
|
||||
new Drive(),
|
||||
22,
|
||||
new Guid("0000f00d-1212-efde-1523-785fef13d123"),
|
||||
new[] { (byte)1, (byte)3, (byte)4 },
|
||||
new[] { (byte)11, (byte)3, (byte)1 },
|
||||
new[] { (byte)12, (byte)7, (byte)4 },
|
||||
DateTime.Now,
|
||||
"a@b",
|
||||
"1",
|
||||
null,
|
||||
null,
|
||||
() => DateTime.Now,
|
||||
false, /*isDemo*/
|
||||
null /*group*/),
|
||||
"My Station Name");
|
||||
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, bike.State.Value);
|
||||
|
||||
var response = JsonConvert.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
||||
{
|
||||
""Ilockit_ID"": ""ISHAREIT+0815"",
|
||||
""state"": ""occupied"",
|
||||
""start_time"": ""2018-01-27 17:33:00.989464+01"",
|
||||
""K_seed"": ""[-18, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
||||
""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]"",
|
||||
}");
|
||||
|
||||
// Update from new auth keys.
|
||||
bike.Load(response, "a@b");
|
||||
|
||||
Assert.AreEqual(InUseStateEnum.Booked, bike.State.Value);
|
||||
}
|
||||
|
||||
/// <summary> Verifies loading a default user without special permissions.</summary>
|
||||
[Test]
|
||||
public void TestGetAccount_DebugLevelNone()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<AuthorizationResponse>(@"
|
||||
{
|
||||
""response_state"" : ""OK: nothing todo "",
|
||||
""user_group"" : [ ""300029"", ""300001"" ],
|
||||
""user_id"" : ""ohauff@posteo.de"",
|
||||
""authcookie"" : ""5781_f172cf59108fe53e7524c841847fee69_oiF2kahH"",
|
||||
""response"" : ""authorization"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""response_text"" : ""Herzlich willkommen im Fahrradmietsystem"",
|
||||
""debuglevel"" : ""0"",
|
||||
""apiserver"" : ""https://shareeapp-fr01.copri.eu""
|
||||
}");
|
||||
|
||||
var account = response.GetAccount("merch123", "hallo@welt", "0815");
|
||||
|
||||
Assert.That(
|
||||
account.DebugLevel,
|
||||
Is.EqualTo(Permissions.None));
|
||||
}
|
||||
|
||||
/// <summary> Verifies loading a admin user with all special permissions.</summary>
|
||||
[Test]
|
||||
public void TestGetAccount_DebugLevelAll()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<AuthorizationResponse>(@"
|
||||
{
|
||||
""response_state"" : ""OK: nothing todo "",
|
||||
""user_group"" : [ ""300029"", ""300001"" ],
|
||||
""user_id"" : ""ohauff@posteo.de"",
|
||||
""authcookie"" : ""5781_f172cf59108fe53e7524c841847fee69_oiF2kahH"",
|
||||
""response"" : ""authorization"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""response_text"" : ""Herzlich willkommen im Fahrradmietsystem"",
|
||||
""debuglevel"" : ""1"",
|
||||
""apiserver"" : ""https://shareeapp-fr01.copri.eu""
|
||||
}");
|
||||
|
||||
var account = response.GetAccount("merch123", "hallo@welt", "0815");
|
||||
|
||||
Assert.That(
|
||||
account.DebugLevel,
|
||||
Is.EqualTo(Permissions.All));
|
||||
}
|
||||
|
||||
/// <summary> Verifies loading a admin user with all special permissions.</summary>
|
||||
[Test]
|
||||
public void TestGetAccount_DebugLevel_Logging()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<AuthorizationResponse>(@"
|
||||
{
|
||||
""response_state"" : ""OK: nothing todo "",
|
||||
""user_group"" : [ ""300029"", ""300001"" ],
|
||||
""user_id"" : ""ohauff@posteo.de"",
|
||||
""authcookie"" : ""5781_f172cf59108fe53e7524c841847fee69_oiF2kahH"",
|
||||
""response"" : ""authorization"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""response_text"" : ""Herzlich willkommen im Fahrradmietsystem"",
|
||||
""debuglevel"" : ""64"",
|
||||
""apiserver"" : ""https://shareeapp-fr01.copri.eu""
|
||||
}");
|
||||
|
||||
var account = response.GetAccount("merch123", "hallo@welt", "0815");
|
||||
|
||||
Assert.That(
|
||||
account.DebugLevel,
|
||||
Is.EqualTo(Permissions.PickLoggingLevel));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue