mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 18:46:30 +01:00
194 lines
9 KiB
C#
194 lines
9 KiB
C#
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)));
|
|
}
|
|
}
|
|
}
|