sharee.bike-App/SharedBusinessLogic.Tests/ViewModel/Bikes/Bike/BluetoothLock/TestRequestHandlerFactory.cs

195 lines
9 KiB
C#
Raw Permalink Normal View History

2023-01-18 14:22:51 +01:00
using System;
2021-07-12 21:31:46 +02:00
using System.Collections.Generic;
2023-08-31 12:20:06 +02:00
using NSubstitute;
2022-08-30 15:42:25 +02:00
using NUnit.Framework;
2024-04-09 12:53:23 +02:00
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;
2021-07-12 21:31:46 +02:00
2024-04-09 12:53:23 +02:00
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.Bike.BluetoothLock
2021-07-12 21:31:46 +02:00
{
2022-09-06 16:08:19 +02:00
/// <summary>
2024-04-09 12:53:23 +02:00
/// Moved to SharedBusinessLogic.Tests (.Net Core)
2022-09-06 16:08:19 +02:00
/// </summary>
[TestFixture]
public class TestRequestHandlerFactory
{
[Test]
public void TestCreate()
{
// Verify handler for disposable bike.
var bike = new BikeInfoMutable(
2023-08-31 12:20:06 +02:00
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
2024-04-09 12:53:23 +02:00
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"),
2022-09-06 16:08:19 +02:00
"My Station Name");
2024-04-09 12:53:23 +02:00
Assert.That(bike.State.Value, Is.EqualTo(InUseStateEnum.Disposable));
Assert.That(bike.LockInfo.State, Is.EqualTo(LockingState.UnknownDisconnected));
Assert.That(
2022-09-06 16:08:19 +02:00
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
2023-08-31 12:20:06 +02:00
Substitute.For<ISmartDevice>(),
2022-09-06 16:08:19 +02:00
null /* viewService */ ,
2023-08-31 12:20:06 +02:00
Substitute.For<IBikesViewModel>(),
2024-04-09 12:53:23 +02:00
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(DisposableDisconnected)));
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
// Verify handler for requested bike with state unknown.
bike = new BikeInfoMutable(
2023-08-31 12:20:06 +02:00
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
2024-04-09 12:53:23 +02:00
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>()),
2022-09-06 16:08:19 +02:00
"My Station Name");
2024-04-09 12:53:23 +02:00
Assert.That(
2022-09-06 16:08:19 +02:00
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
2023-08-31 12:20:06 +02:00
Substitute.For<ISmartDevice>(),
2022-09-06 16:08:19 +02:00
null /* viewService */,
2023-08-31 12:20:06 +02:00
Substitute.For<IBikesViewModel>(),
2024-04-09 12:53:23 +02:00
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(ReservedDisconnected)));
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
// Verify handler for requested bike with state closed.
bike = new BikeInfoMutable(
2023-08-31 12:20:06 +02:00
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
2024-04-09 12:53:23 +02:00
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>()),
2022-09-06 16:08:19 +02:00
"My Station Name");
bike.LockInfo.State = LockingState.Closed;
2024-04-09 12:53:23 +02:00
Assert.That(
2022-09-06 16:08:19 +02:00
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
2023-08-31 12:20:06 +02:00
Substitute.For<ISmartDevice>(),
2022-09-06 16:08:19 +02:00
null /* viewService */,
2023-08-31 12:20:06 +02:00
Substitute.For<IBikesViewModel>(),
2024-04-09 12:53:23 +02:00
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(ReservedClosed)));
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
// Verify handler for requested bike with state open.
bike = new BikeInfoMutable(
2023-08-31 12:20:06 +02:00
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
2024-04-09 12:53:23 +02:00
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>()),
2022-09-06 16:08:19 +02:00
"My Station Name");
bike.LockInfo.State = LockingState.Open;
2024-04-09 12:53:23 +02:00
Assert.That(
2022-09-06 16:08:19 +02:00
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
2023-08-31 12:20:06 +02:00
Substitute.For<ISmartDevice>(),
2022-09-06 16:08:19 +02:00
null /* viewService */,
2023-08-31 12:20:06 +02:00
Substitute.For<IBikesViewModel>(),
2024-04-09 12:53:23 +02:00
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(ReservedOpen)));
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
// Verify handler for booked bike with state closed.
bike = new BikeInfoMutable(
2023-08-31 12:20:06 +02:00
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
2024-04-09 12:53:23 +02:00
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>()),
2022-09-06 16:08:19 +02:00
"My Station Name");
bike.LockInfo.State = LockingState.Closed;
2024-04-09 12:53:23 +02:00
Assert.That(
2022-09-06 16:08:19 +02:00
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
2023-08-31 12:20:06 +02:00
Substitute.For<ISmartDevice>(),
2022-09-06 16:08:19 +02:00
null /* viewService */,
2023-08-31 12:20:06 +02:00
Substitute.For<IBikesViewModel>(),
2024-04-09 12:53:23 +02:00
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(BookedClosed)));
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
// Verify handler for booked bike with state open.
bike = new BikeInfoMutable(
2023-08-31 12:20:06 +02:00
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
2024-04-09 12:53:23 +02:00
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>()),
2022-09-06 16:08:19 +02:00
"My Station Name");
bike.LockInfo.State = LockingState.Open;
2024-04-09 12:53:23 +02:00
Assert.That(
2022-09-06 16:08:19 +02:00
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
2023-08-31 12:20:06 +02:00
Substitute.For<ISmartDevice>(),
2022-09-06 16:08:19 +02:00
null /* viewService */,
2023-08-31 12:20:06 +02:00
Substitute.For<IBikesViewModel>(),
2024-04-09 12:53:23 +02:00
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(BookedOpen)));
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
// Verify handler for booked bike with state unknown.
bike = new BikeInfoMutable(
2023-08-31 12:20:06 +02:00
Substitute.For<IGeolocationService>(),
Substitute.For<ILocksService>(),
() => false /* not connected */,
(_) => Substitute.For<IConnector>(),
() => Substitute.For<IPollingUpdateTaskManager>(),
2024-04-09 12:53:23 +02:00
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>()),
2022-09-06 16:08:19 +02:00
"My Station Name");
2022-08-30 15:42:25 +02:00
2024-04-09 12:53:23 +02:00
Assert.That(
2022-09-06 16:08:19 +02:00
RequestHandlerFactory.Create(
bike,
() => false, // isConnectedDelegate
(connected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // LockService
null, // viewUpdateManager
2023-08-31 12:20:06 +02:00
Substitute.For<ISmartDevice>(),
2022-09-06 16:08:19 +02:00
null /* viewService */,
2023-08-31 12:20:06 +02:00
Substitute.For<IBikesViewModel>(),
2024-04-09 12:53:23 +02:00
Substitute.For<IUser>()).GetType(), Is.EqualTo(typeof(BookedDisconnected)));
2022-09-06 16:08:19 +02:00
}
}
2021-07-12 21:31:46 +02:00
}