2023-04-05 15:02:10 +02:00
|
|
|
using System;
|
2021-05-13 20:09:46 +02:00
|
|
|
using System.Linq;
|
2022-08-30 15:42:25 +02:00
|
|
|
using NUnit.Framework;
|
|
|
|
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
|
2023-04-05 15:02:10 +02:00
|
|
|
using TINK.Services.Geolocation;
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
|
|
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
[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);
|
2021-05-13 20:09:46 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
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);
|
|
|
|
}
|
2021-05-13 20:09:46 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
[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);
|
2021-05-13 20:09:46 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
lockInfo.Guid = new Guid("00000000-0000-0000-0000-e57e6b9aee16");
|
|
|
|
Assert.AreEqual(new Guid("00000000-0000-0000-0000-e57e6b9aee16"), lockInfo.Guid);
|
|
|
|
}
|
2021-05-13 20:09:46 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
[Test]
|
|
|
|
public void TestLoad()
|
|
|
|
{
|
2021-05-13 20:09:46 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
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);
|
2021-05-13 20:09:46 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
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 });
|
2021-05-13 20:09:46 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
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);
|
|
|
|
}
|
2023-04-05 15:02:10 +02:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestLastLockingStateChange()
|
|
|
|
=> Assert.That(
|
|
|
|
new LockInfoMutable(1, new Guid(), null, null, null, LockingState.Open, () => new DateTime(2023, 03, 13)).LastLockingStateChange,
|
|
|
|
Is.Null);
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestLastLockingStateChangeCangeCtor()
|
|
|
|
{
|
|
|
|
var lockInfo = new LockInfoMutable(1, new Guid(), null, null, null, LockingState.Open, () => new DateTime(2023, 03, 13));
|
|
|
|
|
|
|
|
lockInfo.State = LockingState.Closed;
|
|
|
|
|
|
|
|
Assert.That(
|
|
|
|
lockInfo.LastLockingStateChange,
|
|
|
|
Is.EqualTo(new DateTime(2023, 03, 13)));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestLocationCtor()
|
|
|
|
=> Assert.That(
|
|
|
|
new LockInfoMutable(1, new Guid(), null, null, null, LockingState.Open, () => new DateTime(2023, 03, 13)).Location,
|
|
|
|
Is.Null);
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestLocation()
|
|
|
|
{
|
|
|
|
var lockInfo = new LockInfoMutable(1, new Guid(), null, null, null, LockingState.Open, () => new DateTime(2023, 03, 13));
|
|
|
|
|
|
|
|
lockInfo.Location = new Geolocation.Builder { Latitude = 47.99, Longitude = 7.78}.Build();
|
|
|
|
|
|
|
|
// Veryfy that location is kept because bike might be returned later.
|
|
|
|
Assert.That(
|
|
|
|
lockInfo.Location.Latitude,
|
|
|
|
Is.EqualTo(47.99).Within(0.001));
|
|
|
|
Assert.That(
|
|
|
|
lockInfo.Location.Longitude,
|
|
|
|
Is.EqualTo(7.78).Within(0.001));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestLocationStateChange()
|
|
|
|
{
|
|
|
|
var lockInfo = new LockInfoMutable(1, new Guid(), null, null, null, LockingState.Open, () => new DateTime(2023, 03, 13));
|
|
|
|
|
|
|
|
lockInfo.Location = new Geolocation.Builder { Latitude = 47.99, Longitude = 7.78 }.Build();
|
|
|
|
|
|
|
|
lockInfo.State = LockingState.Closed;
|
|
|
|
|
|
|
|
// Veryfy that location is kept because bike might be returned later.
|
|
|
|
Assert.That(
|
|
|
|
lockInfo.Location,
|
|
|
|
Is.Null);
|
|
|
|
}
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
2021-05-13 20:09:46 +02:00
|
|
|
}
|