mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-16 23:26:26 +01:00
82 lines
2.2 KiB
C#
82 lines
2.2 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
|
|
using ShareeBike.Services.BluetoothLock;
|
|
using ShareeBike.Services.BluetoothLock.Tdo;
|
|
using static ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.Command.DisconnectCommand;
|
|
using ShareeBike.Services.BluetoothLock.Exception;
|
|
|
|
namespace SharedBusinessLogic.Tests.Model.Bikes.BikeInfoNS.BluetoothLock.Command
|
|
{
|
|
[TestFixture]
|
|
public class TestDisconnectCommand
|
|
{
|
|
/// <summary>
|
|
/// Use case: Disconnect lock
|
|
/// </summary>
|
|
[Test]
|
|
public async Task TestDisconnect()
|
|
{
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
var locks = Substitute.For<ILocksService>();
|
|
var listener = Substitute.For<IDisconnectCommandListener>();
|
|
|
|
bike.LockInfo.Id.Returns(0);
|
|
bike.LockInfo.State.Returns(LockingState.Closed);
|
|
|
|
await locks.DisconnectAsync(Arg.Any<int>(), Arg.Any<Guid>());
|
|
|
|
await InvokeAsync<TestDisconnectCommand>(
|
|
bike,
|
|
locks,
|
|
listener);
|
|
|
|
Assert.That(
|
|
bike.LockInfo.State,
|
|
Is.EqualTo(LockingState.UnknownDisconnected));
|
|
|
|
// Verify behavior
|
|
Received.InOrder(async () =>
|
|
{
|
|
listener.Received().ReportStep(Step.DisconnectLock);
|
|
await locks.DisconnectAsync(Arg.Any<int>(), Arg.Any<Guid>());
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Use case: Disconnect lock
|
|
/// </summary>
|
|
[Test]
|
|
public async Task TestDisconnectException()
|
|
{
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
var locks = Substitute.For<ILocksService>();
|
|
var listener = Substitute.For<IDisconnectCommandListener>();
|
|
|
|
bike.LockInfo.Id.Returns(0);
|
|
bike.LockInfo.State.Returns(LockingState.Closed);
|
|
|
|
locks.DisconnectAsync(Arg.Any<int>(), Arg.Any<Guid>())
|
|
.Returns<Task>(x => throw new Exception("exception"));
|
|
|
|
await InvokeAsync<TestDisconnectCommand>(
|
|
bike,
|
|
locks,
|
|
listener);
|
|
|
|
Assert.That(
|
|
bike.LockInfo.State,
|
|
Is.EqualTo(LockingState.Closed));
|
|
|
|
// Verify behavior
|
|
Received.InOrder(async () =>
|
|
{
|
|
listener.Received().ReportStep(Step.DisconnectLock);
|
|
await locks.DisconnectAsync(Arg.Any<int>(), Arg.Any<Guid>());
|
|
await listener.Received().ReportStateAsync(State.GeneralDisconnectError,"exception");
|
|
});
|
|
}
|
|
}
|
|
}
|