sharee.bike-App/TestLockItBLE/Services/BluetoothLock/BLE/TestLockItServiceBase.cs
2021-05-13 17:25:46 +02:00

69 lines
2.8 KiB
C#

using NSubstitute;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
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>());
}
}
}