Version 3.0.294

This commit is contained in:
Oliver Hauff 2022-04-25 22:15:15 +02:00
parent d92fb4a40f
commit 8f40f2c208
133 changed files with 17890 additions and 14246 deletions

View file

@ -0,0 +1,201 @@
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)));
}
}
}

View file

@ -734,5 +734,149 @@ namespace TestTINKLib.Fixtures.Connector
() => response.GetIsAgbAcknowledged(),
Is.False);
}
[Test]
public void TestGetLockModelBluetooth()
{
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : ""Ilockit""
}");
Assert.That(
response.GetLockModel(),
Is.EqualTo(LockModel.ILockIt));
}
[Test]
public void TestGetLockModelSigo()
{
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : ""SIGO""
}");
Assert.That(
response.GetLockModel(),
Is.EqualTo(LockModel.Sigo));
}
[Test]
public void TestGetLockModelBordComputer()
{
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : ""LOCK""
}");
Assert.That(
response.GetLockModel(),
Is.EqualTo(LockModel.BordComputer));
}
[Test]
public void TestGetLockModelUnknown()
{
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : """"
}");
Assert.That(
response.GetLockModel(),
Is.Null);
}
[Test]
public void TestGetCopriLockingStateClosed()
{
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : """",
""lock_state"" : ""locked""
}");
Assert.That(
TextToTypeHelper.GetCopriLockingState(response),
Is.EqualTo(TINK.Model.Bikes.Bike.CopriLock.LockingState.Closed));
}
[Test]
public void TestGetCopriLockingStateClosing()
{
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : """",
""lock_state"" : ""locking""
}");
Assert.That(
TextToTypeHelper.GetCopriLockingState(response),
Is.EqualTo(TINK.Model.Bikes.Bike.CopriLock.LockingState.Closing));
}
[Test]
public void TestGetCopriLockingStateOpen()
{
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : """",
""lock_state"" : ""unlocked""
}");
Assert.That(
TextToTypeHelper.GetCopriLockingState(response),
Is.EqualTo(TINK.Model.Bikes.Bike.CopriLock.LockingState.Open));
}
[Test]
public void TestGetCopriLockingStateOpening()
{
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : """",
""lock_state"" : ""unlocking""
}");
Assert.That(
TextToTypeHelper.GetCopriLockingState(response),
Is.EqualTo(TINK.Model.Bikes.Bike.CopriLock.LockingState.Opening));
}
}
}

View file

@ -168,7 +168,7 @@ namespace TestTINKLib.Fixtures.Connector
{
// Bike 5 is availalbe.
var l_oBikesTarget = UpdaterJSON.GetBikesAvailable(
GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 1));
GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 1));
Assert.AreEqual(12, l_oBikesTarget.Count, "Bike 5 is available an must be part of available bikes collection");
@ -184,7 +184,7 @@ namespace TestTINKLib.Fixtures.Connector
// Bike 5 is reserved.
// Count of bikes must decrease and bike #5 no more in list of bikes.
l_oBikesTarget = UpdaterJSON.GetBikesAvailable(
GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 2));
GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 2));
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");
@ -192,7 +192,7 @@ namespace TestTINKLib.Fixtures.Connector
// Bike 5 is booked.
// Count of bikes must decrease and bike #5 no more in list of bikes.
l_oBikesTarget = UpdaterJSON.GetBikesAvailable(
GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 3));
GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 3));
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"));
@ -207,7 +207,9 @@ namespace TestTINKLib.Fixtures.Connector
() => 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);
Assert.AreEqual(
2,
l_oBikesTarget.Count);
// Bike 5 is reserved
l_oBikesTarget = UpdaterJSON.GetBikesOccupied(
@ -223,7 +225,6 @@ namespace TestTINKLib.Fixtures.Connector
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!
Assert.AreEqual("2360", l_oBikesTarget.GetById("5").State.Code);
// Bike 5 is booked
@ -240,13 +241,12 @@ namespace TestTINKLib.Fixtures.Connector
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!
Assert.AreEqual("2360", l_oBikesTarget.GetById("5").State.Code);
}
public void TestGetBikesAvailable_BikeNr5GetBooked()
{
// Bike 5 is availalbe.
var l_oBikesTarget = UpdaterJSON.GetBikesAvailable(GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 1));
var l_oBikesTarget = UpdaterJSON.GetBikesAvailable(GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 1));
Assert.AreEqual(11, l_oBikesTarget.Count, "Bike 5 is available an must be part of available bikes collection");
@ -261,14 +261,14 @@ namespace TestTINKLib.Fixtures.Connector
// Bike 5 is reserved.
// Count of bikes must decrease and bike #5 no more in list of bikes.
l_oBikesTarget = UpdaterJSON.GetBikesAvailable(GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 2));
l_oBikesTarget = UpdaterJSON.GetBikesAvailable(GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 2));
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 = UpdaterJSON.GetBikesAvailable(GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 3));
l_oBikesTarget = UpdaterJSON.GetBikesAvailable(GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 3));
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"));
@ -300,7 +300,6 @@ namespace TestTINKLib.Fixtures.Connector
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!
Assert.AreEqual("2360", bikesTarget.GetById("5").State.Code);
// Bike 5 is booked
bikesTarget = UpdaterJSON.GetBikesOccupied(
@ -317,7 +316,6 @@ namespace TestTINKLib.Fixtures.Connector
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!
Assert.AreEqual("2360", bikesTarget.GetById("5").State.Code);
}
[Test]
@ -385,7 +383,7 @@ namespace TestTINKLib.Fixtures.Connector
public void TestGetBikesAvailable()
{
var l_oBikesTarget = UpdaterJSON.GetBikesAvailable(
GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 1));
GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 1));
// Verify count of bikes
Assert.AreEqual(12, l_oBikesTarget.Count);
@ -691,7 +689,7 @@ namespace TestTINKLib.Fixtures.Connector
}");
// Update from new auth keys.
bike.Load(response, "a@b", () => DateTime.Now);
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));
@ -725,7 +723,7 @@ namespace TestTINKLib.Fixtures.Connector
}");
// Update from new auth keys.
bike.Load(response, "a@b", () => DateTime.Now);
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));
@ -768,7 +766,7 @@ namespace TestTINKLib.Fixtures.Connector
}");
// Update from new auth keys.
bike.Load(response, "a@b", () => DateTime.Now);
bike.Load(response, "a@b");
Assert.AreEqual(InUseStateEnum.Booked, bike.State.Value);
}