Version 3.0.360

This commit is contained in:
Anja 2023-02-22 14:03:35 +01:00
parent 5c0b2e70c9
commit faf68061f4
160 changed files with 2114 additions and 1932 deletions

View file

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS;
using TINK.Model.Bikes.BikeInfoNS.BC;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
using TINK.Model.State;
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BC
{
[TestFixture]
public class TestBikeInfo
{
/// <summary>
/// Dummy subclass to provide assess to protected member for testing.
/// </summary>
private class TestBikeInfoSubClass : BikeInfo
{
public TestBikeInfoSubClass(
IStateInfo stateInfo,
TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike bike,
Drive drive,
bool? isDemo = DEFAULTVALUEISDEMO,
IEnumerable<string> group = null,
string stationId = null,
Uri operatorUri = null,
RentalDescription tariffDescription = null) : base(
stateInfo,
bike,
drive,
DataSource.Copri,
isDemo,
group,
stationId,
operatorUri,
tariffDescription)
{
}
}
[Test]
public void TestCtorCopyNull()
{
Assert.Throws<ArgumentNullException>(
() => new BikeInfo(null),
"Verify that no unspecific reference not set to... exception is thrown");
}
[Test]
public void TestCtorBikeNull()
{
Assert.That(
() => new TestBikeInfoSubClass(new StateInfo(), null, new Drive()),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorDriveNull()
{
Assert.That(
() => new TestBikeInfoSubClass(new StateInfo(), new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike(string.Empty, LockModel.ILockIt), null),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorCopy()
{
Assert.That(
() => new BikeInfo(null),
Throws.ArgumentNullException);
}
}
}

View file

@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using NSubstitute;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.State;
using IBikeInfo = TINK.Model.Bikes.BikeInfoNS.BC.IBikeInfo;
namespace TestTINKLib.Fixtures.ObjectTests.Bike
{
[TestFixture]
public class TestBikeInfoMutable
{
private class BikeInfoMutable : TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
{
public BikeInfoMutable(
string id,
LockModel lockModel,
bool isDemo = false,
IEnumerable<string> group = null,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null,
string stationId = null,
string stationName = null,
Uri operatorUri = null,
RentalDescription tariffDescription = null,
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null) : base(
new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike(id, lockModel, wheelType, typeOfBike, description),
new TINK.Model.Bikes.BikeInfoNS.DriveNS.Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
isDemo,
group,
stationId,
stationName,
operatorUri,
tariffDescription,
dateTimeProvider,
stateInfo)
{
}
}
[Test]
public void TestConstruct()
{
var l_oBikeInfo = new BikeInfoMutable("17", LockModel.ILockIt);
Assert.AreEqual("17", l_oBikeInfo.Id);
Assert.IsNull(l_oBikeInfo.StationId);
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeInfo.State.Value);
Assert.AreEqual(null, l_oBikeInfo.WheelType);
Assert.AreEqual(null, l_oBikeInfo.TypeOfBike);
l_oBikeInfo = new BikeInfoMutable("22", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo, "Test description", "23");
Assert.AreEqual("22", l_oBikeInfo.Id);
Assert.IsFalse(l_oBikeInfo.IsDemo);
Assert.AreEqual("23", l_oBikeInfo.StationId);
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeInfo.State.Value);
Assert.AreEqual(WheelType.Trike, l_oBikeInfo.WheelType);
Assert.AreEqual(TypeOfBike.Cargo, l_oBikeInfo.TypeOfBike);
}
[Test]
public void TestConstructCopyBooked()
{
// State Booked
var bikeInfoSource = Substitute.For<IBikeInfo>();
var stateSource = Substitute.For<IStateInfo>();
bikeInfoSource.Bike.Returns(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.BordComputer, WheelType.Trike, TypeOfBike.Cargo));
bikeInfoSource.StationId.Returns("23");
bikeInfoSource.State.Returns(stateSource);
stateSource.Value.Returns(InUseStateEnum.Booked);
stateSource.From.Returns(new System.DateTime(2018, 01, 03));
stateSource.MailAddress.Returns("a@b");
stateSource.Code.Returns("234");
var bikeInfoTarget = new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable(bikeInfoSource, "My Station Name");
Assert.AreEqual(InUseStateEnum.Booked, bikeInfoTarget.State.Value);
Assert.AreEqual("22", bikeInfoTarget.Id);
Assert.AreEqual("23", bikeInfoTarget.StationId);
Assert.AreEqual("My Station Name", bikeInfoTarget.StationName);
Assert.AreEqual(WheelType.Trike, bikeInfoTarget.WheelType);
Assert.AreEqual(TypeOfBike.Cargo, bikeInfoTarget.TypeOfBike);
Assert.AreEqual(InUseStateEnum.Booked, bikeInfoTarget.State.Value);
Assert.AreEqual(new System.DateTime(2018, 01, 03), bikeInfoTarget.State.From);
Assert.AreEqual("a@b", bikeInfoTarget.State.MailAddress);
}
[Test]
public void TestConstructCopyReserved()
{
// State Reserved
var bikeInfoSource = Substitute.For<IBikeInfo>();
var stateSource = Substitute.For<IStateInfo>();
bikeInfoSource.Bike.Returns(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.BordComputer, WheelType.Trike, TypeOfBike.Cargo));
bikeInfoSource.StationId.Returns("23");
bikeInfoSource.State.Returns(stateSource);
stateSource.Value.Returns(InUseStateEnum.Reserved);
stateSource.From.Returns(new System.DateTime(2018, 01, 03));
stateSource.MailAddress.Returns("a@b");
stateSource.Code.Returns("234");
var bikeInfoTarget = new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable(bikeInfoSource, "My Station Name");
Assert.AreEqual(InUseStateEnum.Reserved, bikeInfoTarget.State.Value);
Assert.AreEqual("22", bikeInfoTarget.Id);
Assert.AreEqual("23", bikeInfoTarget.StationId);
Assert.AreEqual(WheelType.Trike, bikeInfoTarget.WheelType);
Assert.AreEqual(TypeOfBike.Cargo, bikeInfoTarget.TypeOfBike);
Assert.AreEqual(InUseStateEnum.Reserved, bikeInfoTarget.State.Value);
Assert.AreEqual(new System.DateTime(2018, 01, 03), bikeInfoTarget.State.From);
Assert.AreEqual("a@b", bikeInfoTarget.State.MailAddress);
}
[Test]
public void TestConstructCopyAvailable()
{
// State Disposable
var bikeInfoSource = Substitute.For<IBikeInfo>();
var stateSource = Substitute.For<IStateInfo>();
bikeInfoSource.Bike.Returns(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.BordComputer, WheelType.Trike, TypeOfBike.Cargo));
bikeInfoSource.StationId.Returns("23");
bikeInfoSource.State.Returns(stateSource);
stateSource.Value.Returns(InUseStateEnum.Disposable);
var bikeInfoTarget = new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable(bikeInfoSource, "My Station Name");
Assert.AreEqual(InUseStateEnum.Disposable, bikeInfoTarget.State.Value);
Assert.AreEqual("22", bikeInfoTarget.Id);
Assert.AreEqual("23", bikeInfoTarget.StationId);
Assert.AreEqual(WheelType.Trike, bikeInfoTarget.WheelType);
Assert.AreEqual(TypeOfBike.Cargo, bikeInfoTarget.TypeOfBike);
Assert.AreEqual(InUseStateEnum.Disposable, bikeInfoTarget.State.Value);
Assert.IsNull(bikeInfoTarget.State.From);
}
[Test]
public void TestConstructBikeNull()
{
Assert.That(
() => new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable(null, "My Station Name"),
Throws.ArgumentNullException);
}
}
}

View file

@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.State;
namespace TestTINKLib
{
[TestFixture]
class TestBikeMutable
{
private class BikeInfoMutable : TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
{
public BikeInfoMutable(
string id,
LockModel lockType,
bool isDemo = false,
IEnumerable<string> group = null,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null,
string stationId = null,
string stationName = null,
Uri operatorUri = null,
RentalDescription tariffDescription = null,
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null) : base(
new Bike(id, lockType, wheelType, typeOfBike, description),
new TINK.Model.Bikes.BikeInfoNS.DriveNS.Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
isDemo,
group,
stationId,
stationName,
operatorUri,
tariffDescription,
dateTimeProvider,
stateInfo)
{
}
}
[Test]
public void TestConstruct()
{
var l_oBike = new BikeInfoMutable(
"42",
LockModel.ILockIt,
false,
new List<string> { "TINK" },
WheelType.Two,
TypeOfBike.Cargo);
Assert.AreEqual("42", l_oBike.Id);
Assert.IsFalse(l_oBike.IsDemo);
Assert.AreEqual(WheelType.Two, l_oBike.WheelType);
Assert.AreEqual(TypeOfBike.Cargo, l_oBike.TypeOfBike);
Assert.AreEqual(InUseStateEnum.Disposable, l_oBike.State.Value);
Assert.IsNull(l_oBike.StationId);
l_oBike = new BikeInfoMutable(
"17",
LockModel.ILockIt,
true,
new List<string> { "TINK" },
WheelType.Mono,
TypeOfBike.Allround,
"Test description",
"1");
Assert.AreEqual("17", l_oBike.Id);
Assert.IsTrue(l_oBike.IsDemo);
Assert.AreEqual(WheelType.Mono, l_oBike.WheelType);
Assert.AreEqual(TypeOfBike.Allround, l_oBike.TypeOfBike);
Assert.AreEqual(InUseStateEnum.Disposable, l_oBike.State.Value);
Assert.AreEqual("1", l_oBike.StationId);
}
[Test]
public void TestToString()
{
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", 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

@ -0,0 +1,59 @@
using Newtonsoft.Json;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using TINK.Model.Bike;
using TINK.Model.State;
using BikeInfoMutable = TINK.Model.Bike.BC.BikeInfoMutable;
namespace TestTINKLib
{
/// <summary>
/// Exclude from build beause serialization... see below.
/// </summary>
[TestFixture]
public class TestBikeSerializeJSON
{
[Test, Ignore("Disabled because serialization does no more work due to inheritance since commit ec14b93b.")]
public void TestConstruct_SerializeJSON_Disposable()
{
// Create object to test.
var l_oBikeSource = new BikeInfoMutable(3, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Cargo, p_oDateTimeProvider: () => new DateTime(1970, 1, 1));
// Verify prerequisites
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeSource.State.Value);
Assert.IsNull(l_oBikeSource.State.MailAddress);
Assert.IsNull(l_oBikeSource.State.Code);
Assert.IsNull(l_oBikeSource.State.From);
// Serialize object and verify.
var l_oDetected = JsonConvert.SerializeObject(l_oBikeSource, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
const string EXPECTED = @"
{
""Id"": 3,
""CurrentStation"": null,
""WheelType"": 1,
""TypeOfBike"": 1,
""State"": {
""StateInfoObject"": {
""$type"": ""TINK.Model.State.StateAvailableInfo, TINKLib""
}
}
}";
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED),
TestHelper.PrepareXmlForStringCompare(l_oDetected));
// Deserialize object.
var l_oBikeTarget = JsonConvert.DeserializeObject<BikeInfoMutable>(l_oDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
// Verify state.
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeTarget.State.Value);
Assert.IsNull(l_oBikeTarget.State.MailAddress);
Assert.IsNull(l_oBikeTarget.State.Code);
Assert.IsNull(l_oBikeTarget.State.From);
}
}
}

View file

@ -0,0 +1,108 @@
using System;
using NSubstitute.ExceptionExtensions;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
using TINK.Model.State;
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
{
[TestFixture]
public class TestBikeInfo
{
[Test]
public void TestCtorCopyNull()
{
Assert.Throws<ArgumentException>(
() => new BikeInfo(null, null),
"Verify that no unspecific reference not set to... exception is thrown");
Assert.Throws<ArgumentException>(
() => new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, "1"), null),
"Verify that no unspecific reference not set to... exception is thrown");
}
[Test]
public void TestCtorAvailable()
{
Assert.AreEqual("12", new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "13").Id);
Assert.AreEqual("13", new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "13").StationId);
Assert.AreEqual(InUseStateEnum.Disposable, new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "13").State.Value);
}
[Test]
public void TestCtorAvailableBikeNull()
{
Assert.That(
() => new BikeInfo(
null,
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
5200544,
new Guid("00000000-0000-0000-0000-000000000001"),
"13"),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorRequested()
{
Assert.AreEqual("12", new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null, null, dateTimeProvider: () => new DateTime(2019, 1, 1), false /*isDemo*/, null /*group*/).Id);
Assert.AreEqual(112, new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null, null, dateTimeProvider: () => new DateTime(2019, 1, 1), false /*isDemo*/, null /*group*/).LockInfo.Id);
Assert.AreEqual(InUseStateEnum.Reserved, new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null, null, dateTimeProvider: () => new DateTime(2019, 1, 1), false /*isDemo*/, null /*group*/).State.Value);
}
[Test]
public void TestCtorRequestedBikeNull()
{
Assert.That(
() => new BikeInfo(
null,
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
112,
new Guid(),
null,
null,
null,
new DateTime(2020, 1, 1),
"a@b",
"13",
null,
null,
dateTimeProvider: () => new DateTime(2019, 1, 1),
false /*isDemo*/,
null /*group*/),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorBooked()
{
Assert.AreEqual("12", new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null /*operator uri*/).Id);
Assert.AreEqual(112, new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null /*operator uri*/).LockInfo.Id);
Assert.AreEqual(InUseStateEnum.Booked, new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null /*operator uri*/).State.Value);
}
[Test]
public void TestCtorBookedNull()
{
Assert.That(
() => new BikeInfo(
null,
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
112,
new Guid(),
null,
null,
null,
new DateTime(2020, 1, 1),
"a@b",
"13",
null /*operator uri*/),
Throws.ArgumentNullException);
}
}
}

View file

@ -0,0 +1,57 @@
using System;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
namespace TestShareeLib.Model.Bike.BluetoothLock
{
[TestFixture]
public class TestBikeInfoMutalbe
{
[Test]
public void TestCtor()
{
Assert.That(
new BikeInfoMutable(
new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo(
new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike(
"MyBikeId",
TINK.Model.Bikes.BikeInfoNS.BikeNS.LockModel.ILockIt),
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
42,
new Guid(),
"17"),
"My Station Name").StationName,
Is.EqualTo("My Station Name"));
}
[Test]
public void TestToString()
{
Assert.That(
new BikeInfoMutable(
new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo(
new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike(
"MyBikeId",
TINK.Model.Bikes.BikeInfoNS.BikeNS.LockModel.ILockIt,
TINK.Model.Bikes.BikeInfoNS.BikeNS.WheelType.Trike,
TINK.Model.Bikes.BikeInfoNS.BikeNS.TypeOfBike.Cargo),
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
42,
new Guid(),
"17"),
"My Station Name").ToString(),
Is.EqualTo("Id=MyBikeId;type=Cargo;state=Disposable"));
}
[Test]
public void TestCtorBikeNull()
{
Assert.That(
() => new BikeInfoMutable(null, "My Station Name"),
Throws.ArgumentNullException);
}
}
}

View file

@ -0,0 +1,175 @@
using System;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
{
[TestFixture]
public class TestLockInfo
{
[Test]
public void TestCtor()
{
Assert.AreEqual(
LockingState.UnknownDisconnected,
new LockInfo.Builder { Id = 123 }.Build().State);
Assert.AreEqual(
123,
new LockInfo.Builder { Id = 123 }.Build().Id);
}
[Test]
public void TestEquals()
{
Assert.IsTrue(new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build() == new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build());
}
[Test]
public void TestEqualsFalse_Id()
{
Assert.IsFalse(new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build() == new LockInfo.Builder
{
Id = 3,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build());
}
[Test]
public void TestEqualsFalse_Guid()
{
Assert.IsFalse(new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build() == new LockInfo.Builder
{
Id = 2,
Guid = new Guid("1000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build());
}
[Test]
public void TestEqualsFalse_Seed()
{
Assert.IsFalse(new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build() == new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 5, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build());
}
[Test]
public void TestEqualsFalse_UserKey()
{
Assert.IsFalse(new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build() == new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 9, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build());
}
[Test]
public void TestEqualsFalse_AdminKey()
{
Assert.IsFalse(new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build() == new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 11, 1 },
State = LockingState.Closed
}.Build());
}
[Test]
public void TestEqualsFalse_LockingState()
{
Assert.IsFalse(new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build() == new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Open
}.Build());
}
}
}

View file

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
using TINK.Services.BluetoothLock.Tdo;
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
{
[TestFixture]
public class TestLockInfoHelper
{
[Test]
public void TestUpdateById_State()
{
var locksInfo = new List<LockInfo> {
new LockInfo.Builder { Id = 12, Seed = new byte[] { 3, 5 }, UserKey = new byte[] {2, 1 }, State = LockingState.UnknownFromHardwareError }.Build(),
new LockInfo.Builder { Id = 14, Seed = new byte[] { 3, 1 }, UserKey = new byte[] {2, 7 }, State = LockingState.Open }.Build(),
new LockInfo.Builder { Id = 3, Seed = new byte[] { 1, 5 }, UserKey = new byte[] {2, 9 }, State = LockingState.Closed }.Build(),
};
var locksInfoTdo = new List<LockInfoTdo> {
new LockInfoTdo.Builder { Id =14, State = LockitLockingState.Closed}.Build()
};
var resultList = locksInfo.UpdateById(locksInfoTdo);
var result = resultList.FirstOrDefault(x => x.Id == 14);
Assert.NotNull(result, "Target element was removed.");
Assert.AreEqual(LockingState.Closed, result.State);
}
[Test]
public void TestUpdateById_Guid()
{
var locksInfo = new List<LockInfo> {
new LockInfo.Builder { Id = 12, Seed = new byte[] { 3, 5 }, UserKey = new byte[] {2, 1 }, State = LockingState.UnknownFromHardwareError }.Build(),
new LockInfo.Builder { Id = 14, Seed = new byte[] { 3, 1 }, UserKey = new byte[] {2, 7 }, State = LockingState.Open }.Build(),
new LockInfo.Builder { Id = 3, Seed = new byte[] { 1, 5 }, UserKey = new byte[] {2, 9 }, State = LockingState.Closed }.Build(),
};
var locksInfoTdo = new List<LockInfoTdo> {
new LockInfoTdo.Builder { Id =14, Guid = new System.Guid("00000000-0000-0000-0000-e57e6b9aee16"), State = LockitLockingState.Open}.Build()
};
var resultList = locksInfo.UpdateById(locksInfoTdo);
var result = resultList.FirstOrDefault(x => x.Id == 14);
Assert.NotNull(result, "Target element was removed.");
Assert.AreEqual(new Guid("00000000-0000-0000-0000-e57e6b9aee16"), result.Guid);
}
}
}

View file

@ -0,0 +1,66 @@
using System;
using System.Linq;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
{
[TestFixture]
public class TestLockInfoMutable
{
[Test]
public void TestCtor()
{
var lockInfo = new LockInfoMutable(
1,
new Guid("00000000-0000-0000-0000-e57e6b9aee16"),
new byte[] { 1, 2, 3 }, // User key
new byte[] { 1, 23 }, // Admin key
new byte[] { 1, 12 }, // Seed
LockingState.Closed);
Assert.AreEqual(1, lockInfo.Id);
Assert.AreEqual(new Guid("00000000-0000-0000-0000-e57e6b9aee16"), lockInfo.Guid);
Assert.IsTrue((new byte[] { 1, 2, 3 }).SequenceEqual(lockInfo.UserKey));
Assert.IsTrue((new byte[] { 1, 23 }).SequenceEqual(lockInfo.AdminKey));
Assert.IsTrue((new byte[] { 1, 12 }).SequenceEqual(lockInfo.Seed));
Assert.AreEqual(LockingState.Closed, lockInfo.State);
}
[Test]
public void TestSetGuid()
{
var lockInfo = new LockInfoMutable(1, new Guid(), new byte[] { 1, 2, 3 }, new byte[] { 1, 23 }, new byte[] { 1, 12 }, LockingState.Closed);
lockInfo.Guid = new Guid("00000000-0000-0000-0000-e57e6b9aee16");
Assert.AreEqual(new Guid("00000000-0000-0000-0000-e57e6b9aee16"), lockInfo.Guid);
}
[Test]
public void TestLoad()
{
var lockInfo = new LockInfoMutable(
2,
new Guid(),
new byte[] { 5, 4 }, // User key
new byte[] { 14, 223 }, // Admin key
new byte[] { 3, 4, 5 }, // Seed
LockingState.Closed);
lockInfo.Load(
1,
new Guid("00000000-0000-0000-0000-e57e6b9aee16"),
new byte[] { 1, 12 }, // Seed
new byte[] { 1, 2, 3 }, // User key)
new byte[] { 1, 23 });
Assert.AreEqual(1, lockInfo.Id);
Assert.AreEqual(new Guid("00000000-0000-0000-0000-e57e6b9aee16"), lockInfo.Guid);
Assert.IsTrue((new byte[] { 1, 2, 3 }).SequenceEqual(lockInfo.UserKey));
Assert.IsTrue((new byte[] { 1, 23 }).SequenceEqual(lockInfo.AdminKey));
Assert.IsTrue((new byte[] { 1, 12 }).SequenceEqual(lockInfo.Seed));
Assert.AreEqual(LockingState.Closed, lockInfo.State);
}
}
}

View file

@ -0,0 +1,93 @@
using System;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS;
using TINK.Model.Bikes.BikeInfoNS.BC;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
namespace TestShareeLib.Model.Bike.CopriLock
{
[TestFixture]
public class TestBikeInfo
{
[Test]
public void TestCtorAvailable()
{
var bike = new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("bikeId", LockModel.Sigo),
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
"stationId",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo());
Assert.That(
bike.State.Value,
Is.EqualTo(TINK.Model.State.InUseStateEnum.Disposable));
}
[Test]
public void TestCtorAvailableBikeNull()
{
Assert.That(
() => new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
null,
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
"stationId",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo()),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorFeedbackRequired()
{
var bike = new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("bikeId", LockModel.Sigo),
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
"stationId",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo(),
true);
Assert.That(
bike.State.Value,
Is.EqualTo(TINK.Model.State.InUseStateEnum.FeedbackPending));
}
[Test]
public void TestCtorRequestedBikeNull()
{
Assert.That(
() => new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
null,
new Drive(),
DataSource.Copri,
DateTime.Now,
"a@b",
"stationId",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo(),
new Uri("https://sharee.bike"),
new RentalDescription(),
() => DateTime.Now),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorOccupiedBikeNull()
{
Assert.That(
() => new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
null,
new Drive(),
DataSource.Copri,
DateTime.Now,
"a@b",
"stationId",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo(),
new Uri("https://sharee.bike"),
new RentalDescription()),
Throws.ArgumentNullException);
}
}
}

View file

@ -0,0 +1,37 @@
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BC;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
namespace TestShareeLib.Model.Bike.CopriLock
{
[TestFixture]
public class TestBikeInfoMutable
{
[Test]
public void TestCtorBikeInfoNull()
{
Assert.That(
() => new BikeInfoMutable(null, "Station 32"),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorBikeInfo()
{
var bike = new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike(
"MyId",
TINK.Model.Bikes.BikeInfoNS.BikeNS.LockModel.Sigo);
var bikeInfo = new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
bike,
new Drive(new TINK.Model.Bikes.BikeInfoNS.DriveNS.EngineNS.Engine("BackendLock")),
DataSource.Copri,
"StationId",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo());
Assert.That(
new BikeInfoMutable(bikeInfo, "Station 32").Drive.Type,
Is.EqualTo(DriveType.Pedelec));
}
}
}

View file

@ -0,0 +1,49 @@
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
namespace TestShareeLib.Model.BikeInfo.DriveNS.BatteryNS
{
[TestFixture]
public class TestBattery
{
[Test]
public void TestSetCurrentChargePercent() => Assert.That(
new Battery.Builder { CurrentChargePercent = 20 }.Build().CurrentChargePercent,
Is.EqualTo(20.0));
[Test]
public void TestSetCurrentChargePercentOutOfRange() => Assert.That(
new Battery.Builder { CurrentChargePercent = 101 }.Build().CurrentChargePercent,
Is.NaN);
[Test]
public void TestSetCurrentChargeBars() => Assert.That(
new Battery.Builder { CurrentChargeBars = 21, MaxChargeBars = 22 }.Build().CurrentChargeBars,
Is.EqualTo(21));
[Test]
public void TestSetCurrentChargeBarsOutOfRange() => Assert.That(
new Battery.Builder { CurrentChargeBars = -1, MaxChargeBars = 22 }.Build().CurrentChargeBars,
Is.Null);
[Test]
public void TestSetMaxChargeBars() => Assert.That(
new Battery.Builder { MaxChargeBars = 23 }.Build().MaxChargeBars,
Is.EqualTo(23));
[Test]
public void TestSetMaxChargeBarsOutOfRange() => Assert.That(
new Battery.Builder { MaxChargeBars = -1 }.Build().MaxChargeBars,
Is.Null);
[Test]
public void TestSetCurrentChargeBarsNoMaxValueSet() => Assert.That(
new Battery.Builder { CurrentChargeBars = 21 }.Build().CurrentChargeBars,
Is.Null);
[Test]
public void TestSetCurrentChargeBars_CurrentValueTooLarge() => Assert.That(
new Battery.Builder { CurrentChargeBars = 25, MaxChargeBars = 22 }.Build().CurrentChargeBars,
Is.Null);
}
}

View file

@ -0,0 +1,49 @@
using NSubstitute;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS.EngineNS;
namespace TestShareeLib.Model.BikeInfo.DriveNS
{
[TestFixture]
public class TestDriveMutable
{
[Test]
public void TestCtorNoArgs()
{
var drive = new TINK.Model.Bikes.BikeInfoNS.DriveNS.Drive();
Assert.That(
drive.Type,
Is.EqualTo(DriveType.SoleHumanPowered));
Assert.That(
drive.Engine,
Is.Not.Null);
Assert.That(
drive.Battery,
Is.Not.Null);
}
[Test]
public void TestCtor()
{
var engine = Substitute.For<IEngine>();
var battery = Substitute.For<IBattery>();
engine.Manufacturer.Returns("Bosch");
battery.CurrentChargePercent.Returns(97);
var drive = new TINK.Model.Bikes.BikeInfoNS.DriveNS.Drive(engine, battery);
Assert.That(
drive.Engine.Manufacturer,
Is.EqualTo("Bosch"));
Assert.That(
drive.Battery.CurrentChargePercent,
Is.EqualTo(97));
}
}
}

View file

@ -0,0 +1,46 @@
using NUnit.Framework;
namespace TestTINKLib.Fixtures.ObjectTests.Bike
{
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
[TestFixture]
public class TestBike
{
[Test]
public void TestConstruct()
{
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", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Cargo);
Assert.AreEqual("43", l_oBike.Id);
Assert.AreEqual(TypeOfBike.Cargo, l_oBike.TypeOfBike);
Assert.AreEqual(WheelType.Mono, l_oBike.WheelType);
}
[Test]
public void TestCompare()
{
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", LockModel.ILockIt, WheelType.Two, TypeOfBike.Allround);
Assert.IsFalse(l_oBike1 == l_oBike2);
l_oBike2 = new Bike("43", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround);
Assert.IsFalse(l_oBike1 == l_oBike2);
l_oBike2 = new Bike("43", LockModel.ILockIt, WheelType.Two, TypeOfBike.Cargo);
Assert.IsFalse(l_oBike1 == l_oBike2);
l_oBike2 = new Bike("43", LockModel.ILockIt, null, null);
Assert.IsTrue(l_oBike1 == l_oBike2);
}
}
}

View file

@ -0,0 +1,21 @@
using NUnit.Framework;
using TINK.Model.Bikes;
namespace TestTINKLib
{
[TestFixture]
public class TestBikeCollection
{
/// <summary> Tests the member.</summary>
[Test]
public void TestConstruct()
{
var l_oColl = new BikeCollection();
Assert.AreEqual(0, l_oColl.Count);
Assert.IsNull(l_oColl.GetById("1"));
}
}
}

View file

@ -0,0 +1,293 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using NUnit.Framework;
using TINK.Model.Bikes;
using TINK.Model.Bikes.BikeInfoNS;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
using TINK.Model.Connector.Updater;
using TINK.Model.State;
using TINK.Model.Station;
using BikeInfo = TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo;
namespace TestTINKLib
{
[TestFixture]
public class TestBikeCollectionMutable
{
private class BikeInfoMutable : TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
{
public BikeInfoMutable(
string id,
LockModel lockType,
bool isDemo = false,
IEnumerable<string> group = null,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null,
string stationId = null,
string stationName = null,
Uri operatorUri = null,
RentalDescription tariffDescription = null,
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null) : base(
new Bike(id, lockType, wheelType, typeOfBike, description),
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
isDemo,
group,
stationId,
stationName,
operatorUri,
tariffDescription,
dateTimeProvider,
stateInfo)
{
}
}
/// <summary> Tests the member.</summary>
[Test]
public void TestAdd()
{
var l_oColl = new BikeCollectionMutable();
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", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo)));
}
[Test]
public void TestUpdate_Null()
{
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", 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,
};
// Verify initial state
Assert.NotNull(l_oBikeColl.GetById("63"));
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeColl.GetById("57").State.Value);
Assert.AreEqual(InUseStateEnum.Reserved, l_oBikeColl.GetById("20").State.Value);
Assert.Null(l_oBikeColl.GetById("33"));
l_oBikeColl.Update(null, null);
// Verify modified state
Assert.Null(l_oBikeColl.GetById("63"));
Assert.Null(l_oBikeColl.GetById("57"));
Assert.Null(l_oBikeColl.GetById("20"));
Assert.Null(l_oBikeColl.GetById("33"));
}
[Test]
public void TestUpdate()
{
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", 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,
};
// Verify initial state
Assert.NotNull(bikeColl.GetById("63")); // Will be removed
Assert.AreEqual(InUseStateEnum.Disposable, bikeColl.GetById("57").State.Value); // Will be requested
Assert.AreEqual(InUseStateEnum.Reserved, bikeColl.GetById("20").State.Value); // Will be booked
Assert.Null(bikeColl.GetById("33")); //
var bikeResponse = new List<BikeInfo>
{
new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new Bike("57", LockModel.ILockIt),
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
DateTime.Now,
"john@long",
"7" /*station id*/,
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo(),
null),
new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new Bike("20", LockModel.ILockIt),
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
DateTime.Now,
"john@long",
"7",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo(),
null),
new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new Bike("33", LockModel.Sigo),
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
"7",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo()),
};
bikeColl.Update(bikeResponse, new List<IStation>());
// Verify modified state
Assert.Null(bikeColl.GetById("63"), "Bike not contained in response must not exist.");
Assert.AreEqual(InUseStateEnum.Booked, bikeColl.GetById("57").State.Value);
Assert.AreEqual(InUseStateEnum.Booked, bikeColl.GetById("20").State.Value);
Assert.NotNull(bikeColl.GetById("33"));
}
/// <summary>
/// Bike for which station name is updated is not contained in bike collection when calling update.
/// </summary>
[Test]
public void TestUpdate_StationName_NewBike()
{
var bikeColl = new BikeCollectionMutable();
// Verify initial state
Assert.That(bikeColl.GetById("57"), Is.Null);
var l_oBikeResponse = new List<BikeInfo>
{
new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new Bike("57", LockModel.Sigo),
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
"7" /*station id*/,
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo()),
};
var stations = new List<IStation>
{
new Station("7", new List<string>(), null, "My facy station")
};
bikeColl.Update(l_oBikeResponse, stations);
// Verify modified state
Assert.That(bikeColl.GetById("57").StationId, Is.EqualTo("7"));
Assert.That(bikeColl.GetById("57").StationName, Is.EqualTo("My facy station"));
}
[Test]
public void TestUpdate_StationName_UpdateExistingBike()
{
var bikeColl = new BikeCollectionMutable
{
new BikeInfoMutable("57", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
};
// Verify initial state
Assert.That(bikeColl.GetById("57"), Is.Not.Null);
var bikeResponse = new List<BikeInfo>
{
new BikeInfo(new Bike("57" /* bike id*/, LockModel.ILockIt, WheelType.Trike, TypeOfBike.Allround, "Test description"), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, false, new List<string> {"TINK" }, "7" /*station id*/, null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
};
var stations = new List<IStation>
{
new Station("7", new List<string>(), null, "My facy station")
};
bikeColl.Update(bikeResponse, stations);
// Verify modified state
Assert.That(bikeColl.GetById("57").StationId, Is.Null, "Station id is only set when update creates BikeInfo object, not when updating object BikeInfo because station name does not change.");
Assert.That(bikeColl.GetById("57").StationName, Is.Null, "Station name is only set when update creates BikeInfo object, not when updating object BikeInfo because station name does not change.");
}
[Test]
public void TestUpdate_StationName_Nullstations()
{
var bikeColl = new BikeCollectionMutable();
var bikeResponse = new List<BikeInfo>
{
new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new Bike("57", LockModel.Sigo),
new Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
"7" /*station id*/,
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo(),
operatorUri: null /*operator uri*/),
};
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""
}"),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri);
Assert.That(
BikeCollectionMutable.BikeInfoMutableFactory.Create(bikeInfo, "Stat1").GetType(),
Is.EqualTo(typeof(TINK.Model.Bikes.BikeInfoNS.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""
}"),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri);
Assert.That(
BikeCollectionMutable.BikeInfoMutableFactory.Create(bikeInfo, "Stat1").GetType(),
Is.EqualTo(typeof(TINK.Model.Bikes.BikeInfoNS.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""
}"),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri);
Assert.That(
BikeCollectionMutable.BikeInfoMutableFactory.Create(bikeInfo, "Stat1"),
Is.Null);
}
}
}

View file

@ -0,0 +1,67 @@
using NUnit.Framework;
using TINK.Model.Bike;
using Newtonsoft.Json;
using TINK.Model.State;
using System.Collections.Generic;
using BikeInfoMutable = TINK.Model.Bike.BC.BikeInfoMutable;
namespace TestTINKLib
{
/// <summary>
/// Exclude from build beause serialization... see below.
/// </summary>
[TestFixture]
public class TestBikeCollectionSerializeJSON
{
[Test, Ignore("Disabled because serialization does no more work due to inheritance since commit ec14b93b.")]
public void Test_SerializeJSON()
{
var l_oCollSource = new BikeCollectionMutable
{
new BikeInfoMutable(57, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround)
};
// Verify prerequisites.
Assert.AreEqual(1, l_oCollSource.Count);
Assert.AreEqual(57, l_oCollSource[0].Id);
Assert.AreEqual(InUseStateEnum.Disposable, l_oCollSource[0].State.Value);
Assert.IsNull(l_oCollSource[0].State.MailAddress);
Assert.IsNull(l_oCollSource[0].State.Code);
Assert.IsNull(l_oCollSource[0].State.From);
// Serialize object and verify json
var l_oDetected = JsonConvert.SerializeObject(l_oCollSource, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
const string EXPECTED = @"
[
{
""Id"": 57,
""CurrentStation"": null,
""WheelType"": 1,
""TypeOfBike"": 0,
""State"": {
""StateInfoObject"": {
""$type"": ""TINK.Model.State.StateAvailableInfo, TINKLib""
}
}
}
]";
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED),
TestHelper.PrepareXmlForStringCompare(l_oDetected));
// Deserialize object.
var l_oBikeCollectionTarget = JsonConvert.DeserializeObject<BikeCollectionMutable>(l_oDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
// Verify state.
Assert.AreEqual(1, l_oBikeCollectionTarget.Count);
Assert.AreEqual(57, l_oBikeCollectionTarget[0].Id);
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeCollectionTarget[0].State.Value);
Assert.IsNull(l_oBikeCollectionTarget[0].State.MailAddress);
Assert.IsNull(l_oBikeCollectionTarget[0].State.Code);
Assert.IsNull(l_oBikeCollectionTarget[0].State.From);
}
}
}

View file

@ -0,0 +1,26 @@
using System;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
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.");
}
}
}