mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-21 12:36:28 +02:00
Initial version
This commit is contained in:
parent
41b618cb27
commit
e4fb48f6ab
24 changed files with 4387 additions and 0 deletions
17
TestShareeLib/Model/Bike/BC/TestBikeInfo.cs
Normal file
17
TestShareeLib/Model/Bike/BC/TestBikeInfo.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using NUnit.Framework;
|
||||
using TINK.Model.Bike.BC;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BC
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestBikeInfo
|
||||
{
|
||||
[Test]
|
||||
public void TestCtorCopyNull()
|
||||
{
|
||||
Assert.Throws<System.ArgumentException>(
|
||||
() => new BikeInfo(null),
|
||||
"Verify that no unspecific reference not set to... exception is thrown");
|
||||
}
|
||||
}
|
||||
}
|
80
TestShareeLib/Model/Bike/BC/TestBikeMutable.cs
Normal file
80
TestShareeLib/Model/Bike/BC/TestBikeMutable.cs
Normal file
|
@ -0,0 +1,80 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.Bike;
|
||||
using TINK.Model.Bikes.Bike;
|
||||
using TINK.Model.State;
|
||||
|
||||
namespace TestTINKLib
|
||||
{
|
||||
[TestFixture]
|
||||
class TestBikeMutable
|
||||
{
|
||||
private class BikeInfoMutable : TINK.Model.Bike.BC.BikeInfoMutable
|
||||
{
|
||||
public BikeInfoMutable(
|
||||
int id,
|
||||
bool isDemo = false,
|
||||
IEnumerable<string> group = null,
|
||||
WheelType? wheelType = null,
|
||||
TypeOfBike? typeOfBike = null,
|
||||
string description = null,
|
||||
int? currentStationId = null,
|
||||
Uri operatorUri = null,
|
||||
TariffDescription tariffDescription = null,
|
||||
Func<DateTime> dateTimeProvider = null,
|
||||
IStateInfo stateInfo = null) : base(id, isDemo, group, wheelType, typeOfBike, description, currentStationId, operatorUri, tariffDescription, dateTimeProvider, stateInfo)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable(
|
||||
42,
|
||||
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.CurrentStation);
|
||||
|
||||
l_oBike = new BikeInfoMutable(
|
||||
17,
|
||||
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.CurrentStation);
|
||||
}
|
||||
|
||||
[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));
|
||||
|
||||
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));
|
||||
Assert.AreEqual(
|
||||
"Id=3, wheel(s)=Trike, type=Allround, demo=True, state=Disposable, location=Station 5.",
|
||||
l_oBike.ToString());
|
||||
}
|
||||
}
|
||||
}
|
59
TestShareeLib/Model/Bike/BC/TestBikeSerializeJSON.cs
Normal file
59
TestShareeLib/Model/Bike/BC/TestBikeSerializeJSON.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
47
TestShareeLib/Model/Bike/BluetoothLock/TestBikeInfo.cs
Normal file
47
TestShareeLib/Model/Bike/BluetoothLock/TestBikeInfo.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using TINK.Model.Bike.BluetoothLock;
|
||||
using TINK.Model.State;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestBikeInfo
|
||||
{
|
||||
[Test]
|
||||
public void TestCtorCopyNull()
|
||||
{
|
||||
Assert.Throws<System.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),
|
||||
"Verify that no unspecific reference not set to... exception is thrown");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCtorAvailable()
|
||||
{
|
||||
Assert.AreEqual (12,new BikeInfo(12, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), 13).Id);
|
||||
Assert.AreEqual(13, new BikeInfo(12, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), 13).CurrentStation);
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, new BikeInfo(12, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), 13).State.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCtorRequested()
|
||||
{
|
||||
Assert.AreEqual(12, new BikeInfo(12, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", 13, null, null, dateTimeProvider: () => new DateTime(2019, 1, 1)).Id);
|
||||
Assert.AreEqual(112, new BikeInfo(12, 112, new Guid(), null, null, null, new DateTime(2020,1,1), "a@b", 13, null, null, dateTimeProvider: () => new DateTime(2019, 1, 1)).LockInfo.Id);
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, new BikeInfo(12, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", 13, null, null, dateTimeProvider: () => new DateTime(2019, 1, 1)).State.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCtorBooked()
|
||||
{
|
||||
Assert.AreEqual(12, new BikeInfo(12, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", 13, null /*operator uri*/).Id);
|
||||
Assert.AreEqual(112, new BikeInfo(12, 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(12, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", 13, null /*operator uri*/).State.Value);
|
||||
}
|
||||
}
|
||||
}
|
172
TestShareeLib/Model/Bike/BluetoothLock/TestLockInfo.cs
Normal file
172
TestShareeLib/Model/Bike/BluetoothLock/TestLockInfo.cs
Normal file
|
@ -0,0 +1,172 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using TINK.Model.Bike.BluetoothLock;
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestLockInfo
|
||||
{
|
||||
[Test]
|
||||
public void TestCtor()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
LockingState.Disconnected,
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
53
TestShareeLib/Model/Bike/BluetoothLock/TestLockInfoHelper.cs
Normal file
53
TestShareeLib/Model/Bike/BluetoothLock/TestLockInfoHelper.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TINK.Model.Bike.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.Unknown }.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.Unknown }.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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using TINK.Model.Bike.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);
|
||||
}
|
||||
}
|
||||
}
|
46
TestShareeLib/Model/Bike/TestBike.cs
Normal file
46
TestShareeLib/Model/Bike/TestBike.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using NUnit.Framework;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Bike
|
||||
{
|
||||
using TINK.Model.Bike;
|
||||
|
||||
[TestFixture]
|
||||
public class TestBike
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var l_oBike = new Bike(43);
|
||||
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);
|
||||
|
||||
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);
|
||||
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);
|
||||
Assert.IsFalse(l_oBike1 == l_oBike2);
|
||||
|
||||
l_oBike2 = new Bike(43, WheelType.Mono, TypeOfBike.Allround);
|
||||
Assert.IsFalse(l_oBike1 == l_oBike2);
|
||||
|
||||
l_oBike2 = new Bike(43, WheelType.Two, TypeOfBike.Cargo);
|
||||
Assert.IsFalse(l_oBike1 == l_oBike2);
|
||||
|
||||
l_oBike2 = new Bike(43, null, null);
|
||||
Assert.IsTrue(l_oBike1 == l_oBike2);
|
||||
}
|
||||
}
|
||||
}
|
22
TestShareeLib/Model/Bike/TestBikeCollection.cs
Normal file
22
TestShareeLib/Model/Bike/TestBikeCollection.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using TINK.Model.Bike;
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
109
TestShareeLib/Model/Bike/TestBikeCollectionMutable.cs
Normal file
109
TestShareeLib/Model/Bike/TestBikeCollectionMutable.cs
Normal file
|
@ -0,0 +1,109 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TINK.Model.Bike;
|
||||
using TINK.Model.Bikes.Bike;
|
||||
using TINK.Model.State;
|
||||
|
||||
using BikeInfo = TINK.Model.Bike.BC.BikeInfo;
|
||||
using BikeInfoMutable = TINK.Model.Bike.BC.BikeInfoMutable;
|
||||
|
||||
namespace TestTINKLib
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestBikeCollectionMutable
|
||||
{
|
||||
private class BikeInfoMutable : TINK.Model.Bike.BC.BikeInfoMutable
|
||||
{
|
||||
public BikeInfoMutable(
|
||||
int id,
|
||||
bool isDemo = false,
|
||||
IEnumerable<string> group = null,
|
||||
WheelType? wheelType = null,
|
||||
TypeOfBike? typeOfBike = null,
|
||||
string description = null,
|
||||
int? currentStationId = null,
|
||||
Uri operatorUri = null,
|
||||
TariffDescription tariffDescription = null,
|
||||
Func<DateTime> dateTimeProvider = null,
|
||||
IStateInfo stateInfo = null) : base(id, isDemo, group, wheelType, typeOfBike, description, currentStationId, operatorUri, tariffDescription, dateTimeProvider, stateInfo)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Tests the member.</summary>
|
||||
[Test]
|
||||
public void TestAdd()
|
||||
{
|
||||
var l_oColl = new BikeCollectionMutable();
|
||||
|
||||
l_oColl.Add(new BikeInfoMutable(57, 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)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUpdate_Null()
|
||||
{
|
||||
var l_oBikeRequested = new BikeInfoMutable(20, 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),
|
||||
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);
|
||||
|
||||
// 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 l_oBikeRequested = new BikeInfoMutable(20, 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),
|
||||
l_oBikeRequested,
|
||||
};
|
||||
|
||||
// Verify initial state
|
||||
Assert.NotNull(l_oBikeColl.GetById(63)); // Will be removed
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeColl.GetById(57).State.Value); // Will be requested
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oBikeColl.GetById(20).State.Value); // Will be booked
|
||||
Assert.Null(l_oBikeColl.GetById(33)); //
|
||||
|
||||
var l_oBikeResponse = new List<BikeInfo>
|
||||
{
|
||||
new BikeInfo(57, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", 7, 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),
|
||||
};
|
||||
|
||||
l_oBikeColl.Update(l_oBikeResponse);
|
||||
|
||||
// Verify modified state
|
||||
Assert.Null(l_oBikeColl.GetById(63));
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oBikeColl.GetById(57).State.Value);
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oBikeColl.GetById(20).State.Value);
|
||||
Assert.NotNull(l_oBikeColl.GetById(33));
|
||||
}
|
||||
}
|
||||
}
|
67
TestShareeLib/Model/Bike/TestBikeCollectionSerializeJSON.cs
Normal file
67
TestShareeLib/Model/Bike/TestBikeCollectionSerializeJSON.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using TINK.Model.State;
|
||||
|
||||
|
||||
namespace TestTINKLib.Fixtures.Bike
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestStateBookedInfoSerializeJSON
|
||||
{
|
||||
[Test]
|
||||
public void TestSerializeJSON()
|
||||
{
|
||||
// Create object to test.
|
||||
var l_oInfoSource = new StateOccupiedInfo(
|
||||
new DateTime(2017, 09, 20, 23, 05, 0),
|
||||
"Heinz@mueller",
|
||||
"17 xxb");
|
||||
|
||||
// Serialize object and verify.
|
||||
var l_oDetected = JsonConvert.SerializeObject(l_oInfoSource);
|
||||
const string EXPECTED = @"
|
||||
{
|
||||
""From"":""2017 - 09 - 20T23: 05:00"",
|
||||
""MailAddress"":""Heinz@mueller"",
|
||||
""Code"":""17 xxb""
|
||||
}";
|
||||
Assert.AreEqual(
|
||||
TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty)),
|
||||
TestHelper.PrepareXmlForStringCompare(l_oDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)));
|
||||
|
||||
// Deserialize object and verify.
|
||||
var l_oInfoTarget = JsonConvert.DeserializeObject<StateOccupiedInfo>(l_oDetected);
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oInfoTarget.Value);
|
||||
Assert.AreEqual("Heinz@mueller", l_oInfoTarget.MailAddress);
|
||||
Assert.AreEqual("17 xxb", l_oInfoTarget.Code);
|
||||
Assert.AreEqual(new DateTime(2017, 9, 20, 23, 5, 0), l_oInfoTarget.From);
|
||||
}
|
||||
}
|
||||
}
|
86
TestShareeLib/Model/TestBikeCollectionFilter.cs
Normal file
86
TestShareeLib/Model/TestBikeCollectionFilter.cs
Normal file
|
@ -0,0 +1,86 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TINK.Model;
|
||||
using TINK.Model.Bike;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Bike
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestBikeCollectionFilter
|
||||
{
|
||||
[Test]
|
||||
public void TestGetAtStation()
|
||||
{
|
||||
var coll = new BikeCollection(
|
||||
new Dictionary<int, 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 */) }
|
||||
});
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
BikeCollectionFilter.GetAtStation(null, 12).Count);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
coll.GetAtStation(null).Count);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
coll.GetAtStation(22).Count);
|
||||
|
||||
Assert.AreEqual(
|
||||
1,
|
||||
coll.GetAtStation(3).Count);
|
||||
|
||||
Assert.AreEqual(
|
||||
2,
|
||||
coll.GetAtStation(12).Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetLockIt_Null()
|
||||
{
|
||||
Assert.That(
|
||||
BikeCollectionFilter.GetLockIt(null).Count,
|
||||
Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetLockIt_NoLockIt()
|
||||
{
|
||||
// Holds no LockIt bikes
|
||||
var coll = new BikeCollection(
|
||||
new Dictionary<int, 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 */) }
|
||||
});
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
coll.GetLockIt().Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetLockIt()
|
||||
{
|
||||
|
||||
// Holds no LockIt bike with matching station number.
|
||||
var coll = new BikeCollection(
|
||||
new Dictionary<int, TINK.Model.Bike.BC.BikeInfo>
|
||||
{
|
||||
{7, new TINK.Model.Bike.BC.BikeInfo(8, 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 */) }
|
||||
});
|
||||
|
||||
Assert.AreEqual(
|
||||
1,
|
||||
coll.GetLockIt().Count);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue