mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using TINK.Services.BluetoothLock;
|
|
using TINK.Services.BluetoothLock.BLE;
|
|
using TINK.Services.BluetoothLock.Tdo;
|
|
|
|
namespace TestLockItBLE.Services.BluetoothLock.BLE
|
|
{
|
|
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>();
|
|
|
|
await LockItServiceBase.CheckReconnect(
|
|
devices,
|
|
locksInfo,
|
|
TimeSpan.FromSeconds(0));
|
|
|
|
await disconnectedDevice.DidNotReceive().ReconnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>());
|
|
}
|
|
|
|
[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"));
|
|
|
|
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() };
|
|
|
|
await LockItServiceBase.CheckReconnect(
|
|
devices,
|
|
locksInfo,
|
|
TimeSpan.FromSeconds(0));
|
|
|
|
await disconnectedDevice.DidNotReceive().ReconnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>());
|
|
}
|
|
|
|
[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"));
|
|
|
|
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() };
|
|
|
|
await LockItServiceBase.CheckReconnect(
|
|
devices,
|
|
locksInfo,
|
|
TimeSpan.FromSeconds(0));
|
|
|
|
await disconnectedDevice.Received().ReconnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>());
|
|
}
|
|
}
|
|
}
|