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

@ -14,17 +14,18 @@ namespace TestTINKLib
{
public BikeInfoMutable(
string id,
LockModel lockType,
bool isDemo = false,
IEnumerable<string> group = null,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
TypeOfBike? typeOfBike = null,
string description = null,
string stationId = null,
string stationName = null,
Uri operatorUri = null,
TariffDescription tariffDescription = null,
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null) : base(id, isDemo, group, wheelType, typeOfBike, description, stationId, stationName, operatorUri, tariffDescription, dateTimeProvider, stateInfo)
IStateInfo stateInfo = null) : base(id, lockType, isDemo, group, wheelType, typeOfBike, description, stationId, stationName, operatorUri, tariffDescription, dateTimeProvider, stateInfo)
{
}
}
@ -34,6 +35,7 @@ namespace TestTINKLib
{
var l_oBike = new BikeInfoMutable(
"42",
LockModel.ILockIt,
false,
new List<string> { "TINK" },
WheelType.Two,
@ -48,10 +50,11 @@ namespace TestTINKLib
l_oBike = new BikeInfoMutable(
"17",
LockModel.ILockIt,
true,
new List<string> { "TINK" },
WheelType.Mono,
TypeOfBike.Allround,
TypeOfBike.Allround,
"Test description",
"1");
@ -66,13 +69,13 @@ namespace TestTINKLib
[Test]
public void TestToString()
{
var l_oBike = new BikeInfoMutable("3", false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Cargo, dateTimeProvider: () => new DateTime(1970, 1, 1));
var l_oBike = new BikeInfoMutable("3", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Cargo, dateTimeProvider: () => new DateTime(1970, 1, 1));
Assert.AreEqual(
"Id=3, wheel(s)=Two, type=Cargo, demo=False, state=Disposable, location=On the road.",
l_oBike.ToString());
l_oBike = new BikeInfoMutable("3", true, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "5", dateTimeProvider: () => new DateTime(1970, 1, 1));
l_oBike = new BikeInfoMutable("3", LockModel.ILockIt, true, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "5", dateTimeProvider: () => new DateTime(1970, 1, 1));
Assert.AreEqual(
"Id=3, wheel(s)=Trike, type=Allround, demo=True, state=Disposable, location=Station 5.",
l_oBike.ToString());

View file

@ -1,5 +1,6 @@
using NUnit.Framework;
using System;
using TINK.Model.Bike;
using TINK.Model.Bike.BluetoothLock;
using TINK.Model.State;
@ -11,12 +12,12 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
[Test]
public void TestCtorCopyNull()
{
Assert.Throws<System.ArgumentException>(
Assert.Throws<ArgumentException>(
() => new BikeInfo(null, null),
"Verify that no unspecific reference not set to... exception is thrown");
Assert.Throws<System.ArgumentException>(
() => new BikeInfo(new TINK.Model.Bike.BC.BikeInfo("12", "1"), null),
Assert.Throws<ArgumentException>(
() => new BikeInfo(new TINK.Model.Bike.BC.BikeInfo("12", LockModel.ILockIt, "1"), null),
"Verify that no unspecific reference not set to... exception is thrown");
}

View file

@ -10,12 +10,12 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
[Test]
public void TestConstruct()
{
var l_oBike = new Bike("43");
var l_oBike = new Bike("43", LockModel.ILockIt);
Assert.AreEqual("43", l_oBike.Id);
Assert.AreEqual(null, l_oBike.TypeOfBike);
Assert.AreEqual(null, l_oBike.WheelType);
l_oBike = new Bike("43", WheelType.Mono, TypeOfBike.Cargo);
l_oBike = new Bike("43", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Cargo);
Assert.AreEqual("43", l_oBike.Id);
Assert.AreEqual(TypeOfBike.Cargo, l_oBike.TypeOfBike);
@ -25,21 +25,21 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
[Test]
public void TestCompare()
{
var l_oBike1 = new Bike("43");
var l_oBike1 = new Bike("43", LockModel.ILockIt);
Assert.AreEqual("43", l_oBike1.Id);
Assert.AreEqual(null, l_oBike1.TypeOfBike);
Assert.AreEqual(null, l_oBike1.WheelType);
var l_oBike2 = new Bike("42", WheelType.Two, TypeOfBike.Allround);
var l_oBike2 = new Bike("42", LockModel.ILockIt, WheelType.Two, TypeOfBike.Allround);
Assert.IsFalse(l_oBike1 == l_oBike2);
l_oBike2 = new Bike("43", WheelType.Mono, TypeOfBike.Allround);
l_oBike2 = new Bike("43", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround);
Assert.IsFalse(l_oBike1 == l_oBike2);
l_oBike2 = new Bike("43", WheelType.Two, TypeOfBike.Cargo);
l_oBike2 = new Bike("43", LockModel.ILockIt, WheelType.Two, TypeOfBike.Cargo);
Assert.IsFalse(l_oBike1 == l_oBike2);
l_oBike2 = new Bike("43", null, null);
l_oBike2 = new Bike("43", LockModel.ILockIt, null, null);
Assert.IsTrue(l_oBike1 == l_oBike2);
}
}

View file

@ -1,8 +1,10 @@
using NUnit.Framework;
using Newtonsoft.Json;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using TINK.Model.Bike;
using TINK.Model.Bikes.Bike;
using TINK.Model.Connector;
using TINK.Model.State;
using TINK.Model.Station;
using BikeInfo = TINK.Model.Bike.BC.BikeInfo;
@ -17,6 +19,7 @@ namespace TestTINKLib
{
public BikeInfoMutable(
string id,
LockModel lockType,
bool isDemo = false,
IEnumerable<string> group = null,
WheelType? wheelType = null,
@ -27,7 +30,7 @@ namespace TestTINKLib
Uri operatorUri = null,
TariffDescription tariffDescription = null,
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null) : base(id, isDemo, group, wheelType, typeOfBike, description, stationId, stationName, operatorUri, tariffDescription, dateTimeProvider, stateInfo)
IStateInfo stateInfo = null) : base(id, lockType, isDemo, group, wheelType, typeOfBike, description, stationId, stationName, operatorUri, tariffDescription, dateTimeProvider, stateInfo)
{
}
}
@ -38,21 +41,21 @@ namespace TestTINKLib
{
var l_oColl = new BikeCollectionMutable();
l_oColl.Add(new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround));
l_oColl.Add(new BikeInfoMutable("57", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround));
Assert.Throws<Exception>(() => l_oColl.Add(new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo)));
Assert.Throws<Exception>(() => l_oColl.Add(new BikeInfoMutable("57", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo)));
}
[Test]
public void TestUpdate_Null()
{
var l_oBikeRequested = new BikeInfoMutable("20", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround);
var l_oBikeRequested = new BikeInfoMutable("20", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround);
l_oBikeRequested.State.Load(new StateInfo(() => DateTime.Now, DateTime.Now, "john@long", "1234"));
var l_oBikeColl = new BikeCollectionMutable
{
new BikeInfoMutable("63", false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround),
new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
new BikeInfoMutable("63", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround),
new BikeInfoMutable("57", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
l_oBikeRequested,
};
@ -74,13 +77,13 @@ namespace TestTINKLib
[Test]
public void TestUpdate()
{
var bikeRequested = new BikeInfoMutable("20", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround);
var bikeRequested = new BikeInfoMutable("20", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround);
bikeRequested.State.Load(new StateInfo(() => DateTime.Now, DateTime.Now, "john@long", "1234"));
var bikeColl = new BikeCollectionMutable
{
new BikeInfoMutable("63", false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround),
new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
new BikeInfoMutable("63", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround),
new BikeInfoMutable("57", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
bikeRequested,
};
@ -90,15 +93,30 @@ namespace TestTINKLib
Assert.AreEqual(InUseStateEnum.Reserved, bikeColl.GetById("20").State.Value); // Will be booked
Assert.Null(bikeColl.GetById("33")); //
var l_oBikeResponse = new List<BikeInfo>
var bikeResponse = new List<BikeInfo>
{
new BikeInfo("57" /* bike id*/, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "7" /*station id*/, null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
new BikeInfo("20", false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "7", null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
new BikeInfo("33", "7", null /*operator uri*/, null, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround),
new TINK.Model.Bike.CopriLock.BikeInfo(
"57" /* bike id*/,
DateTime.Now,
"john@long",
"7" /*station id*/,
new TINK.Model.Bikes.Bike.CopriLock.LockInfo(),
null),
new TINK.Model.Bike.CopriLock.BikeInfo(
"20",
DateTime.Now,
"john@long",
"7",
new TINK.Model.Bikes.Bike.CopriLock.LockInfo(),
null),
new TINK.Model.Bike.CopriLock.BikeInfo(
"33",
"7",
new TINK.Model.Bikes.Bike.CopriLock.LockInfo()),
};
bikeColl.Update(l_oBikeResponse, new List<IStation>());
bikeColl.Update(bikeResponse, new List<IStation>());
// Verify modified state
Assert.Null(bikeColl.GetById("63"), "Bike not contained in response must not exist.");
@ -120,7 +138,10 @@ namespace TestTINKLib
var l_oBikeResponse = new List<BikeInfo>
{
new BikeInfo("57" /* bike id*/, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "7" /*station id*/, null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
new TINK.Model.Bike.CopriLock.BikeInfo(
"57" /* bike id*/,
"7" /*station id*/,
new TINK.Model.Bikes.Bike.CopriLock.LockInfo()),
};
var stations = new List<IStation>
@ -142,7 +163,7 @@ namespace TestTINKLib
var bikeColl = new BikeCollectionMutable
{
new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
new BikeInfoMutable("57", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
};
// Verify initial state
@ -150,7 +171,7 @@ namespace TestTINKLib
var bikeResponse = new List<BikeInfo>
{
new BikeInfo("57" /* bike id*/, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "7" /*station id*/, null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
new BikeInfo("57" /* bike id*/, LockModel.ILockIt, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "7" /*station id*/, null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
};
var stations = new List<IStation>
@ -172,16 +193,75 @@ namespace TestTINKLib
var bikeColl = new BikeCollectionMutable();
var l_oBikeResponse = new List<BikeInfo>
var bikeResponse = new List<BikeInfo>
{
new BikeInfo("57" /* bike id*/, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "7" /*station id*/, null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
new TINK.Model.Bike.CopriLock.BikeInfo(
"57" /* bike id*/,
"7" /*station id*/,
new TINK.Model.Bikes.Bike.CopriLock.LockInfo(),
null /*operator uri*/),
};
bikeColl.Update(l_oBikeResponse, null);
bikeColl.Update(bikeResponse, null);
// Verify modified state
Assert.That(bikeColl.GetById("57").StationId, Is.EqualTo("7"));
Assert.That(bikeColl.GetById("57").StationName, Is.EqualTo(""));
}
[Test]
public void TestCreateBluetoothBike()
{
var bikeInfo = BikeInfoFactory.Create(JsonConvert.DeserializeObject<TINK.Repository.Response.BikeInfoAvailable>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : ""Ilockit""
}"));
Assert.That(
BikeCollectionMutable.BikeInfoMutableFactory.Create(bikeInfo, "Stat1").GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.BluetoothLock.BikeInfoMutable)));
}
[Test]
public void TestCreateCopriBike()
{
var bikeInfo = BikeInfoFactory.Create(JsonConvert.DeserializeObject<TINK.Repository.Response.BikeInfoAvailable>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : ""SIGO""
}"));
Assert.That(
BikeCollectionMutable.BikeInfoMutableFactory.Create(bikeInfo, "Stat1").GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.CopriLock.BikeInfoMutable)));
}
[Test]
public void TestCreateBCBike()
{
var bikeInfo = BikeInfoFactory.Create(JsonConvert.DeserializeObject<TINK.Repository.Response.BikeInfoAvailable>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : ""LOCK""
}"));
Assert.That(
BikeCollectionMutable.BikeInfoMutableFactory.Create(bikeInfo, "Stat1"),
Is.Null);
}
}
}

View file

@ -0,0 +1,27 @@
using NUnit.Framework;
using System;
using TINK.Model.Bike;
using TINK.Model.Bikes.Bike;
namespace TestShareeLib.Model.Bike
{
[TestFixture]
public class TestBikeExtension
{
[Test]
public void TestGetType()
{
Assert.That(LockModel.Sigo.GetLockType(), Is.EqualTo(LockType.Backend));
Assert.That(LockModel.ILockIt.GetLockType(), Is.EqualTo(LockType.Bluethooth));
Assert.That(
() => LockModel.BordComputer.GetLockType(),
Throws.InstanceOf<ArgumentException>());
}
[Test]
public void TestGetTypeCount()
{
Assert.That(Enum.GetValues(typeof(LockModel)).Length, Is.EqualTo(3), $"Impelemtation of {nameof(BikeExtension.GetLockType)} must be updated.");
}
}
}

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);
}

View file

@ -15,9 +15,9 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
var coll = new BikeCollection(
new Dictionary<string, TINK.Model.Bike.BC.BikeInfo>
{
{"3", new TINK.Model.Bike.BC.BikeInfo("7", "3" /* Stadion id */) },
{"7", new TINK.Model.Bike.BC.BikeInfo("8", "12" /* Stadion id */) },
{"12", new TINK.Model.Bike.BC.BikeInfo("33", "12" /* Stadion id */) }
{"3", new TINK.Model.Bike.BC.BikeInfo("7", LockModel.ILockIt, "3" /* Stadion id */) },
{"7", new TINK.Model.Bike.BC.BikeInfo("8", LockModel.ILockIt, "12" /* Stadion id */) },
{"12", new TINK.Model.Bike.BC.BikeInfo("33", LockModel.ILockIt, "12" /* Stadion id */) }
});
Assert.AreEqual(
@ -56,8 +56,8 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
var coll = new BikeCollection(
new Dictionary<string, TINK.Model.Bike.BC.BikeInfo>
{
{"7", new TINK.Model.Bike.BC.BikeInfo("8", "12" /* Stadion id */) },
{"12", new TINK.Model.Bike.BC.BikeInfo("33", "12" /* Stadion id */) }
{"7", new TINK.Model.Bike.BC.BikeInfo("8", LockModel.ILockIt, "12" /* Stadion id */) },
{"12", new TINK.Model.Bike.BC.BikeInfo("33", LockModel.ILockIt, "12" /* Stadion id */) }
});
Assert.AreEqual(
@ -73,9 +73,9 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
var coll = new BikeCollection(
new Dictionary<string, TINK.Model.Bike.BC.BikeInfo>
{
{"7", new TINK.Model.Bike.BC.BikeInfo("8", "12" /* Stadion id */) },
{"7", new TINK.Model.Bike.BC.BikeInfo("8", LockModel.ILockIt, "12" /* Stadion id */) },
{"11", new TINK.Model.Bike.BluetoothLock.BikeInfo("33", 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "12" /* Stadion id */) },
{"12", new TINK.Model.Bike.BC.BikeInfo("33", "12" /* Stadion id */) }
{"12", new TINK.Model.Bike.BC.BikeInfo("33", LockModel.ILockIt, "12" /* Stadion id */) }
});
Assert.AreEqual(

View file

@ -110,6 +110,22 @@ namespace TestShareeLib.Repository.Request
new RequestBuilderLoggedIn("123", "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"), double.NaN));
}
[Test]
public void TestBookAndStartOpening()
{
Assert.That(
new RequestBuilderLoggedIn("123", "456").BookAndStartOpening("42"),
Is.EqualTo("request=booking_request&bike=42&authcookie=456123&state=occupied&lock_state=unlocking"));
}
[Test]
public void TestReturnAndStartClosing()
{
Assert.That(
new RequestBuilderLoggedIn("123", "456").ReturnAndStartClosing("42", null),
Is.EqualTo("request=booking_update&bike=42&authcookie=456123&state=available&lock_state=locking"));
}
[Test]
public void TestDoSubmitMiniSurvey()
{

View file

@ -28,11 +28,11 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.0" />
<PackageReference Include="NSubstitute" Version="4.3.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.2" />
</ItemGroup>
<ItemGroup>

View file

@ -485,7 +485,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.Re
viewService.DisplayAlert(string.Empty, "Close lock and return bike Nr. 0?", "Yes", "No").Returns(Task.FromResult(true));
locks[0].CloseAsync()
.Returns<LockitLockingState?>(x => throw new CounldntCloseMovingException());
.Returns<LockitLockingState?>(x => throw new CouldntCloseMovingException());
//bike.LockInfo.State.Returns(LockingState.Open); // If locking fails bike remains open.
bike.State.Value.Returns(InUseStateEnum.Booked); // Booking state remains unchanged if closing fails.

View file

@ -97,6 +97,14 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel
var bikeFR9999 = bikesAtStation.FirstOrDefault(x => x.Id == "FR9999") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel; // Was id 1315
var bikeFR9998 = bikesAtStation.FirstOrDefault(x => x.Id == "FR9998") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel; // Was id 1543
Assert.That(
bikeFR9999,
Is.Not.Null);
Assert.That(
bikeFR9998,
Is.Not.Null);
Assert.AreEqual("Available.", bikeFR9999.StateText);
Assert.AreEqual("Available.", bikeFR9998.StateText);
Assert.AreEqual("NotLoggedIn", bikeFR9999.LockitButtonText);
@ -261,6 +269,22 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel
var bike1315 = bikesAtStation.FirstOrDefault(x => x.Id == "1315") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
var bike1543 = bikesAtStation.FirstOrDefault(x => x.Id == "1543") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
Assert.That(
bike1545,
Is.Not.Null);
Assert.That(
bike1537,
Is.Not.Null);
Assert.That(
bike1315,
Is.Not.Null);
Assert.That(
bike1543,
Is.Not.Null);
Assert.AreEqual($"Rented since {DateTime.Parse("2020-11-06 17:53:22.784681+01"):dd. MMMM HH:mm}.", bike1545.StateText);
Assert.AreEqual($"Rented since {DateTime.Parse("2020-10-12 08:38:12.374231+02"):dd. MMMM HH:mm}.", bike1537.StateText);
Assert.AreEqual("Available.", bike1315.StateText);
@ -371,6 +395,22 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel
var bike1315 = bikesAtStation.FirstOrDefault(x => x.Id == "1315") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
var bike1543 = bikesAtStation.FirstOrDefault(x => x.Id == "1543") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
Assert.That(
bike1545,
Is.Not.Null);
Assert.That(
bike1537,
Is.Not.Null);
Assert.That(
bike1315,
Is.Not.Null);
Assert.That(
bike1543,
Is.Not.Null);
Assert.AreEqual($"Rented since {DateTime.Parse("2020-11-06 17:53:22.784681+01"):dd. MMMM HH:mm}.", bike1545.StateText);
Assert.AreEqual($"Rented since {DateTime.Parse("2020-10-12 08:38:12.374231+02"):dd. MMMM HH:mm}.", bike1537.StateText);
Assert.AreEqual("Available.", bike1315.StateText);
@ -479,6 +519,22 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel
var bike1315 = bikesAtStation.FirstOrDefault(x => x.Id == "1315") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
var bike1543 = bikesAtStation.FirstOrDefault(x => x.Id == "1543") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
Assert.That(
bike1545,
Is.Not.Null);
Assert.That(
bike1537,
Is.Not.Null);
Assert.That(
bike1315,
Is.Not.Null);
Assert.That(
bike1543,
Is.Not.Null);
Assert.AreEqual($"Rented since {DateTime.Parse("2020-11-06 17:53:22.784681+01"):dd. MMMM HH:mm}.", bike1545.StateText);
Assert.AreEqual($"Rented since {DateTime.Parse("2020-10-12 08:38:12.374231+02"):dd. MMMM HH:mm}.", bike1537.StateText);
Assert.AreEqual("Available.", bike1315.StateText);
@ -583,6 +639,22 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel
var bike1315 = bikesAtStation.FirstOrDefault(x => x.Id == "1315") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
var bike1543 = bikesAtStation.FirstOrDefault(x => x.Id == "1543") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
Assert.That(
bike1545,
Is.Not.Null);
Assert.That(
bike1537,
Is.Not.Null);
Assert.That(
bike1315,
Is.Not.Null);
Assert.That(
bike1543,
Is.Not.Null);
Assert.AreEqual($"Rented since {DateTime.Parse("2020-11-06 17:53:22.784681+01"):dd. MMMM HH:mm}.", bike1545.StateText);
Assert.AreEqual($"Rented since {DateTime.Parse("2020-10-12 08:38:12.374231+02"):dd. MMMM HH:mm}.", bike1537.StateText);
Assert.AreEqual("Available.", bike1315.StateText);
@ -688,6 +760,22 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel
var bike1315 = bikesAtStation.FirstOrDefault(x => x.Id == "1315") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
var bike1543 = bikesAtStation.FirstOrDefault(x => x.Id == "1543") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
Assert.That(
bike1545,
Is.Not.Null);
Assert.That(
bike1537,
Is.Not.Null);
Assert.That(
bike1315,
Is.Not.Null);
Assert.That(
bike1543,
Is.Not.Null);
Assert.AreEqual($"Rented since {DateTime.Parse("2020-11-06 17:53:22.784681+01"):dd. MMMM HH:mm}.", bike1545.StateText);
Assert.AreEqual($"Rented since {DateTime.Parse("2020-10-12 08:38:12.374231+02"):dd. MMMM HH:mm}.", bike1537.StateText);
Assert.AreEqual("Available.", bike1315.StateText);