Version 3.0.381

This commit is contained in:
Anja 2024-04-09 12:53:23 +02:00
parent f963c0a219
commit 3a363acf3a
1525 changed files with 60589 additions and 125098 deletions

View file

@ -0,0 +1,44 @@
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.User;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.Services.Geolocation;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
{
[TestFixture]
public class TestBookedClosed
{
/// <summary>
/// Test construction of object.
/// </summary>
[Test]
public void Testctor()
{
var handler = new BookedClosed(
Substitute.For<IBikeInfoMutable>(),
() => true, // isConnectedDelegate
(isConnected) => Substitute.For<IConnector>(),
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
Substitute.For<ISmartDevice>(),
Substitute.For<IViewService>(),
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>());
// Verify prerequisites.
Assert.That(handler.ButtonText, Is.EqualTo("End rental"));
Assert.That(handler.IsButtonVisible, Is.True);
Assert.That(handler.LockitButtonText, Is.EqualTo("Open lock"));
Assert.That(handler.IsLockitButtonVisible, Is.True);
}
}
}

View file

@ -0,0 +1,78 @@
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.User;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.Services.Geolocation;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
{
[TestFixture]
public class TestBookedDisconnected
{
/// <summary>
/// Test construction of object.
/// </summary>
[Test]
public void Testctor()
{
var handler = new BookedDisconnected(
Substitute.For<IBikeInfoMutable>(),
() => true, // isConnectedDelegate
(isConnected) => Substitute.For<IConnector>(),
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
Substitute.For<ISmartDevice>(),
Substitute.For<IViewService>(),
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>());
// Verify prerequisites.
Assert.That(handler.ButtonText, Is.EqualTo("Connect lock"));
Assert.That(handler.IsButtonVisible, Is.True);
Assert.That(handler.LockitButtonText, Is.EqualTo("BookedDisconnected"));
Assert.That(handler.IsLockitButtonVisible, Is.False);
}
[Test]
public void TestNotSupported()
{
var bike = Substitute.For<IBikeInfoMutable>();
var connector = Substitute.For<IConnector>();
var command = Substitute.For<ICommand>();
var geolocation = Substitute.For<IGeolocationService>();
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 BookedDisconnected(
bike,
() => true, // isConnectedDelegate
(isConnected) => connector,
geolocation,
locks,
() => pollingManager,
Substitute.For<ISmartDevice>(),
viewService,
bikesViewModel,
activeUser);
var subsequent = handler.HandleRequestOption2().Result;
// Verify that nothing happened because request is not supported.
Assert.That(subsequent.ButtonText, Is.EqualTo("Connect lock"));
Assert.That(subsequent.IsButtonVisible, Is.True);
Assert.That(subsequent.LockitButtonText, Is.EqualTo("BookedDisconnected"));
Assert.That(subsequent.IsLockitButtonVisible, Is.False);
}
}
}

View file

@ -0,0 +1,44 @@
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.User;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.Services.Geolocation;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
{
[TestFixture]
public class TestBookedOpen
{
/// <summary>
/// Test construction of object.
/// </summary>
[Test]
public void Testctor()
{
var handler = new BookedOpen(
Substitute.For<IBikeInfoMutable>(),
() => true, // isConnectedDelegate
(isConnected) => Substitute.For<IConnector>(),
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
Substitute.For<ISmartDevice>(),
Substitute.For<IViewService>(),
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>());
// Verify prerequisites.
Assert.That(handler.ButtonText, Is.EqualTo("Close lock"));
Assert.That(handler.IsButtonVisible, Is.True);
Assert.That(handler.LockitButtonText, Is.EqualTo("BookedOpen"));
Assert.That(handler.IsLockitButtonVisible, Is.False);
}
}
}

View file

@ -0,0 +1,46 @@
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.User;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.Services.Geolocation;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
namespace SharedBusinessLogic.Tests.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
{
[TestFixture]
public class TestBookedUnknown
{
/// <summary>
/// Test construction of object.
/// </summary>
[Test]
public void Testctor()
{
var handler = new BookedUnknown(
Substitute.For<IBikeInfoMutable>(),
() => true, // isConnectedDelegate
(isConnected) => Substitute.For<IConnector>(),
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
Substitute.For<ISmartDevice>(),
Substitute.For<IViewService>(),
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>());
// Verify prerequisites.
Assert.That(handler.ButtonText, Is.EqualTo("Open lock"));
Assert.That(handler.IsButtonVisible, Is.True);
Assert.That(handler.LockitButtonText, Is.EqualTo("Close lock"));
Assert.That(handler.IsLockitButtonVisible, Is.True);
}
}
}

View file

@ -0,0 +1,44 @@
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.User;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.Services.Geolocation;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
{
[TestFixture]
public class TestDisposableDisconnected
{
/// <summary>
/// Test construction of object.
/// </summary>
[Test]
public void Testctor()
{
var handler = new DisposableDisconnected(
Substitute.For<IBikeInfoMutable>(),
() => true, // isConnectedDelegate
(isConnected) => Substitute.For<IConnector>(),
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
Substitute.For<ISmartDevice>(),
Substitute.For<IViewService>(),
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>());
// Verify prerequisites.
Assert.That(handler.ButtonText, Is.EqualTo("Reserve / Rent"));
Assert.That(handler.IsButtonVisible, Is.True);
Assert.That(handler.LockitButtonText, Is.EqualTo("DisposableDisconnected"));
Assert.That(handler.IsLockitButtonVisible, Is.False);
}
}
}

View file

@ -0,0 +1,45 @@
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.User;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.Services.Geolocation;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
{
[TestFixture]
public class TestDisposableOpen
{
/// <summary>
/// Test construction of object.
/// </summary>
[Test]
public void Testctor()
{
var handler = new DisposableOpen(
Substitute.For<IBikeInfoMutable>(),
() => true, // isConnectedDelegate
(isConnected) => Substitute.For<IConnector>(),
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
Substitute.For<ISmartDevice>(),
Substitute.For<IViewService>(),
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>());
// Verify prerequisites.
Assert.That(handler.ButtonText, Is.EqualTo("Reserve / Rent"));
Assert.That(handler.IsButtonVisible, Is.True);
Assert.That(handler.LockitButtonText, Is.EqualTo("Close lock"));
Assert.That(handler.IsLockitButtonVisible, Is.True);
}
}
}

View file

@ -0,0 +1,44 @@
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.User;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.Services.Geolocation;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
namespace SharedBusinessLogic.Tests.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
{
[TestFixture]
public class TestReservedClosed
{
/// <summary>
/// Test construction of object.
/// </summary>
[Test]
public void Testctor()
{
var handler = new ReservedClosed(
Substitute.For<IBikeInfoMutable>(),
() => true, // isConnectedDelegate
(isConnected) => Substitute.For<IConnector>(),
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
Substitute.For<ISmartDevice>(),
Substitute.For<IViewService>(),
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>());
// Verify prerequisites.
Assert.That(handler.ButtonText, Is.EqualTo("Cancel reservation"));
Assert.That(handler.IsButtonVisible, Is.True);
Assert.That(handler.LockitButtonText, Is.EqualTo("Start rental & Open lock"));
Assert.That(handler.IsLockitButtonVisible, Is.True);
}
}
}

View file

@ -0,0 +1,44 @@
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.User;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.Services.Geolocation;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
namespace SharedBusinessLogic.Tests.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
(isConnected) => Substitute.For<IConnector>(),
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
Substitute.For<ISmartDevice>(),
Substitute.For<IViewService>(),
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>());
// Verify prerequisites.
Assert.That(handler.ButtonText, Is.EqualTo("Cancel reservation"));
Assert.That(handler.IsButtonVisible, Is.True);
Assert.That(handler.LockitButtonText, Is.EqualTo("Start rental"));
Assert.That(handler.IsLockitButtonVisible, Is.True);
}
}
}

View file

@ -0,0 +1,44 @@
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.User;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.Services.Geolocation;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
{
[TestFixture]
public class TestReservedOpen
{
/// <summary>
/// Test construction of object.
/// </summary>
[Test]
public void Testctor()
{
var handler = new ReservedOpen(
Substitute.For<IBikeInfoMutable>(),
() => true, // isConnectedDelegate
(isConnected) => Substitute.For<IConnector>(),
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
Substitute.For<ISmartDevice>(),
Substitute.For<IViewService>(),
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>());
// Verify prerequisites.
Assert.That(handler.ButtonText, Is.EqualTo("Close lock"));
Assert.That(handler.IsButtonVisible, Is.True);
Assert.That(handler.LockitButtonText, Is.EqualTo("Start rental"));
Assert.That(handler.IsLockitButtonVisible, Is.True);
}
}
}

View file

@ -0,0 +1,44 @@
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.User;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.Services.Geolocation;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
namespace SharedBusinessLogic.Tests.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
{
[TestFixture]
public class TestReservedUnknown
{
/// <summary>
/// Test construction of object.
/// </summary>
[Test]
public void Testctor()
{
var handler = new ReservedUnknown(
Substitute.For<IBikeInfoMutable>(),
() => true, // isConnectedDelegate
(isConnected) => Substitute.For<IConnector>(),
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
Substitute.For<ISmartDevice>(),
Substitute.For<IViewService>(),
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>());
// Verify prerequisites.
Assert.That(handler.ButtonText, Is.EqualTo("Close lock"));
Assert.That(handler.IsButtonVisible, Is.True);
Assert.That(handler.LockitButtonText, Is.EqualTo("Start rental"));
Assert.That(handler.IsLockitButtonVisible, Is.True);
}
}
}

View file

@ -0,0 +1,207 @@
using System.Threading.Tasks;
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.State;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
using CloseCommand = ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.Command.CloseCommand;
namespace SharedBusinessLogic.Tests.ViewModel.Bikes.Bike.BluetoothLock
{
[TestFixture]
public class TestCloseLockActionViewModel
{
/// <summary>
/// Use case: Close lock.
/// Final state: Occupied closed, End rental requested
/// </summary>
[Test]
public async Task TestCloseLockAndRequestEndRental()
{
var bike = Substitute.For<IBikeInfoMutable>();
var connector = Substitute.For<IConnector>();
var command = Substitute.For<ICommand>();
var locks = Substitute.For<ILocksService>();
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
var viewService = Substitute.For<IViewService>();
var bikesViewModel = Substitute.For<IBikesViewModel>();
var listener = Substitute.For<CloseCommand.ICloseCommandListener>();
var closeLockActionViewModel = new CloseLockActionViewModel<BookedOpen>(
bike,
() => pollingManager,
viewService,
bikesViewModel);
bike.Id.Returns("0");
bike.CloseLockAsync(Arg.Any<CloseCommand.ICloseCommandListener>(), Arg.Any<Task>()).Returns(x =>
{
// Add calls to ReportStep which IBikeInfoMutable implementation would do.
closeLockActionViewModel.ReportStep(CloseCommand.Step.StartingQueryingLocation);
closeLockActionViewModel.ReportStep(CloseCommand.Step.ClosingLock);
closeLockActionViewModel.ReportStep(CloseCommand.Step.WaitStopPollingQueryLocation);
closeLockActionViewModel.ReportStep(CloseCommand.Step.QueryLocationTerminated);
closeLockActionViewModel.ReportStep(CloseCommand.Step.UpdateLockingState);
return Task.CompletedTask;
});
bike.State.Value.Returns(InUseStateEnum.Booked); // Request handler factory queries state to create appropriate request handler object.
bike.LockInfo.State.Returns(LockingState.Closed); // Request handler factory queries lock state to create appropriate request handler object.
await closeLockActionViewModel.CloseLockAsync();
// Verify behavior
Received.InOrder(() =>
{
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.StartRentalProcess(Arg.Is<IRentalProcessViewModel>(
x => x.BikeId == "0"
&& x.State == CurrentRentalProcess.CloseLock
&& x.StepIndex == 1
&& x.Result == CurrentStepStatus.None));
//Step.StartingQueryingLocation
bikesViewModel.ActionText = "Start query location...";
//Step.ClosingLock
bikesViewModel.ActionText = "The lock bolt moves through the spokes of the rear wheel.";
//Step.WaitStopPollingQueryLocation
bikesViewModel.ActionText = "Query location...";
//Step.UpdateLockingState
bikesViewModel.ActionText = "Updating lock state...";
bikesViewModel.RentalProcess.Result = CurrentStepStatus.Succeeded;
bikesViewModel.RentalProcess.StepIndex = 2;
bikesViewModel.RentalProcess.Result = CurrentStepStatus.None;
//Ask whether park bike or end rental
viewService.DisplayAlert(
"Please choose",
"Do you want to park the bike to continue riding later or return the bike now and end the rental?",
"End rental",
"Park bike"
);
closeLockActionViewModel.IsEndRentalRequested = true;
bikesViewModel.RentalProcess.Result = CurrentStepStatus.Succeeded;
bikesViewModel.ActionText = "One moment please...";
pollingManager.StartAsync(); // polling must be restarted again
bikesViewModel.ActionText = string.Empty;
bikesViewModel.RentalProcess.State = CurrentRentalProcess.None;
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
return;
});
}
/// <summary>
/// Use case: Close lock.
/// Final state: Occupied closed, Park bike requested
/// </summary>
[Test]
public async Task TestCloseLockAndRequestParkBike()
{
var bike = Substitute.For<IBikeInfoMutable>();
var connector = Substitute.For<IConnector>();
var command = Substitute.For<ICommand>();
var locks = Substitute.For<ILocksService>();
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
var viewService = Substitute.For<IViewService>();
var bikesViewModel = Substitute.For<IBikesViewModel>();
var listener = Substitute.For<CloseCommand.ICloseCommandListener>();
var closeLockActionViewModel = new CloseLockActionViewModel<BookedOpen>(
bike,
() => pollingManager,
viewService,
bikesViewModel);
bike.Id.Returns("0");
bike.CloseLockAsync(Arg.Any<CloseCommand.ICloseCommandListener>(), Arg.Any<Task>()).Returns(x =>
{
// Add calls to ReportStep which IBikeInfoMutable implementation would do.
closeLockActionViewModel.ReportStep(CloseCommand.Step.StartingQueryingLocation);
closeLockActionViewModel.ReportStep(CloseCommand.Step.ClosingLock);
closeLockActionViewModel.ReportStep(CloseCommand.Step.WaitStopPollingQueryLocation);
closeLockActionViewModel.ReportStep(CloseCommand.Step.QueryLocationTerminated);
closeLockActionViewModel.ReportStep(CloseCommand.Step.UpdateLockingState);
return Task.CompletedTask;
});
bike.State.Value.Returns(InUseStateEnum.Booked); // Request handler factory queries state to create appropriate request handler object.
bike.LockInfo.State.Returns(LockingState.Closed); // Request handler factory queries lock state to create appropriate request handler object.
await closeLockActionViewModel.CloseLockAsync();
// Verify behavior
Received.InOrder(() =>
{
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.StartRentalProcess(Arg.Is<IRentalProcessViewModel>(
x => x.BikeId == "0"
&& x.State == CurrentRentalProcess.CloseLock
&& x.StepIndex == 1
&& x.Result == CurrentStepStatus.None));
//Step.StartingQueryingLocation
bikesViewModel.ActionText = "Start query location...";
//Step.ClosingLock
bikesViewModel.ActionText = "The lock bolt moves through the spokes of the rear wheel.";
//Step.WaitStopPollingQueryLocation
bikesViewModel.ActionText = "Query location...";
//Step.UpdateLockingState
bikesViewModel.ActionText = "Updating lock state...";
bikesViewModel.RentalProcess.Result = CurrentStepStatus.Succeeded;
bikesViewModel.RentalProcess.StepIndex = 2;
bikesViewModel.RentalProcess.Result = CurrentStepStatus.None;
//Ask whether park bike or end rental
viewService.DisplayAlert(
"Please choose",
"Do you want to park the bike to continue riding later or return the bike now and end the rental?",
"End rental",
"Park bike"
);
closeLockActionViewModel.IsEndRentalRequested = false;
bikesViewModel.RentalProcess.Result = CurrentStepStatus.Succeeded;
//Show confirmation
viewService.DisplayAlert(
"Lock is closed",
"Bike is parked. Your chargeable rental continues!",
"OK"
);
bikesViewModel.ActionText = "One moment please...";
pollingManager.StartAsync(); // polling must be restarted again
bikesViewModel.ActionText = string.Empty;
bikesViewModel.RentalProcess.State = CurrentRentalProcess.None;
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
return;
});
}
}
}

View file

@ -0,0 +1,79 @@
using System.Threading.Tasks;
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.State;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
using AuthCommand = ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Command.AuthCommand;
using ConnectCommand = ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.Command.ConnectAndGetStateCommand;
namespace SharedBusinessLogic.Tests.ViewModel.Bikes.Bike.BluetoothLock
{
[TestFixture]
public class TestConnectLockActionViewModel
{
/// <summary>
/// Use case: Connect lock.
/// Final state: Occupied open
/// </summary>
[Test]
public async Task TestConnectLock()
{
var bike = Substitute.For<IBikeInfoMutable>();
var connector = Substitute.For<IConnector>();
var command = Substitute.For<ICommand>();
var locks = Substitute.For<ILocksService>();
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
var viewService = Substitute.For<IViewService>();
var bikesViewModel = Substitute.For<IBikesViewModel>();
var listener = Substitute.For<ConnectCommand.IConnectAndGetStateCommandListener>();
var connectLockActionViewModel = new ConnectLockActionViewModel<BookedDisconnected>(
bike,
() => pollingManager,
viewService,
bikesViewModel);
bike.Id.Returns("0");
bike.ConnectAsync(Arg.Any<ConnectCommand.IConnectAndGetStateCommandListener>()).Returns(x =>
{
// Add calls to ReportStep which IBikeInfoMutable implementation would do.
connectLockActionViewModel.ReportStep(AuthCommand.Step.Authenticate);
connectLockActionViewModel.ReportStep(ConnectCommand.Step.ConnectLock);
connectLockActionViewModel.ReportStep(ConnectCommand.Step.GetLockingState);
return Task.CompletedTask;
});
bike.State.Value.Returns(InUseStateEnum.Booked); // Request handler factory queries state to create appropriate request handler object.
bike.LockInfo.State.Returns(LockingState.Open); // Request handler factory queries lock state to create appropriate request handler object.
await connectLockActionViewModel.ConnectLockAsync();
// Verify behavior
Received.InOrder(() =>
{
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
//Auth
bikesViewModel.ActionText = "Calculate authentication keys...";
//Connect lock & Get State
bikesViewModel.ActionText = "Connecting lock...";
bikesViewModel.ActionText = "One moment please...";
pollingManager.StartAsync(); // polling must be restarted again
bikesViewModel.ActionText = string.Empty;
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
return;
});
}
}
}

View file

@ -0,0 +1,90 @@
using System.Threading.Tasks;
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.Command;
using ShareeBike.Model.Connector;
using ShareeBike.Model.State;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
using OpenCommand = ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.Command.OpenCommand;
namespace SharedBusinessLogic.Tests.ViewModel.Bikes.Bike.BluetoothLock
{
[TestFixture]
public class TestOpenLockActionViewModel
{
/// <summary>
/// Use case: Open lock.
/// Final state: Occupied open
/// </summary>
[Test]
public async Task TestOpenLock()
{
var bike = Substitute.For<IBikeInfoMutable>();
var connector = Substitute.For<IConnector>();
var command = Substitute.For<ICommand>();
var locks = Substitute.For<ILocksService>();
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
var viewService = Substitute.For<IViewService>();
var bikesViewModel = Substitute.For<IBikesViewModel>();
var listener = Substitute.For<OpenCommand.IOpenCommandListener>();
var openLockActionViewModel = new OpenLockActionViewModel<BookedClosed>(
bike,
() => pollingManager,
viewService,
bikesViewModel);
bike.Id.Returns("0");
bike.OpenLockAsync(Arg.Any<OpenCommand.IOpenCommandListener>(), Arg.Any<Task>()).Returns(x =>
{
// Add calls to ReportStep which IBikeInfoMutable implementation would do.
openLockActionViewModel.ReportStep(OpenCommand.Step.OpeningLock);
openLockActionViewModel.ReportStep(OpenCommand.Step.GetLockInfos);
openLockActionViewModel.ReportStep(OpenCommand.Step.UpdateLockingState);
return Task.CompletedTask;
});
bike.State.Value.Returns(InUseStateEnum.Booked); // Request handler factory queries state to create appropriate request handler object.
bike.LockInfo.State.Returns(LockingState.Open); // Request handler factory queries lock state to create appropriate request handler object.
await openLockActionViewModel.OpenLockAsync();
// Verify behavior
Received.InOrder(() =>
{
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopAsync(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.StartRentalProcess(Arg.Is<IRentalProcessViewModel>(
x => x.BikeId == "0"
&& x.State == CurrentRentalProcess.OpenLock
&& x.StepIndex == 1
&& x.Result == CurrentStepStatus.None));
//ClosingLock & GetLockInfos
bikesViewModel.ActionText = "The lock bolt moves through the spokes of the rear wheel.";
//UpdateLockingState
bikesViewModel.ActionText = "Updating lock state...";
bikesViewModel.RentalProcess.Result = CurrentStepStatus.Succeeded;
bikesViewModel.ActionText = "One moment please...";
pollingManager.StartAsync(); // polling must be restarted again
bikesViewModel.ActionText = string.Empty;
bikesViewModel.RentalProcess.State = CurrentRentalProcess.None;
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
return;
});
}
}
}

View file

@ -0,0 +1,194 @@
using System;
using System.Collections.Generic;
using NSubstitute;
using NUnit.Framework;
using SharedBusinessLogic.Tests.Framework.Model.Services.Geolocation;
using SharedBusinessLogic.Tests.Framework.Services.BluetoothLock;
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.State;
using ShareeBike.Model.User;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.Services.Geolocation;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock;
using ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.Bike.BluetoothLock
{
/// <summary>
/// Moved to SharedBusinessLogic.Tests (.Net Core)
/// </summary>
[TestFixture]
public class TestRequestHandlerFactory
{
[Test]
public void TestCreate()
{
// Verify handler for disposable bike.
var bike = new BikeInfoMutable(
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
new BikeInfo(new ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt), new DriveMutable(), ShareeBike.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "12"),
"My Station Name");
Assert.That(bike.State.Value, Is.EqualTo(InUseStateEnum.Disposable));
Assert.That(bike.LockInfo.State, Is.EqualTo(LockingState.UnknownDisconnected));
Assert.That(
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
Substitute.For<ISmartDevice>(),
null /* viewService */ ,
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(DisposableDisconnected)));
// Verify handler for requested bike with state unknown.
bike = new BikeInfoMutable(
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
new BikeInfo(new ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new DriveMutable(), ShareeBike.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 0 /* lock Id */, new Guid(), /*K User*/ null, /*K Admin*/ null, /*K Seed*/ null, new DateTime(2020, 1, 1), "a@b.com", "12", null, null, () => new DateTime(2020, 1, 1), false, new List<string>()),
"My Station Name");
Assert.That(
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
Substitute.For<ISmartDevice>(),
null /* viewService */,
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(ReservedDisconnected)));
// Verify handler for requested bike with state closed.
bike = new BikeInfoMutable(
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
new BikeInfo(new ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new DriveMutable(), ShareeBike.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 0 /* lock Id*/, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b.com", "12", null, null, () => new DateTime(2020, 1, 1), false, new List<string>()),
"My Station Name");
bike.LockInfo.State = LockingState.Closed;
Assert.That(
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
Substitute.For<ISmartDevice>(),
null /* viewService */,
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(ReservedClosed)));
// Verify handler for requested bike with state open.
bike = new BikeInfoMutable(
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
new BikeInfo(new ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new DriveMutable(), ShareeBike.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 0 /* lock Id*/, new Guid(), null /* user key */, null, null, new DateTime(2020, 1, 1), "a@b.com", "12", null, null, () => new DateTime(2020, 1, 1), false, new List<string>()),
"My Station Name");
bike.LockInfo.State = LockingState.Open;
Assert.That(
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
Substitute.For<ISmartDevice>(),
null /* viewService */,
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(ReservedOpen)));
// Verify handler for booked bike with state closed.
bike = new BikeInfoMutable(
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
new BikeInfo(new ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new DriveMutable(), ShareeBike.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 0 /* lock Id*/, new Guid(), null, null, null, new System.DateTime(2020, 1, 1), "a@b.com", "12", null /*operator uri*/, null, false, new List<string>()),
"My Station Name");
bike.LockInfo.State = LockingState.Closed;
Assert.That(
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
Substitute.For<ISmartDevice>(),
null /* viewService */,
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(BookedClosed)));
// Verify handler for booked bike with state open.
bike = new BikeInfoMutable(
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
new BikeInfo(new ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new DriveMutable(), ShareeBike.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 0 /* lock Id*/, new Guid(), null, null, null, new System.DateTime(2020, 1, 1), "a@b.com", "12", null /*operator uri*/, null, false, new List<string>()),
"My Station Name");
bike.LockInfo.State = LockingState.Open;
Assert.That(
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
Substitute.For<ISmartDevice>(),
null /* viewService */,
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(BookedOpen)));
// Verify handler for booked bike with state unknown.
bike = new BikeInfoMutable(
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
new BikeInfo(new ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new DriveMutable(), ShareeBike.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 0 /* lock Id*/, new Guid(), null, null, null, new System.DateTime(2020, 1, 1), "a@b.com", "12", null /*operator uri*/, null, false, new List<string>()),
"My Station Name");
Assert.That(
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
Substitute.For<ISmartDevice>(),
null /* viewService */,
Substitute.For<IBikesViewModel>(),
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(BookedDisconnected)));
}
}
}