2022-08-30 15:42:25 +02:00
|
|
|
|
using System;
|
2021-07-12 21:31:46 +02:00
|
|
|
|
using System.Collections.Generic;
|
2022-08-30 15:42:25 +02:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Rhino.Mocks;
|
2021-11-14 23:27:29 +01:00
|
|
|
|
using TestFramework.Model.Services.Geolocation;
|
|
|
|
|
using TestFramework.Services.BluetoothLock;
|
2022-08-30 15:42:25 +02:00
|
|
|
|
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
|
|
|
|
|
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
|
|
|
|
|
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
|
2021-07-12 21:31:46 +02:00
|
|
|
|
using TINK.Model.Device;
|
|
|
|
|
using TINK.Model.State;
|
|
|
|
|
using TINK.Model.User;
|
|
|
|
|
using TINK.ViewModel.Bikes;
|
|
|
|
|
using TINK.ViewModel.Bikes.Bike.BluetoothLock;
|
|
|
|
|
using TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
|
|
|
|
|
|
|
|
|
|
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Moved to TestShareeLib (.Net Core)
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class TestRequestHandlerFactory
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestCreate()
|
|
|
|
|
{
|
|
|
|
|
// Verify handler for disposable bike.
|
2022-01-04 18:59:16 +01:00
|
|
|
|
var bike = new BikeInfoMutable(
|
2022-08-30 15:42:25 +02:00
|
|
|
|
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", TINK.Model.Bikes.BikeInfoNS.BikeNS.LockModel.ILockIt), new Drive(), 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "12"),
|
2022-01-04 18:59:16 +01:00
|
|
|
|
"My Station Name");
|
2021-07-12 21:31:46 +02:00
|
|
|
|
Assert.AreEqual(InUseStateEnum.Disposable, bike.State.Value);
|
2022-04-10 17:38:34 +02:00
|
|
|
|
Assert.AreEqual(LockingState.UnknownDisconnected, bike.LockInfo.State);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
typeof(DisposableDisconnected),
|
|
|
|
|
RequestHandlerFactory.Create(
|
|
|
|
|
bike,
|
|
|
|
|
() => false, // isConnectedDelegate
|
|
|
|
|
(connected) => null, // connectorFactory
|
|
|
|
|
new GeolocationMock(), // geolocation
|
|
|
|
|
new LocksServiceMock(), // LockService
|
|
|
|
|
null, // viewUpdateManager
|
|
|
|
|
NSubstitute.Substitute.For<ISmartDevice>(),
|
|
|
|
|
null /* viewService */ ,
|
|
|
|
|
MockRepository.GenerateStub<IBikesViewModel>(),
|
|
|
|
|
MockRepository.GenerateStub<IUser>()).GetType());
|
|
|
|
|
|
|
|
|
|
// Verify handler for requested bike with state unknown.
|
2022-01-04 18:59:16 +01:00
|
|
|
|
bike = new BikeInfoMutable(
|
2022-08-30 15:42:25 +02:00
|
|
|
|
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new Drive(), 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-01-04 18:59:16 +01:00
|
|
|
|
"My Station Name");
|
2021-07-12 21:31:46 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
typeof(ReservedDisconnected),
|
|
|
|
|
RequestHandlerFactory.Create(
|
|
|
|
|
bike,
|
|
|
|
|
() => false, // isConnectedDelegate
|
|
|
|
|
(connected) => null, // connectorFactory
|
|
|
|
|
new GeolocationMock(), // geolocation
|
|
|
|
|
new LocksServiceMock(), // LockService
|
|
|
|
|
null, // viewUpdateManager
|
|
|
|
|
NSubstitute.Substitute.For<ISmartDevice>(),
|
|
|
|
|
null /* viewService */,
|
|
|
|
|
MockRepository.GenerateStub<IBikesViewModel>(),
|
|
|
|
|
MockRepository.GenerateStub<IUser>()).GetType());
|
|
|
|
|
|
|
|
|
|
// Verify handler for requested bike with state closed.
|
2022-01-04 18:59:16 +01:00
|
|
|
|
bike = new BikeInfoMutable(
|
2022-08-30 15:42:25 +02:00
|
|
|
|
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new Drive(), 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-01-04 18:59:16 +01:00
|
|
|
|
"My Station Name");
|
2021-07-12 21:31:46 +02:00
|
|
|
|
bike.LockInfo.State = LockingState.Closed;
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
typeof(ReservedClosed),
|
|
|
|
|
RequestHandlerFactory.Create(
|
|
|
|
|
bike,
|
|
|
|
|
() => false, // isConnectedDelegate
|
|
|
|
|
(connected) => null, // connectorFactory
|
|
|
|
|
new GeolocationMock(), // geolocation
|
|
|
|
|
new LocksServiceMock(), // LockService
|
|
|
|
|
null, // viewUpdateManager
|
|
|
|
|
NSubstitute.Substitute.For<ISmartDevice>(),
|
|
|
|
|
null /* viewService */,
|
|
|
|
|
MockRepository.GenerateStub<IBikesViewModel>(),
|
|
|
|
|
MockRepository.GenerateStub<IUser>()).GetType());
|
|
|
|
|
|
|
|
|
|
// Verify handler for requested bike with state open.
|
2022-01-04 18:59:16 +01:00
|
|
|
|
bike = new BikeInfoMutable(
|
2022-08-30 15:42:25 +02:00
|
|
|
|
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new Drive(), 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-01-04 18:59:16 +01:00
|
|
|
|
"My Station Name");
|
2021-07-12 21:31:46 +02:00
|
|
|
|
bike.LockInfo.State = LockingState.Open;
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
typeof(ReservedOpen),
|
|
|
|
|
RequestHandlerFactory.Create(
|
|
|
|
|
bike,
|
|
|
|
|
() => false, // isConnectedDelegate
|
|
|
|
|
(connected) => null, // connectorFactory
|
|
|
|
|
new GeolocationMock(), // geolocation
|
|
|
|
|
new LocksServiceMock(), // LockService
|
|
|
|
|
null, // viewUpdateManager
|
|
|
|
|
NSubstitute.Substitute.For<ISmartDevice>(),
|
|
|
|
|
null /* viewService */,
|
|
|
|
|
MockRepository.GenerateStub<IBikesViewModel>(),
|
|
|
|
|
MockRepository.GenerateStub<IUser>()).GetType());
|
|
|
|
|
|
|
|
|
|
// Verify handler for booked bike with state closed.
|
2022-01-04 18:59:16 +01:00
|
|
|
|
bike = new BikeInfoMutable(
|
2022-08-30 15:42:25 +02:00
|
|
|
|
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new Drive(), 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-01-04 18:59:16 +01:00
|
|
|
|
"My Station Name");
|
2021-07-12 21:31:46 +02:00
|
|
|
|
bike.LockInfo.State = LockingState.Closed;
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
typeof(BookedClosed),
|
|
|
|
|
RequestHandlerFactory.Create(
|
|
|
|
|
bike,
|
|
|
|
|
() => false, // isConnectedDelegate
|
|
|
|
|
(connected) => null, // connectorFactory
|
|
|
|
|
new GeolocationMock(), // geolocation
|
|
|
|
|
new LocksServiceMock(), // LockService
|
|
|
|
|
null, // viewUpdateManager
|
|
|
|
|
NSubstitute.Substitute.For<ISmartDevice>(),
|
|
|
|
|
null /* viewService */,
|
|
|
|
|
MockRepository.GenerateStub<IBikesViewModel>(),
|
|
|
|
|
MockRepository.GenerateStub<IUser>()).GetType());
|
|
|
|
|
|
|
|
|
|
// Verify handler for booked bike with state open.
|
2022-01-04 18:59:16 +01:00
|
|
|
|
bike = new BikeInfoMutable(
|
2022-08-30 15:42:25 +02:00
|
|
|
|
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new Drive(), 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-01-04 18:59:16 +01:00
|
|
|
|
"My Station Name");
|
2021-07-12 21:31:46 +02:00
|
|
|
|
bike.LockInfo.State = LockingState.Open;
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
typeof(BookedOpen),
|
|
|
|
|
RequestHandlerFactory.Create(
|
|
|
|
|
bike,
|
|
|
|
|
() => false, // isConnectedDelegate
|
|
|
|
|
(connected) => null, // connectorFactory
|
|
|
|
|
new GeolocationMock(), // geolocation
|
|
|
|
|
new LocksServiceMock(), // LockService
|
|
|
|
|
null, // viewUpdateManager
|
|
|
|
|
NSubstitute.Substitute.For<ISmartDevice>(),
|
|
|
|
|
null /* viewService */,
|
|
|
|
|
MockRepository.GenerateStub<IBikesViewModel>(),
|
|
|
|
|
MockRepository.GenerateStub<IUser>()).GetType());
|
|
|
|
|
|
|
|
|
|
// Verify handler for booked bike with state unknown.
|
2022-01-04 18:59:16 +01:00
|
|
|
|
bike = new BikeInfoMutable(
|
2022-08-30 15:42:25 +02:00
|
|
|
|
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new Drive(), 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-01-04 18:59:16 +01:00
|
|
|
|
"My Station Name");
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2021-07-12 21:31:46 +02:00
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
typeof(BookedDisconnected),
|
|
|
|
|
RequestHandlerFactory.Create(
|
2022-08-30 15:42:25 +02:00
|
|
|
|
bike,
|
|
|
|
|
() => false, // isConnectedDelegate
|
2021-07-12 21:31:46 +02:00
|
|
|
|
(connected) => null, // connectorFactory
|
|
|
|
|
new GeolocationMock(), // geolocation
|
|
|
|
|
new LocksServiceMock(), // LockService
|
|
|
|
|
null, // viewUpdateManager
|
|
|
|
|
NSubstitute.Substitute.For<ISmartDevice>(),
|
|
|
|
|
null /* viewService */,
|
|
|
|
|
MockRepository.GenerateStub<IBikesViewModel>(),
|
|
|
|
|
MockRepository.GenerateStub<IUser>()).GetType());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|