mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-21 12:36:28 +02:00
Version 3.0.362
This commit is contained in:
parent
cba4da9357
commit
4ff3307997
128 changed files with 3954 additions and 3193 deletions
|
@ -1,10 +1,13 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using Plugin.BLE.Abstractions.Contracts;
|
||||
using TINK.Services.BluetoothLock;
|
||||
using TINK.Services.BluetoothLock.BLE;
|
||||
using TINK.Services.BluetoothLock.Exception;
|
||||
using TINK.Services.BluetoothLock.Tdo;
|
||||
|
||||
namespace TestLockItBLE.Services.BluetoothLock.BLE
|
||||
|
@ -64,5 +67,77 @@ namespace TestLockItBLE.Services.BluetoothLock.BLE
|
|||
|
||||
await disconnectedDevice.Received().ReconnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConnect_Connected_InvalidArgs()
|
||||
{
|
||||
var device = Substitute.For<IDevice>();
|
||||
var adapter = Substitute.For<IAdapter>();
|
||||
var cipher = Substitute.For<TINK.Model.Device.ICipher>();
|
||||
|
||||
var exception = Assert.Throws<AggregateException>(
|
||||
() => { var lockIt = LockItEventBased.Authenticate(device, null, adapter, cipher).Result; },
|
||||
"If connected no auth is requied.");
|
||||
|
||||
Assert.That(exception.InnerExceptions.Count > 0);
|
||||
Assert.That(exception.InnerExceptions[0], Is.InstanceOf<BluetoothDisconnectedException>());
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConnect_Connected()
|
||||
{
|
||||
var device = Substitute.For<IDevice>();
|
||||
var adapter = Substitute.For<IAdapter>();
|
||||
var cipher = Substitute.For<TINK.Model.Device.ICipher>();
|
||||
var auth = Substitute.For<ICharacteristic>();
|
||||
var lockControl = Substitute.For<IService>();
|
||||
|
||||
var authTdo = new LockInfoAuthTdo.Builder
|
||||
{
|
||||
Id = 12,
|
||||
K_seed = new byte[] { (byte)'i', (byte)'V', (byte)'F', (byte)'m', (byte)'u', (byte)'T', (byte)'n', (byte)'K', (byte)'q', (byte)'E', (byte)'Y', (byte)'h', (byte)'m', (byte)'T', (byte)'l', (byte)'e' },
|
||||
K_u = new byte[16]
|
||||
}.Build();
|
||||
|
||||
device.State.Returns(Plugin.BLE.Abstractions.DeviceState.Connected);
|
||||
device.GetServiceAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(Task.FromResult(lockControl));
|
||||
lockControl.GetCharacteristicAsync(Arg.Any<Guid>()).Returns(Task.FromResult(auth));
|
||||
auth.WriteAsync(Arg.Any<byte[]>()).Returns(Task.FromResult(true)); // Write COPRI seed to lock
|
||||
auth.ReadAsync(Arg.Any<CancellationToken>()).Returns(Task.FromResult(new byte[8])); // Read lock seed
|
||||
cipher.Decrypt(Arg.Any<byte[]>(), Arg.Any<byte[]>()).Returns(new byte[3]);
|
||||
cipher.Encrypt(Arg.Any<byte[]>(), Arg.Any<byte[]>()).Returns(new byte[16]);
|
||||
auth.WriteAsync(Arg.Any<byte[]>()).Returns(Task.FromResult(true)); // Write COPRI seed to lock
|
||||
|
||||
device.Name.Returns("Origin");
|
||||
|
||||
Assert.AreEqual(
|
||||
"Origin",
|
||||
LockItEventBased.Authenticate(device, authTdo, adapter, cipher).Result.Name,
|
||||
"If connected no auth is requied.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAuth()
|
||||
{
|
||||
var authTdo = new LockInfoAuthTdo.Builder
|
||||
{
|
||||
Id = 12,
|
||||
K_seed = new byte[] { (byte)'c', (byte)'b', (byte)'z', (byte)'b', (byte)'y', (byte)'I', (byte)'q', (byte)'j', (byte)'v', (byte)'L', (byte)'V', (byte)'I', (byte)'t', (byte)'C', (byte)'B', (byte)'I' },
|
||||
K_u = new byte[16]
|
||||
}.Build();
|
||||
|
||||
var device = Substitute.For<IDevice>();
|
||||
var adapter = Substitute.For<IAdapter>();
|
||||
var cipher = Substitute.For<TINK.Model.Device.ICipher>();
|
||||
|
||||
// Use factory to create LockIt-object.
|
||||
var exception = Assert.Throws<AggregateException>(
|
||||
() => { var lockIt = LockItEventBased.Authenticate(device, authTdo, adapter, cipher).Result; },
|
||||
"If connected no auth is requied.");
|
||||
|
||||
Assert.That(exception.InnerExceptions.Count > 0);
|
||||
Assert.That(exception.InnerExceptions[0], Is.InstanceOf<BluetoothDisconnectedException>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue