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