2022-10-26 20:53:18 +02:00
|
|
|
using System;
|
2022-08-30 15:42:25 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using NSubstitute;
|
|
|
|
using NUnit.Framework;
|
2024-04-09 12:53:23 +02:00
|
|
|
using ShareeBike.Model.Bikes.BikeInfoNS.CopriLock;
|
|
|
|
using ShareeBike.Model.Connector;
|
|
|
|
using ShareeBike.Model.Device;
|
|
|
|
using ShareeBike.Model.User;
|
|
|
|
using ShareeBike.Repository.Exception;
|
|
|
|
using ShareeBike.Repository.Response;
|
|
|
|
using ShareeBike.View;
|
|
|
|
using ShareeBike.ViewModel;
|
|
|
|
using ShareeBike.ViewModel.Bikes;
|
|
|
|
using ShareeBike.ViewModel.Bikes.Bike.CopriLock.RequestHandler;
|
|
|
|
|
|
|
|
namespace SharedBusinessLogic.Tests.ViewModel.Bikes.Bike.CopriLock.RequestHandler
|
2022-08-30 15:42:25 +02:00
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
[TestFixture]
|
|
|
|
public class TestReservedClosed
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Use case: Cancel reservation.
|
|
|
|
/// 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 pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|
|
|
var activeUser = Substitute.For<IUser>();
|
|
|
|
|
|
|
|
var handler = new ReservedClosed(
|
|
|
|
bike,
|
|
|
|
() => true, // isConnectedDelegate
|
2024-04-09 12:53:23 +02:00
|
|
|
(isConnected) => connector,
|
2022-09-06 16:08:19 +02:00
|
|
|
() => pollingManager,
|
|
|
|
Substitute.For<ISmartDevice>(),
|
|
|
|
viewService,
|
|
|
|
bikesViewModel,
|
|
|
|
activeUser);
|
|
|
|
|
|
|
|
bike.Id.Returns("0");
|
|
|
|
|
|
|
|
viewService.DisplayAlert(
|
|
|
|
string.Empty,
|
|
|
|
"Cancel reservation for bike Nr. 0?",
|
|
|
|
"Yes",
|
|
|
|
"No").Returns(Task.FromResult(false)); // User chooes "No"
|
|
|
|
|
|
|
|
var subsequent = handler.HandleRequestOption1().Result;
|
|
|
|
|
2023-04-19 12:14:14 +02:00
|
|
|
// Verify behavior
|
2022-09-06 16:08:19 +02:00
|
|
|
Received.InOrder(() =>
|
|
|
|
{
|
|
|
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|
|
|
viewService.DisplayAlert(
|
|
|
|
string.Empty,
|
|
|
|
"Cancel reservation for bike Nr. 0?",
|
|
|
|
"Yes",
|
|
|
|
"No");
|
|
|
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|
|
|
});
|
|
|
|
|
|
|
|
// Verify state after action
|
|
|
|
Assert.That(
|
|
|
|
subsequent.ButtonText,
|
2023-08-31 12:20:06 +02:00
|
|
|
Is.EqualTo("Cancel reservation"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
Assert.That(
|
|
|
|
subsequent.LockitButtonText,
|
2024-04-09 12:53:23 +02:00
|
|
|
Is.EqualTo("Start rental & Open lock"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsLockitButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCancelReservationDoCancelReservationInvalidAuthorizationResponseException()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
var connector = Substitute.For<IConnector>();
|
|
|
|
var command = Substitute.For<ICommand>();
|
|
|
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|
|
|
var activeUser = Substitute.For<IUser>();
|
|
|
|
|
|
|
|
var handler = new ReservedClosed(
|
|
|
|
bike,
|
|
|
|
() => true, // isConnectedDelegate
|
2024-04-09 12:53:23 +02:00
|
|
|
(isConnected) => connector,
|
2022-09-06 16:08:19 +02:00
|
|
|
() => pollingManager,
|
|
|
|
Substitute.For<ISmartDevice>(),
|
|
|
|
viewService,
|
|
|
|
bikesViewModel,
|
|
|
|
activeUser);
|
|
|
|
|
|
|
|
bike.Id.Returns("0");
|
|
|
|
|
|
|
|
viewService.DisplayAlert(
|
|
|
|
string.Empty,
|
|
|
|
"Cancel reservation for bike Nr. 0?",
|
|
|
|
"Yes",
|
|
|
|
"No").Returns(Task.FromResult(true));
|
|
|
|
|
|
|
|
connector.Command.DoCancelReservation(bike).Returns(x => throw new InvalidAuthorizationResponseException(
|
|
|
|
"otto@mustermann.de", JsonConvert.DeserializeObject<ResponseBase>(@"{}")));
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.Reserved); // Locking state does not change.
|
2022-09-06 16:08:19 +02:00
|
|
|
|
|
|
|
var subsequent = handler.HandleRequestOption1().Result;
|
|
|
|
|
2023-04-19 12:14:14 +02:00
|
|
|
// Verify behavior
|
2022-09-06 16:08:19 +02:00
|
|
|
Received.InOrder(() =>
|
|
|
|
{
|
|
|
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|
|
|
bikesViewModel.ActionText = "One moment please...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.ActionText = "Canceling reservation...";
|
|
|
|
connector.Command.DoCancelReservation(bike); // Booking must be performed
|
2023-02-22 14:03:35 +01:00
|
|
|
bikesViewModel.ActionText = string.Empty;
|
2022-09-06 16:08:19 +02:00
|
|
|
viewService.DisplayAlert(
|
2023-08-31 12:20:06 +02:00
|
|
|
"Reservation could not be canceled!",
|
|
|
|
"Your session has expired. Please login new and try again.",
|
2022-09-06 16:08:19 +02:00
|
|
|
"OK");
|
|
|
|
bikesViewModel.ActionText = "Updating...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StartAsync(); // polling must be restarted again
|
2023-02-22 14:03:35 +01:00
|
|
|
bikesViewModel.ActionText = string.Empty;
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|
|
|
});
|
|
|
|
|
|
|
|
// Verify state after action
|
|
|
|
Assert.That(
|
|
|
|
subsequent.ButtonText,
|
2023-08-31 12:20:06 +02:00
|
|
|
Is.EqualTo("Cancel reservation"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
Assert.That(
|
|
|
|
subsequent.LockitButtonText,
|
2024-04-09 12:53:23 +02:00
|
|
|
Is.EqualTo("Start rental & Open lock"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsLockitButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCancelReservationDoCancelReservationFailsWebConnectFailureException()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
var connector = Substitute.For<IConnector>();
|
|
|
|
var command = Substitute.For<ICommand>();
|
|
|
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|
|
|
var activeUser = Substitute.For<IUser>();
|
|
|
|
|
|
|
|
var handler = new ReservedClosed(
|
|
|
|
bike,
|
|
|
|
() => true, // isConnectedDelegate
|
2024-04-09 12:53:23 +02:00
|
|
|
(isConnected) => connector,
|
2022-09-06 16:08:19 +02:00
|
|
|
() => pollingManager,
|
|
|
|
Substitute.For<ISmartDevice>(),
|
|
|
|
viewService,
|
|
|
|
bikesViewModel,
|
|
|
|
activeUser);
|
|
|
|
|
|
|
|
bike.Id.Returns("0");
|
|
|
|
|
|
|
|
viewService.DisplayAlert(
|
|
|
|
string.Empty,
|
|
|
|
"Cancel reservation for bike Nr. 0?",
|
|
|
|
"Yes",
|
|
|
|
"No").Returns(Task.FromResult(true));
|
|
|
|
|
|
|
|
connector.Command.DoCancelReservation(bike).Returns(x => throw new WebConnectFailureException("Context info", new Exception("Tst")));
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.Reserved); // Locking state does not change.
|
2022-09-06 16:08:19 +02:00
|
|
|
|
|
|
|
var subsequent = handler.HandleRequestOption1().Result;
|
|
|
|
|
2023-04-19 12:14:14 +02:00
|
|
|
// Verify behavior
|
2022-09-06 16:08:19 +02:00
|
|
|
Received.InOrder(() =>
|
|
|
|
{
|
|
|
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|
|
|
bikesViewModel.ActionText = "One moment please...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.ActionText = "Canceling reservation...";
|
|
|
|
connector.Command.DoCancelReservation(bike); // Booking must be performed
|
2023-02-22 14:03:35 +01:00
|
|
|
bikesViewModel.ActionText = string.Empty;
|
2023-08-31 12:20:06 +02:00
|
|
|
viewService.DisplayAlert(
|
|
|
|
"Reservation could not be canceled!",
|
|
|
|
"A stable Internet connection is required. Connect to WIFI or to mobile network and activate mobile data. Try again.",
|
2022-09-06 16:08:19 +02:00
|
|
|
"OK");
|
|
|
|
bikesViewModel.ActionText = "Updating...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StartAsync(); // polling must be restarted again
|
2023-02-22 14:03:35 +01:00
|
|
|
bikesViewModel.ActionText = string.Empty;
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|
|
|
});
|
|
|
|
|
|
|
|
// Verify state after action
|
|
|
|
Assert.That(
|
|
|
|
subsequent.ButtonText,
|
2023-08-31 12:20:06 +02:00
|
|
|
Is.EqualTo("Cancel reservation"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
Assert.That(
|
|
|
|
subsequent.LockitButtonText,
|
2024-04-09 12:53:23 +02:00
|
|
|
Is.EqualTo("Start rental & Open lock"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsLockitButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Use case: Try cancel reservation.
|
|
|
|
/// Final state: Bike remains reserved.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestCancelReservationDoCancelReservationFailsException()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
var connector = Substitute.For<IConnector>();
|
|
|
|
var command = Substitute.For<ICommand>();
|
|
|
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|
|
|
var activeUser = Substitute.For<IUser>();
|
|
|
|
|
|
|
|
var handler = new ReservedClosed(
|
|
|
|
bike,
|
|
|
|
() => true, // isConnectedDelegate
|
2024-04-09 12:53:23 +02:00
|
|
|
(isConnected) => connector,
|
2022-09-06 16:08:19 +02:00
|
|
|
() => pollingManager,
|
|
|
|
Substitute.For<ISmartDevice>(),
|
|
|
|
viewService,
|
|
|
|
bikesViewModel,
|
|
|
|
activeUser);
|
|
|
|
|
|
|
|
bike.Id.Returns("0");
|
|
|
|
|
|
|
|
viewService.DisplayAlert(
|
|
|
|
string.Empty,
|
|
|
|
"Cancel reservation for bike Nr. 0?",
|
|
|
|
"Yes",
|
|
|
|
"No").Returns(Task.FromResult(true));
|
|
|
|
|
|
|
|
connector.Command.DoCancelReservation(bike).Returns(x => throw new Exception("Some error", new Exception("Inner exception")));
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.Reserved); // Locking state does not change.
|
2022-09-06 16:08:19 +02:00
|
|
|
|
|
|
|
var subsequent = handler.HandleRequestOption1().Result;
|
|
|
|
|
2023-04-19 12:14:14 +02:00
|
|
|
// Verify behavior
|
2022-09-06 16:08:19 +02:00
|
|
|
Received.InOrder(() =>
|
|
|
|
{
|
|
|
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|
|
|
bikesViewModel.ActionText = "One moment please...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.ActionText = "Canceling reservation...";
|
|
|
|
connector.Command.DoCancelReservation(bike); // Cancel reservation must be performed
|
2023-02-22 14:03:35 +01:00
|
|
|
bikesViewModel.ActionText = string.Empty;
|
2022-09-06 16:08:19 +02:00
|
|
|
viewService.DisplayAlert(
|
2023-08-31 12:20:06 +02:00
|
|
|
"Reservation could not be canceled!",
|
2022-09-06 16:08:19 +02:00
|
|
|
"Some error",
|
|
|
|
"OK");
|
|
|
|
bikesViewModel.ActionText = "Updating...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StartAsync(); // polling must be restarted again
|
2023-02-22 14:03:35 +01:00
|
|
|
bikesViewModel.ActionText = string.Empty;
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|
|
|
});
|
|
|
|
|
|
|
|
// Verify state after action
|
|
|
|
Assert.That(
|
|
|
|
subsequent.ButtonText,
|
2023-08-31 12:20:06 +02:00
|
|
|
Is.EqualTo("Cancel reservation"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
Assert.That(
|
|
|
|
subsequent.LockitButtonText,
|
2024-04-09 12:53:23 +02:00
|
|
|
Is.EqualTo("Start rental & Open lock"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsLockitButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Use case: Cancel reservation.
|
|
|
|
/// Final state: Bike is available again.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestCancelReservation()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
var connector = Substitute.For<IConnector>();
|
|
|
|
var command = Substitute.For<ICommand>();
|
|
|
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|
|
|
var activeUser = Substitute.For<IUser>();
|
|
|
|
|
|
|
|
var handler = new ReservedClosed(
|
|
|
|
bike,
|
|
|
|
() => true, // isConnectedDelegate
|
2024-04-09 12:53:23 +02:00
|
|
|
(isConnected) => connector,
|
2022-09-06 16:08:19 +02:00
|
|
|
() => pollingManager,
|
|
|
|
Substitute.For<ISmartDevice>(),
|
|
|
|
viewService,
|
|
|
|
bikesViewModel,
|
|
|
|
activeUser);
|
|
|
|
|
|
|
|
bike.Id.Returns("0");
|
|
|
|
|
|
|
|
viewService.DisplayAlert(
|
|
|
|
string.Empty,
|
|
|
|
"Cancel reservation for bike Nr. 0?",
|
|
|
|
"Yes",
|
|
|
|
"No").Returns(Task.FromResult(true));
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.Disposable); // Reservation gets canceled.
|
2022-09-06 16:08:19 +02:00
|
|
|
|
|
|
|
var subsequent = handler.HandleRequestOption1().Result;
|
|
|
|
|
2023-04-19 12:14:14 +02:00
|
|
|
// Verify behavior
|
2022-09-06 16:08:19 +02:00
|
|
|
Received.InOrder(() =>
|
|
|
|
{
|
|
|
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|
|
|
bikesViewModel.ActionText = "One moment please...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.ActionText = "Canceling reservation...";
|
|
|
|
connector.Command.DoCancelReservation(bike); // Cancel reservation must be performed
|
|
|
|
bikesViewModel.ActionText = "Updating...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StartAsync(); // polling must be restarted again
|
2023-02-22 14:03:35 +01:00
|
|
|
bikesViewModel.ActionText = string.Empty;
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|
|
|
});
|
|
|
|
|
|
|
|
// Verify state
|
|
|
|
Assert.That(
|
|
|
|
subsequent.ButtonText,
|
2024-04-09 12:53:23 +02:00
|
|
|
Is.EqualTo("Start rental & Open lock"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
Assert.That(
|
|
|
|
subsequent.LockitButtonText,
|
|
|
|
Is.EqualTo("Reserve bike"));
|
|
|
|
Assert.That(
|
|
|
|
subsequent.IsLockitButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Use case: Cancel booking.
|
|
|
|
/// Final state: Same as initial state.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestBookAndReleaseCancel()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
var connector = Substitute.For<IConnector>();
|
|
|
|
var command = Substitute.For<ICommand>();
|
|
|
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|
|
|
var activeUser = Substitute.For<IUser>();
|
|
|
|
|
|
|
|
var handler = new ReservedClosed(
|
|
|
|
bike,
|
|
|
|
() => true, // isConnectedDelegate
|
2024-04-09 12:53:23 +02:00
|
|
|
(isConnected) => connector,
|
2022-09-06 16:08:19 +02:00
|
|
|
() => pollingManager,
|
|
|
|
Substitute.For<ISmartDevice>(),
|
|
|
|
viewService,
|
|
|
|
bikesViewModel,
|
|
|
|
activeUser);
|
|
|
|
|
|
|
|
bike.Id.Returns("0");
|
|
|
|
|
|
|
|
viewService.DisplayAlert(
|
|
|
|
string.Empty,
|
|
|
|
"Rent bike Nr. 0 and open lock?",
|
|
|
|
"Yes",
|
|
|
|
"No").Returns(Task.FromResult(false)); // User chooes "No"
|
|
|
|
|
|
|
|
var subsequent = handler.HandleRequestOption2().Result;
|
|
|
|
|
2023-04-19 12:14:14 +02:00
|
|
|
// Verify behavior
|
2022-09-06 16:08:19 +02:00
|
|
|
Received.InOrder(() =>
|
|
|
|
{
|
|
|
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|
|
|
viewService.DisplayAlert(
|
|
|
|
string.Empty,
|
|
|
|
"Rent bike Nr. 0 and open lock?",
|
|
|
|
"Yes",
|
|
|
|
"No");
|
|
|
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|
|
|
});
|
|
|
|
|
|
|
|
// Verify state after action
|
|
|
|
Assert.That(
|
|
|
|
subsequent.ButtonText,
|
2023-08-31 12:20:06 +02:00
|
|
|
Is.EqualTo("Cancel reservation"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
Assert.That(
|
|
|
|
subsequent.LockitButtonText,
|
2024-04-09 12:53:23 +02:00
|
|
|
Is.EqualTo("Start rental & Open lock"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsLockitButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Use case: Try book bike and release from station.
|
|
|
|
/// Final state: Bike is disposable.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestBookAndReleaseBookAndOpenAyncFailsWebConnectFailureException()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
var connector = Substitute.For<IConnector>();
|
|
|
|
var command = Substitute.For<ICommand>();
|
|
|
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|
|
|
var activeUser = Substitute.For<IUser>();
|
|
|
|
|
|
|
|
var handler = new ReservedClosed(
|
|
|
|
bike,
|
|
|
|
() => true, // isConnectedDelegate
|
2024-04-09 12:53:23 +02:00
|
|
|
(isConnected) => connector,
|
2022-09-06 16:08:19 +02:00
|
|
|
() => pollingManager,
|
|
|
|
Substitute.For<ISmartDevice>(),
|
|
|
|
viewService,
|
|
|
|
bikesViewModel,
|
|
|
|
activeUser);
|
|
|
|
|
|
|
|
bike.Id.Returns("0");
|
|
|
|
|
|
|
|
viewService.DisplayAlert(
|
|
|
|
string.Empty,
|
|
|
|
string.Format("Rent bike {0} and open lock?", "Nr. 0"),
|
|
|
|
"Yes",
|
|
|
|
"No").Returns(Task.FromResult(true));
|
|
|
|
|
|
|
|
connector.Command.BookAndOpenAync(bike).Returns(x => throw new WebConnectFailureException("Context info", new Exception("Tst")));
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.Reserved); // State remains reserved because booking request failed.
|
2022-09-06 16:08:19 +02:00
|
|
|
|
|
|
|
var subsequent = handler.HandleRequestOption2().Result;
|
|
|
|
|
2023-04-19 12:14:14 +02:00
|
|
|
// Verify behavior
|
2022-09-06 16:08:19 +02:00
|
|
|
Received.InOrder(() =>
|
|
|
|
{
|
|
|
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|
|
|
bikesViewModel.ActionText = "One moment please...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.ActionText = "Renting bike...";
|
|
|
|
connector.Command.BookAndOpenAync(bike); // Booking must be performed
|
2023-02-22 14:03:35 +01:00
|
|
|
bikesViewModel.ActionText = string.Empty;
|
2023-08-31 12:20:06 +02:00
|
|
|
viewService.DisplayAlert(
|
|
|
|
"Connection to booking system not possible.",
|
|
|
|
"A stable Internet connection is required. Connect to WIFI or to mobile network and activate mobile data. Try again.",
|
2022-09-06 16:08:19 +02:00
|
|
|
"OK");
|
|
|
|
bikesViewModel.ActionText = "Updating...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StartAsync(); // polling must be restarted again
|
2023-02-22 14:03:35 +01:00
|
|
|
bikesViewModel.ActionText = string.Empty;
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|
|
|
});
|
|
|
|
|
|
|
|
// Verify state after action
|
|
|
|
Assert.That(
|
|
|
|
subsequent.ButtonText,
|
2023-08-31 12:20:06 +02:00
|
|
|
Is.EqualTo("Cancel reservation"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
Assert.That(
|
|
|
|
subsequent.LockitButtonText,
|
2024-04-09 12:53:23 +02:00
|
|
|
Is.EqualTo("Start rental & Open lock"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsLockitButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Use case: Try book bike and release from station.
|
|
|
|
/// Final state: Bike is disposable.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestBookAndReleaseBookAndOpenAyncFailsException()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
var connector = Substitute.For<IConnector>();
|
|
|
|
var command = Substitute.For<ICommand>();
|
|
|
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|
|
|
var activeUser = Substitute.For<IUser>();
|
|
|
|
|
|
|
|
var handler = new ReservedClosed(
|
|
|
|
bike,
|
|
|
|
() => true, // isConnectedDelegate
|
2024-04-09 12:53:23 +02:00
|
|
|
(isConnected) => connector,
|
2022-09-06 16:08:19 +02:00
|
|
|
() => pollingManager,
|
|
|
|
Substitute.For<ISmartDevice>(),
|
|
|
|
viewService,
|
|
|
|
bikesViewModel,
|
|
|
|
activeUser);
|
|
|
|
|
|
|
|
bike.Id.Returns("0");
|
|
|
|
|
|
|
|
viewService.DisplayAlert(
|
|
|
|
string.Empty,
|
|
|
|
string.Format("Rent bike {0} and open lock?", "Nr. 0"),
|
|
|
|
"Yes",
|
|
|
|
"No").Returns(Task.FromResult(true));
|
|
|
|
|
|
|
|
connector.Command.BookAndOpenAync(bike).Returns(x => throw new Exception("Some error", new Exception("Inner exception")));
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.Reserved); // State remains reserved because booking request failed.
|
2022-09-06 16:08:19 +02:00
|
|
|
|
|
|
|
var subsequent = handler.HandleRequestOption2().Result;
|
|
|
|
|
2023-04-19 12:14:14 +02:00
|
|
|
// Verify behavior
|
2022-09-06 16:08:19 +02:00
|
|
|
Received.InOrder(() =>
|
|
|
|
{
|
|
|
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|
|
|
bikesViewModel.ActionText = "One moment please...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.ActionText = "Renting bike...";
|
|
|
|
connector.Command.BookAndOpenAync(bike); // Booking must be performed
|
2023-02-22 14:03:35 +01:00
|
|
|
bikesViewModel.ActionText = string.Empty;
|
2022-09-06 16:08:19 +02:00
|
|
|
viewService.DisplayAdvancedAlert(
|
2023-08-31 12:20:06 +02:00
|
|
|
"Bike could not be rented!",
|
2022-09-06 16:08:19 +02:00
|
|
|
"Some error",
|
|
|
|
String.Empty,
|
|
|
|
"OK");
|
|
|
|
bikesViewModel.ActionText = "Updating...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StartAsync(); // polling must be restarted again
|
2023-02-22 14:03:35 +01:00
|
|
|
bikesViewModel.ActionText = string.Empty;
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|
|
|
});
|
|
|
|
|
|
|
|
// Verify state after action
|
|
|
|
Assert.That(
|
|
|
|
subsequent.ButtonText,
|
2023-08-31 12:20:06 +02:00
|
|
|
Is.EqualTo("Cancel reservation"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
Assert.That(
|
|
|
|
subsequent.LockitButtonText,
|
2024-04-09 12:53:23 +02:00
|
|
|
Is.EqualTo("Start rental & Open lock"));
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
subsequent.IsLockitButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Use case: Book bike and release from station.
|
|
|
|
/// Final state: Bike is booked and released from station.
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TestBookAndRelease()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
var connector = Substitute.For<IConnector>();
|
|
|
|
var command = Substitute.For<ICommand>();
|
|
|
|
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
|
|
|
var activeUser = Substitute.For<IUser>();
|
|
|
|
|
|
|
|
var handler = new ReservedClosed(
|
|
|
|
bike,
|
|
|
|
() => true, // isConnectedDelegate
|
2024-04-09 12:53:23 +02:00
|
|
|
(isConnected) => connector,
|
2022-09-06 16:08:19 +02:00
|
|
|
() => pollingManager,
|
|
|
|
Substitute.For<ISmartDevice>(),
|
|
|
|
viewService,
|
|
|
|
bikesViewModel,
|
|
|
|
activeUser);
|
|
|
|
|
|
|
|
bike.Id.Returns("0");
|
|
|
|
|
|
|
|
viewService.DisplayAlert(
|
|
|
|
string.Empty,
|
|
|
|
string.Format("Rent bike {0} and open lock?", "Nr. 0"),
|
|
|
|
"Yes",
|
|
|
|
"No").Returns(Task.FromResult(true));
|
|
|
|
|
|
|
|
bike.LockInfo.State.Returns(LockingState.Open); // After Booking and opening, lock state is open.
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.Booked); // After Booking and opening, state is booked.
|
2022-09-06 16:08:19 +02:00
|
|
|
|
|
|
|
var subsequent = handler.HandleRequestOption2().Result;
|
|
|
|
|
2023-04-19 12:14:14 +02:00
|
|
|
// Verify behavior
|
2022-09-06 16:08:19 +02:00
|
|
|
Received.InOrder(() =>
|
|
|
|
{
|
|
|
|
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
|
|
|
bikesViewModel.ActionText = "One moment please...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.ActionText = "Renting bike...";
|
|
|
|
connector.Command.BookAndOpenAync(bike); // Booking must be performed
|
|
|
|
bikesViewModel.ActionText = "Updating...";
|
2023-08-31 12:20:06 +02:00
|
|
|
pollingManager.StartAsync(); // polling must be restarted again
|
2023-02-22 14:03:35 +01:00
|
|
|
bikesViewModel.ActionText = string.Empty;
|
2022-09-06 16:08:19 +02:00
|
|
|
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
|
|
|
});
|
|
|
|
|
|
|
|
// Verify state
|
|
|
|
Assert.That(
|
|
|
|
subsequent.ButtonText,
|
|
|
|
Is.EqualTo("BookedOpen"));
|
|
|
|
Assert.That(
|
|
|
|
subsequent.IsButtonVisible,
|
|
|
|
Is.False);
|
|
|
|
Assert.That(
|
|
|
|
subsequent.LockitButtonText,
|
|
|
|
Is.EqualTo("Open lock"));
|
|
|
|
Assert.That(
|
|
|
|
subsequent.IsLockitButtonVisible,
|
|
|
|
Is.True);
|
|
|
|
}
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
}
|