mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-22 05:47:28 +02:00
Initial version
This commit is contained in:
parent
41b618cb27
commit
e4fb48f6ab
24 changed files with 4387 additions and 0 deletions
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue