sharee.bike-App/TestLockItBLE/Services/BluetoothLock/BLE/TestLockItServiceBase.cs

69 lines
2.4 KiB
C#
Raw Normal View History

2022-08-30 15:42:25 +02:00
using System;
2021-05-13 17:25:46 +02:00
using System.Collections.Generic;
using System.Threading.Tasks;
2022-08-30 15:42:25 +02:00
using NSubstitute;
using NUnit.Framework;
2021-05-13 17:25:46 +02:00
using TINK.Services.BluetoothLock;
using TINK.Services.BluetoothLock.BLE;
using TINK.Services.BluetoothLock.Tdo;
namespace TestLockItBLE.Services.BluetoothLock.BLE
{
2022-09-06 16:08:19 +02:00
public class TestLockItServiceBase
{
[Test]
public async Task TestCheckReconnect_EmptyList()
{
var disconnectedDevice = Substitute.For<ILockService>();
disconnectedDevice.GetDeviceState().Returns(DeviceState.Disconnected);
var devices = new List<ILockService> { disconnectedDevice };
var locksInfo = new List<LockInfoAuthTdo>();
2021-05-13 17:25:46 +02:00
2022-09-06 16:08:19 +02:00
await LockItServiceBase.CheckReconnect(
devices,
locksInfo,
TimeSpan.FromSeconds(0));
2021-05-13 17:25:46 +02:00
2022-09-06 16:08:19 +02:00
await disconnectedDevice.DidNotReceive().ReconnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>());
}
2021-05-13 17:25:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public async Task TestCheckReconnect_NoMatchingIdEntry()
{
var disconnectedDevice = Substitute.For<ILockService>();
disconnectedDevice.GetDeviceState().Returns(DeviceState.Disconnected);
disconnectedDevice.Name.Returns("ISHAREIT+334");
disconnectedDevice.Guid.Returns(new Guid("00000000-0000-0000-0000-000000000001"));
2021-05-13 17:25:46 +02:00
2022-09-06 16:08:19 +02:00
var devices = new List<ILockService> { disconnectedDevice };
var locksInfo = new List<LockInfoAuthTdo> { new LockInfoAuthTdo.Builder { Id = 992, Guid = new Guid("00000000-0000-0000-0000-000000000002"), K_seed = new byte[] { 2 }, K_u = new byte[] { 3 } }.Build() };
2021-05-13 17:25:46 +02:00
2022-09-06 16:08:19 +02:00
await LockItServiceBase.CheckReconnect(
devices,
locksInfo,
TimeSpan.FromSeconds(0));
2021-05-13 17:25:46 +02:00
2022-09-06 16:08:19 +02:00
await disconnectedDevice.DidNotReceive().ReconnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>());
}
2021-05-13 17:25:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public async Task TestCheckReconnect()
{
var disconnectedDevice = Substitute.For<ILockService>();
disconnectedDevice.GetDeviceState().Returns(DeviceState.Disconnected);
disconnectedDevice.Name.Returns("ISHAREIT+992");
disconnectedDevice.Guid.Returns(new Guid("00000000-0000-0000-0000-000000000001"));
2021-05-13 17:25:46 +02:00
2022-09-06 16:08:19 +02:00
var devices = new List<ILockService> { disconnectedDevice };
var locksInfo = new List<LockInfoAuthTdo> { new LockInfoAuthTdo.Builder { Id = 992, Guid = new Guid("00000000-0000-0000-0000-000000000002"), K_seed = new byte[] { 2 }, K_u = new byte[] { 3 } }.Build() };
2021-05-13 17:25:46 +02:00
2022-09-06 16:08:19 +02:00
await LockItServiceBase.CheckReconnect(
devices,
locksInfo,
TimeSpan.FromSeconds(0));
2021-05-13 17:25:46 +02:00
2022-09-06 16:08:19 +02:00
await disconnectedDevice.Received().ReconnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>());
}
}
2021-05-13 17:25:46 +02:00
}