mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-26 00:56:25 +01:00
753 lines
35 KiB
C#
753 lines
35 KiB
C#
|
using NSubstitute;
|
|||
|
using NUnit.Framework;
|
|||
|
using System;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using TINK.Model.Bike.BluetoothLock;
|
|||
|
using TINK.Model.Bikes.Bike.BluetoothLock;
|
|||
|
using TINK.Model.Connector;
|
|||
|
using TINK.Repository.Exception;
|
|||
|
using TINK.Services.BluetoothLock;
|
|||
|
using TINK.Services.BluetoothLock.Exception;
|
|||
|
using TINK.Services.BluetoothLock.Tdo;
|
|||
|
using TINK.Model.Services.Geolocation;
|
|||
|
using TINK.Model.State;
|
|||
|
using TINK.View;
|
|||
|
using TINK.ViewModel;
|
|||
|
using TINK.ViewModel.Bikes;
|
|||
|
using TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using TINK.Repository.Response;
|
|||
|
using TINK.Model.User;
|
|||
|
using TINK.Model.Device;
|
|||
|
|
|||
|
namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
|
{
|
|||
|
public class TestReservedDisconnected
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Test construction of object.
|
|||
|
/// </summary>
|
|||
|
[Test]
|
|||
|
public void Testctor()
|
|||
|
{
|
|||
|
var handler = new ReservedDisconnected(
|
|||
|
Substitute.For<IBikeInfoMutable>(),
|
|||
|
() => true, // isConnectedDelegate
|
|||
|
(isConnexted) => Substitute.For<IConnector>(),
|
|||
|
Substitute.For<IGeolocation>(),
|
|||
|
Substitute.For<ILocksService>(),
|
|||
|
() => Substitute.For<IPollingUpdateTaskManager>(),
|
|||
|
Substitute.For<ISmartDevice>(),
|
|||
|
Substitute.For<IViewService>(),
|
|||
|
Substitute.For<IBikesViewModel>(),
|
|||
|
Substitute.For<IUser>());
|
|||
|
|
|||
|
// Verify prerequisites.
|
|||
|
Assert.AreEqual("Cancel bike reservation", handler.ButtonText);
|
|||
|
Assert.IsTrue(handler.IsButtonVisible);
|
|||
|
Assert.AreEqual("Search lock", handler.LockitButtonText);
|
|||
|
Assert.IsTrue(handler.IsLockitButtonVisible);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Use case: Cancel reservation.
|
|||
|
/// Comment: User deceide to abort cancelling (user is ased whether to really cancel)
|
|||
|
/// Final state: Same as initial state.
|
|||
|
/// </summary>
|
|||
|
[Test]
|
|||
|
public void TestCancelReservationCancel()
|
|||
|
{
|
|||
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|||
|
var connector = Substitute.For<IConnector>();
|
|||
|
var command = Substitute.For<ICommand>();
|
|||
|
var geolocation = Substitute.For<IGeolocation>();
|
|||
|
var locks = Substitute.For<ILocksService>();
|
|||
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|||
|
var viewService = Substitute.For<IViewService>();
|
|||
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|||
|
var activeUser = Substitute.For<IUser>();
|
|||
|
|
|||
|
var handler = new ReservedDisconnected(
|
|||
|
bike,
|
|||
|
() => true, // isConnectedDelegate
|
|||
|
(isConnexted) => connector,
|
|||
|
geolocation,
|
|||
|
locks,
|
|||
|
() => pollingManager,
|
|||
|
Substitute.For<ISmartDevice>(),
|
|||
|
viewService,
|
|||
|
bikesViewModel,
|
|||
|
activeUser);
|
|||
|
|
|||
|
bike.Id.Returns("0");
|
|||
|
|
|||
|
viewService.DisplayAlert(string.Empty, string.Format("Cancel reservation for bike {0}?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(false));
|
|||
|
|
|||
|
var subsequent = handler.HandleRequestOption1().Result;
|
|||
|
|
|||
|
// Verify behaviour
|
|||
|
Received.InOrder(() =>
|
|||
|
{
|
|||
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|||
|
viewService.DisplayAlert(string.Empty, string.Format("Cancel reservation for bike {0}?", "Nr. 0"), "Yes", "No");
|
|||
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|||
|
});
|
|||
|
|
|||
|
// Verify state after action
|
|||
|
Assert.AreEqual("Cancel bike reservation", subsequent.ButtonText);
|
|||
|
Assert.IsTrue(subsequent.IsButtonVisible);
|
|||
|
Assert.AreEqual("Search lock", subsequent.LockitButtonText);
|
|||
|
Assert.IsTrue(subsequent.IsLockitButtonVisible);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Use case: Cancel reservation.
|
|||
|
/// Final state: Disposable.
|
|||
|
/// </summary>
|
|||
|
[Test]
|
|||
|
public void TestCancelReservation()
|
|||
|
{
|
|||
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|||
|
var connector = Substitute.For<IConnector>();
|
|||
|
var command = Substitute.For<ICommand>();
|
|||
|
var geolocation = Substitute.For<IGeolocation>();
|
|||
|
var locks = Substitute.For<ILocksService>();
|
|||
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|||
|
var viewService = Substitute.For<IViewService>();
|
|||
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|||
|
var activeUser = Substitute.For<IUser>();
|
|||
|
|
|||
|
var handler = new ReservedDisconnected(
|
|||
|
bike,
|
|||
|
() => true, // isConnectedDelegate
|
|||
|
(isConnexted) => connector,
|
|||
|
geolocation,
|
|||
|
locks,
|
|||
|
() => pollingManager,
|
|||
|
Substitute.For<ISmartDevice>(),
|
|||
|
viewService,
|
|||
|
bikesViewModel,
|
|||
|
activeUser);
|
|||
|
|
|||
|
bike.Id.Returns("0");
|
|||
|
|
|||
|
viewService.DisplayAlert(string.Empty, string.Format("Cancel reservation for bike {0}?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
|||
|
bike.State.Value.Returns(InUseStateEnum.Disposable); // Reqesthandler factory queries state to create appropriate request handler object.
|
|||
|
bike.LockInfo.State.Returns(LockingState.Disconnected); // Requsthandler factory queries lock state to create appropriate request handler object.
|
|||
|
|
|||
|
var subsequent = handler.HandleRequestOption1().Result;
|
|||
|
|
|||
|
// Verify behaviour
|
|||
|
Received.InOrder(() =>
|
|||
|
{
|
|||
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|||
|
bikesViewModel.ActionText = "One moment please...";
|
|||
|
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
|||
|
bikesViewModel.ActionText = "Canceling reservation...";
|
|||
|
connector.Command.DoCancelReservation(bike); // Booking must be performed
|
|||
|
bikesViewModel.ActionText = "Updating...";
|
|||
|
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|||
|
});
|
|||
|
|
|||
|
// Verify state after action
|
|||
|
Assert.AreEqual("Reserve bike", subsequent.ButtonText);
|
|||
|
Assert.IsTrue(subsequent.IsButtonVisible);
|
|||
|
Assert.AreEqual("DisposableDisconnected", subsequent.LockitButtonText);
|
|||
|
Assert.IsFalse(subsequent.IsLockitButtonVisible);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Use case: Cancel reservation.
|
|||
|
/// Comment: Exception is thrown.
|
|||
|
/// Final state: Same as initial state.
|
|||
|
/// </summary>
|
|||
|
[Test]
|
|||
|
public void TestCancelReservationDoCancelReservationInvalidAuthorizationResponseException()
|
|||
|
{
|
|||
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|||
|
var connector = Substitute.For<IConnector>();
|
|||
|
var command = Substitute.For<ICommand>();
|
|||
|
var geolocation = Substitute.For<IGeolocation>();
|
|||
|
var locks = Substitute.For<ILocksService>();
|
|||
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|||
|
var viewService = Substitute.For<IViewService>();
|
|||
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|||
|
var activeUser = Substitute.For<IUser>();
|
|||
|
|
|||
|
var handler = new ReservedDisconnected(
|
|||
|
bike,
|
|||
|
() => true, // isConnectedDelegate
|
|||
|
(isConnexted) => connector,
|
|||
|
geolocation,
|
|||
|
locks,
|
|||
|
() => pollingManager,
|
|||
|
Substitute.For<ISmartDevice>(),
|
|||
|
viewService,
|
|||
|
bikesViewModel,
|
|||
|
activeUser);
|
|||
|
|
|||
|
bike.Id.Returns("0");
|
|||
|
|
|||
|
viewService.DisplayAlert(string.Empty, string.Format("Cancel reservation for bike {0}?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
|||
|
|
|||
|
var l_oResponse = JsonConvert.DeserializeObject<AuthorizationResponse>(@"
|
|||
|
{
|
|||
|
""response"" : ""authorization"",
|
|||
|
""authcookie"" : ""4da3044c8657a04ba60e2eaa753bc51a"",
|
|||
|
""user_group"" : [ ""TINK"", ""Konrad"" ],
|
|||
|
""response_state"" : ""OK"",
|
|||
|
""apiserver"" : ""https://tinkwwp.copri-bike.de""
|
|||
|
}");
|
|||
|
|
|||
|
connector.Command.DoCancelReservation(bike).Returns(x => throw new InvalidAuthorizationResponseException("mustermann@server.de", l_oResponse));
|
|||
|
bike.State.Value.Returns(InUseStateEnum.Reserved); // Reqesthandler factory queries state to create appropriate request handler object.
|
|||
|
bike.LockInfo.State.Returns(LockingState.Disconnected); // Requsthandler factory queries lock state to create appropriate request handler object.
|
|||
|
|
|||
|
var subsequent = handler.HandleRequestOption1().Result;
|
|||
|
|
|||
|
// Verify behaviour
|
|||
|
Received.InOrder(() =>
|
|||
|
{
|
|||
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|||
|
bikesViewModel.ActionText = "One moment please...";
|
|||
|
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
|||
|
bikesViewModel.ActionText = "Canceling reservation...";
|
|||
|
connector.Command.DoCancelReservation(bike); // Booking must be performed
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
viewService.DisplayAlert("Fehler beim Aufheben der Reservierung!", "Kann Benutzer mustermann@server.de nicht anmelden. Mailadresse unbekannt oder Passwort ungültig.", "OK");
|
|||
|
bikesViewModel.ActionText = "Updating...";
|
|||
|
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|||
|
});
|
|||
|
|
|||
|
// Verify state after action
|
|||
|
Assert.AreEqual("Cancel bike reservation", subsequent.ButtonText);
|
|||
|
Assert.IsTrue(subsequent.IsButtonVisible);
|
|||
|
Assert.AreEqual("Search lock", subsequent.LockitButtonText);
|
|||
|
Assert.IsTrue(subsequent.IsLockitButtonVisible);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Use case: Cancel reservation.
|
|||
|
/// Comment: Canceling reservation fails.
|
|||
|
/// Final state: Same as initial state.
|
|||
|
/// </summary>
|
|||
|
[Test]
|
|||
|
public void TestCancelReservationDoCancelReservationWebConnectFailureException()
|
|||
|
{
|
|||
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|||
|
var connector = Substitute.For<IConnector>();
|
|||
|
var command = Substitute.For<ICommand>();
|
|||
|
var geolocation = Substitute.For<IGeolocation>();
|
|||
|
var locks = Substitute.For<ILocksService>();
|
|||
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|||
|
var viewService = Substitute.For<IViewService>();
|
|||
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|||
|
var activeUser = Substitute.For<IUser>();
|
|||
|
|
|||
|
var handler = new ReservedDisconnected(
|
|||
|
bike,
|
|||
|
() => true, // isConnectedDelegate
|
|||
|
(isConnexted) => connector,
|
|||
|
geolocation,
|
|||
|
locks,
|
|||
|
() => pollingManager,
|
|||
|
Substitute.For<ISmartDevice>(),
|
|||
|
viewService,
|
|||
|
bikesViewModel,
|
|||
|
activeUser);
|
|||
|
|
|||
|
bike.Id.Returns("0");
|
|||
|
|
|||
|
viewService.DisplayAlert(string.Empty, string.Format("Cancel reservation for bike {0}?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
|||
|
|
|||
|
connector.Command.DoCancelReservation(bike).Returns(x => throw new WebConnectFailureException("Context info", new Exception("chub")));
|
|||
|
bike.State.Value.Returns(InUseStateEnum.Reserved); // Reqesthandler factory queries state to create appropriate request handler object.
|
|||
|
bike.LockInfo.State.Returns(LockingState.Disconnected); // Requsthandler factory queries lock state to create appropriate request handler object.
|
|||
|
|
|||
|
var subsequent = handler.HandleRequestOption1().Result;
|
|||
|
|
|||
|
// Verify behaviour
|
|||
|
Received.InOrder(() =>
|
|||
|
{
|
|||
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|||
|
bikesViewModel.ActionText = "One moment please...";
|
|||
|
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
|||
|
bikesViewModel.ActionText = "Canceling reservation...";
|
|||
|
connector.Command.DoCancelReservation(bike); // Booking must be performed
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
viewService.DisplayAlert("Verbingungsfehler beim Aufheben der Reservierung!", "Context info\r\nIst WLAN verfügbar/ Mobilfunknetz vefügbar und mobile Daten aktiviert / ... ?", "OK");
|
|||
|
bikesViewModel.ActionText = "Updating...";
|
|||
|
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|||
|
});
|
|||
|
|
|||
|
// Verify state after action
|
|||
|
Assert.AreEqual("Cancel bike reservation", subsequent.ButtonText);
|
|||
|
Assert.IsTrue(subsequent.IsButtonVisible);
|
|||
|
Assert.AreEqual("Search lock", subsequent.LockitButtonText);
|
|||
|
Assert.IsTrue(subsequent.IsLockitButtonVisible);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Use case: Cancel reservation.
|
|||
|
/// Comment: Canceling reservation fails.
|
|||
|
/// Final state: Same as initial state.
|
|||
|
/// </summary>
|
|||
|
[Test]
|
|||
|
public void TestCancelReservationDoCancelReservationException()
|
|||
|
{
|
|||
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|||
|
var connector = Substitute.For<IConnector>();
|
|||
|
var command = Substitute.For<ICommand>();
|
|||
|
var geolocation = Substitute.For<IGeolocation>();
|
|||
|
var locks = Substitute.For<ILocksService>();
|
|||
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|||
|
var viewService = Substitute.For<IViewService>();
|
|||
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|||
|
var activeUser = Substitute.For<IUser>();
|
|||
|
|
|||
|
var handler = new ReservedDisconnected(
|
|||
|
bike,
|
|||
|
() => true, // isConnectedDelegate
|
|||
|
(isConnexted) => connector,
|
|||
|
geolocation,
|
|||
|
locks,
|
|||
|
() => pollingManager,
|
|||
|
Substitute.For<ISmartDevice>(),
|
|||
|
viewService,
|
|||
|
bikesViewModel,
|
|||
|
activeUser);
|
|||
|
|
|||
|
bike.Id.Returns("0");
|
|||
|
|
|||
|
viewService.DisplayAlert(string.Empty, string.Format("Cancel reservation for bike {0}?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
|||
|
|
|||
|
connector.Command.DoCancelReservation(bike).Returns(x => throw new Exception("Exception message."));
|
|||
|
bike.State.Value.Returns(InUseStateEnum.Reserved); // Reqesthandler factory queries state to create appropriate request handler object.
|
|||
|
bike.LockInfo.State.Returns(LockingState.Disconnected); // Requsthandler factory queries lock state to create appropriate request handler object.
|
|||
|
|
|||
|
var subsequent = handler.HandleRequestOption1().Result;
|
|||
|
|
|||
|
// Verify behaviour
|
|||
|
Received.InOrder(() =>
|
|||
|
{
|
|||
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|||
|
bikesViewModel.ActionText = "One moment please...";
|
|||
|
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
|||
|
bikesViewModel.ActionText = "Canceling reservation...";
|
|||
|
connector.Command.DoCancelReservation(bike); // Booking must be performed
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
viewService.DisplayAlert("Fehler beim Aufheben der Reservierung!", "Exception message.", "OK");
|
|||
|
bikesViewModel.ActionText = "Updating...";
|
|||
|
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|||
|
});
|
|||
|
|
|||
|
// Verify state after action
|
|||
|
Assert.AreEqual("Cancel bike reservation", subsequent.ButtonText);
|
|||
|
Assert.IsTrue(subsequent.IsButtonVisible);
|
|||
|
Assert.AreEqual("Search lock", subsequent.LockitButtonText);
|
|||
|
Assert.IsTrue(subsequent.IsLockitButtonVisible);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Use case: Search.
|
|||
|
/// Final state: reserved closed
|
|||
|
/// </summary>
|
|||
|
[Test]
|
|||
|
public void TestSearch()
|
|||
|
{
|
|||
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|||
|
var connector = Substitute.For<IConnector>();
|
|||
|
var command = Substitute.For<ICommand>();
|
|||
|
var geolocation = Substitute.For<IGeolocation>();
|
|||
|
var locks = Substitute.For<ILocksService>();
|
|||
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|||
|
var viewService = Substitute.For<IViewService>();
|
|||
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|||
|
var activeUser = Substitute.For<IUser>();
|
|||
|
var timeOuts = Substitute.For<ITimeOutProvider>();
|
|||
|
|
|||
|
var handler = new ReservedDisconnected(
|
|||
|
bike,
|
|||
|
() => true, // isConnectedDelegate
|
|||
|
(isConnexted) => connector,
|
|||
|
geolocation,
|
|||
|
locks,
|
|||
|
() => pollingManager,
|
|||
|
Substitute.For<ISmartDevice>(),
|
|||
|
viewService,
|
|||
|
bikesViewModel,
|
|||
|
activeUser);
|
|||
|
|
|||
|
bike.Id.Returns("0");
|
|||
|
|
|||
|
locks.ConnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>())
|
|||
|
.Returns(Task.FromResult(new LockInfoTdo.Builder { State = LockitLockingState.Closed }.Build()));
|
|||
|
|
|||
|
locks.TimeOut.Returns(timeOuts);
|
|||
|
|
|||
|
viewService.DisplayAlert(string.Empty, string.Format("Rent bike {0} and open lock?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
|||
|
|
|||
|
locks[0].OpenAsync()
|
|||
|
.Returns(Task.FromResult((LockitLockingState?)LockitLockingState.Open)); // Return lock state indicating success
|
|||
|
|
|||
|
bike.State.Value.Returns(InUseStateEnum.Booked); // Booking call leads to setting of state to booked.
|
|||
|
|
|||
|
var subsequent = handler.HandleRequestOption2().Result;
|
|||
|
|
|||
|
// Verify behaviour
|
|||
|
Received.InOrder(() =>
|
|||
|
{
|
|||
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|||
|
bikesViewModel.ActionText = "One moment please...";
|
|||
|
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
|||
|
bikesViewModel.ActionText = "Request server...";
|
|||
|
connector.Command.CalculateAuthKeys(bike);
|
|||
|
bikesViewModel.ActionText = "Searching lock...";
|
|||
|
locks.ConnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>());
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
bikesViewModel.ActionText = "Renting bike...";
|
|||
|
connector.Command.DoBook(bike); // Booking must be performed
|
|||
|
bikesViewModel.ActionText = "Opening lock...";
|
|||
|
locks.Received()[0].OpenAsync(); // Lock must be opened
|
|||
|
bikesViewModel.ActionText = "Reading charging level...";
|
|||
|
locks[0].GetBatteryPercentageAsync();
|
|||
|
bikesViewModel.ActionText = "Updating lock state...";
|
|||
|
connector.Command.UpdateLockingStateAsync(bike, null);
|
|||
|
bikesViewModel.ActionText = "Updating...";
|
|||
|
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|||
|
});
|
|||
|
|
|||
|
// Verify state after action
|
|||
|
Assert.AreEqual("Close lock & return bike", subsequent.ButtonText);
|
|||
|
Assert.IsTrue(subsequent.IsButtonVisible);
|
|||
|
Assert.AreEqual("Close lock", subsequent.LockitButtonText);
|
|||
|
Assert.IsTrue(subsequent.IsLockitButtonVisible);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Use case: Search.
|
|||
|
/// Final state: Same as initial state.
|
|||
|
/// </summary>
|
|||
|
[Test]
|
|||
|
public void TestSearchCalculateAuthKeysFailsWebConnectFailureException()
|
|||
|
{
|
|||
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|||
|
var connector = Substitute.For<IConnector>();
|
|||
|
var command = Substitute.For<ICommand>();
|
|||
|
var geolocation = Substitute.For<IGeolocation>();
|
|||
|
var locks = Substitute.For<ILocksService>();
|
|||
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|||
|
var viewService = Substitute.For<IViewService>();
|
|||
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|||
|
var activeUser = Substitute.For<IUser>();
|
|||
|
|
|||
|
var handler = new ReservedDisconnected(
|
|||
|
bike,
|
|||
|
() => true, // isConnectedDelegate
|
|||
|
(isConnexted) => connector,
|
|||
|
geolocation,
|
|||
|
locks,
|
|||
|
() => pollingManager,
|
|||
|
Substitute.For<ISmartDevice>(),
|
|||
|
viewService,
|
|||
|
bikesViewModel,
|
|||
|
activeUser);
|
|||
|
|
|||
|
connector.Command.CalculateAuthKeys(bike).Returns(x => throw new WebConnectFailureException("Context info.", new Exception("Tst")));
|
|||
|
|
|||
|
bike.State.Value.Returns(InUseStateEnum.Booked);
|
|||
|
bike.LockInfo.State.Returns(LockingState.Unknown);
|
|||
|
|
|||
|
var subsequent = handler.HandleRequestOption2().Result;
|
|||
|
|
|||
|
// Verify behaviour
|
|||
|
Received.InOrder(() =>
|
|||
|
{
|
|||
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|||
|
bikesViewModel.ActionText = "One moment please...";
|
|||
|
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
|||
|
bikesViewModel.ActionText = "Request server...";
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
viewService.DisplayAlert("Fehler bei Verbinden mit Schloss!", "Internet muss erreichbar sein um Verbindung mit Schloss für reserviertes Rad herzustellen.\r\nContext info.\r\nIst WLAN verfügbar/ Mobilfunknetz vefügbar und mobile Daten aktiviert / ... ?", "OK");
|
|||
|
bikesViewModel.ActionText = "Updating...";
|
|||
|
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|||
|
});
|
|||
|
|
|||
|
// Verify state after action
|
|||
|
Assert.AreEqual("Cancel bike reservation", handler.ButtonText);
|
|||
|
Assert.IsTrue(handler.IsButtonVisible);
|
|||
|
Assert.AreEqual("Search lock", handler.LockitButtonText);
|
|||
|
Assert.IsTrue(handler.IsLockitButtonVisible);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Use case: Search.
|
|||
|
/// Final state: Same as initial state.
|
|||
|
/// </summary>
|
|||
|
[Test]
|
|||
|
public void TestSearchCalculateAuthKeysFailsException()
|
|||
|
{
|
|||
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|||
|
var connector = Substitute.For<IConnector>();
|
|||
|
var command = Substitute.For<ICommand>();
|
|||
|
var geolocation = Substitute.For<IGeolocation>();
|
|||
|
var locks = Substitute.For<ILocksService>();
|
|||
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|||
|
var viewService = Substitute.For<IViewService>();
|
|||
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|||
|
var activeUser = Substitute.For<IUser>();
|
|||
|
|
|||
|
var handler = new ReservedDisconnected(
|
|||
|
bike,
|
|||
|
() => true, // isConnectedDelegate
|
|||
|
(isConnexted) => connector,
|
|||
|
geolocation,
|
|||
|
locks,
|
|||
|
() => pollingManager,
|
|||
|
Substitute.For<ISmartDevice>(),
|
|||
|
viewService,
|
|||
|
bikesViewModel,
|
|||
|
activeUser);
|
|||
|
|
|||
|
connector.Command.CalculateAuthKeys(bike).Returns(x => throw new Exception("Exception message."));
|
|||
|
|
|||
|
bike.State.Value.Returns(InUseStateEnum.Booked);
|
|||
|
bike.LockInfo.State.Returns(LockingState.Unknown);
|
|||
|
|
|||
|
var subsequent = handler.HandleRequestOption2().Result;
|
|||
|
|
|||
|
// Verify behaviour
|
|||
|
Received.InOrder(() =>
|
|||
|
{
|
|||
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|||
|
bikesViewModel.ActionText = "One moment please...";
|
|||
|
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
|||
|
bikesViewModel.ActionText = "Request server...";
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
viewService.DisplayAlert("Fehler bei Verbinden mit Schloss!", "Kommunikationsfehler bei Schlosssuche.\r\nException message.", "OK");
|
|||
|
bikesViewModel.ActionText = "Updating...";
|
|||
|
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|||
|
});
|
|||
|
|
|||
|
// Verify state after action
|
|||
|
Assert.AreEqual("Cancel bike reservation", handler.ButtonText);
|
|||
|
Assert.IsTrue(handler.IsButtonVisible);
|
|||
|
Assert.AreEqual("Search lock", handler.LockitButtonText);
|
|||
|
Assert.IsTrue(handler.IsLockitButtonVisible);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Use case: Search.
|
|||
|
/// Final state: Same as initial state.
|
|||
|
/// </summary>
|
|||
|
[Test]
|
|||
|
public void TestSearchConnectFailsOutOfReachException()
|
|||
|
{
|
|||
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|||
|
var connector = Substitute.For<IConnector>();
|
|||
|
var command = Substitute.For<ICommand>();
|
|||
|
var geolocation = Substitute.For<IGeolocation>();
|
|||
|
var locks = Substitute.For<ILocksService>();
|
|||
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|||
|
var viewService = Substitute.For<IViewService>();
|
|||
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|||
|
var activeUser = Substitute.For<IUser>();
|
|||
|
var timeOuts = Substitute.For<ITimeOutProvider>();
|
|||
|
|
|||
|
var handler = new ReservedDisconnected(
|
|||
|
bike,
|
|||
|
() => true, // isConnectedDelegate
|
|||
|
(isConnexted) => connector,
|
|||
|
geolocation,
|
|||
|
locks,
|
|||
|
() => pollingManager,
|
|||
|
Substitute.For<ISmartDevice>(),
|
|||
|
viewService,
|
|||
|
bikesViewModel,
|
|||
|
activeUser);
|
|||
|
|
|||
|
locks.ConnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>())
|
|||
|
.Returns<Task<LockInfoTdo>>(x => { throw new OutOfReachException(); });
|
|||
|
locks.TimeOut.Returns(timeOuts);
|
|||
|
|
|||
|
bike.State.Value.Returns(InUseStateEnum.Booked);
|
|||
|
|
|||
|
var subsequent = handler.HandleRequestOption2().Result;
|
|||
|
|
|||
|
// Verify behaviour
|
|||
|
Received.InOrder(() =>
|
|||
|
{
|
|||
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|||
|
bikesViewModel.ActionText = "One moment please...";
|
|||
|
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
|||
|
bikesViewModel.ActionText = "Request server...";
|
|||
|
connector.Command.CalculateAuthKeys(bike);
|
|||
|
bikesViewModel.ActionText = "Searching lock...";
|
|||
|
locks.ConnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>());
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
viewService.DisplayAlert(
|
|||
|
"Fehler bei Verbinden mit Schloss!",
|
|||
|
"Schloss kann erst gefunden werden, wenn reserviertes Rad in der Nähe ist.",
|
|||
|
"Wiederholen",
|
|||
|
"Abbrechen");
|
|||
|
bikesViewModel.ActionText = "Updating...";
|
|||
|
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|||
|
});
|
|||
|
|
|||
|
// Verify state after action
|
|||
|
Assert.AreEqual("Cancel bike reservation", handler.ButtonText);
|
|||
|
Assert.IsTrue(handler.IsButtonVisible);
|
|||
|
Assert.AreEqual("Search lock", handler.LockitButtonText);
|
|||
|
Assert.IsTrue(handler.IsLockitButtonVisible);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Use case: Search.
|
|||
|
/// Final state: Same as initial state.
|
|||
|
/// </summary>
|
|||
|
[Test]
|
|||
|
public void TestSearchConnectFailsException()
|
|||
|
{
|
|||
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|||
|
var connector = Substitute.For<IConnector>();
|
|||
|
var command = Substitute.For<ICommand>();
|
|||
|
var geolocation = Substitute.For<IGeolocation>();
|
|||
|
var locks = Substitute.For<ILocksService>();
|
|||
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|||
|
var viewService = Substitute.For<IViewService>();
|
|||
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|||
|
var activeUser = Substitute.For<IUser>();
|
|||
|
var timeOuts = Substitute.For<ITimeOutProvider>();
|
|||
|
|
|||
|
var handler = new ReservedDisconnected(
|
|||
|
bike,
|
|||
|
() => true, // isConnectedDelegate
|
|||
|
(isConnexted) => connector,
|
|||
|
geolocation,
|
|||
|
locks,
|
|||
|
() => pollingManager,
|
|||
|
Substitute.For<ISmartDevice>(),
|
|||
|
viewService,
|
|||
|
bikesViewModel,
|
|||
|
activeUser);
|
|||
|
|
|||
|
|
|||
|
locks.ConnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>())
|
|||
|
.Returns<Task<LockInfoTdo>>(x => throw new Exception("Execption message."));
|
|||
|
locks.TimeOut.Returns(timeOuts);
|
|||
|
|
|||
|
bike.State.Value.Returns(InUseStateEnum.Booked);
|
|||
|
|
|||
|
var subsequent = handler.HandleRequestOption2().Result;
|
|||
|
|
|||
|
// Verify behaviour
|
|||
|
Received.InOrder(() =>
|
|||
|
{
|
|||
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|||
|
bikesViewModel.ActionText = "One moment please...";
|
|||
|
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
|||
|
bikesViewModel.ActionText = "Request server...";
|
|||
|
connector.Command.CalculateAuthKeys(bike);
|
|||
|
bikesViewModel.ActionText = "Searching lock...";
|
|||
|
locks.ConnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>());
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
viewService.DisplayAdvancedAlert(
|
|||
|
"Fehler bei Verbinden mit Schloss!",
|
|||
|
"Lock of reserved bike can not be found.",
|
|||
|
"Execption message.",
|
|||
|
"Wiederholen",
|
|||
|
"Abbrechen");
|
|||
|
bikesViewModel.ActionText = "Updating...";
|
|||
|
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|||
|
});
|
|||
|
|
|||
|
// Verify state after action
|
|||
|
Assert.AreEqual("Cancel bike reservation", handler.ButtonText);
|
|||
|
Assert.IsTrue(handler.IsButtonVisible);
|
|||
|
Assert.AreEqual("Search lock", handler.LockitButtonText);
|
|||
|
Assert.IsTrue(handler.IsLockitButtonVisible);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Use case: Search.
|
|||
|
/// Final state: Same as initial state.
|
|||
|
/// </summary>
|
|||
|
[Test]
|
|||
|
public void TestSearchConnectNotOpen()
|
|||
|
{
|
|||
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|||
|
var connector = Substitute.For<IConnector>();
|
|||
|
var command = Substitute.For<ICommand>();
|
|||
|
var geolocation = Substitute.For<IGeolocation>();
|
|||
|
var locks = Substitute.For<ILocksService>();
|
|||
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|||
|
var viewService = Substitute.For<IViewService>();
|
|||
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|||
|
var activeUser = Substitute.For<IUser>();
|
|||
|
var timeOuts = Substitute.For<ITimeOutProvider>();
|
|||
|
|
|||
|
var handler = new ReservedDisconnected(
|
|||
|
bike,
|
|||
|
() => true, // isConnectedDelegate
|
|||
|
(isConnexted) => connector,
|
|||
|
geolocation,
|
|||
|
locks,
|
|||
|
() => pollingManager,
|
|||
|
Substitute.For<ISmartDevice>(),
|
|||
|
viewService,
|
|||
|
bikesViewModel,
|
|||
|
activeUser);
|
|||
|
|
|||
|
locks.ConnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>())
|
|||
|
.Returns(new LockInfoTdo.Builder { State = null }.Build());
|
|||
|
locks.TimeOut.Returns(timeOuts);
|
|||
|
|
|||
|
bike.State.Value.Returns(InUseStateEnum.Booked);
|
|||
|
|
|||
|
var subsequent = handler.HandleRequestOption2().Result;
|
|||
|
|
|||
|
// Verify behaviour
|
|||
|
Received.InOrder(() =>
|
|||
|
{
|
|||
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|||
|
bikesViewModel.ActionText = "One moment please...";
|
|||
|
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
|||
|
bikesViewModel.ActionText = "Request server...";
|
|||
|
connector.Command.CalculateAuthKeys(bike);
|
|||
|
bikesViewModel.ActionText = "Searching lock...";
|
|||
|
locks.ConnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>());
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
viewService.DisplayAlert("Fehler bei Verbinden mit Schloss!", "Schlossstatus des reservierten Rads konnte nicht ermittelt werden.", "OK");
|
|||
|
bikesViewModel.ActionText = "Updating...";
|
|||
|
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
|||
|
bikesViewModel.ActionText = "";
|
|||
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|||
|
});
|
|||
|
|
|||
|
// Verify state after action
|
|||
|
Assert.AreEqual("Cancel bike reservation", handler.ButtonText);
|
|||
|
Assert.IsTrue(handler.IsButtonVisible);
|
|||
|
Assert.AreEqual("Search lock", handler.LockitButtonText);
|
|||
|
Assert.IsTrue(handler.IsLockitButtonVisible);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|