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

115 lines
4.8 KiB
C#
Raw Normal View History

2023-01-18 14:22:51 +01:00
using System;
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.BC;
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.User;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.Services.Geolocation;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike;
2021-07-12 21:31:46 +02:00
2024-04-09 12:53:23 +02:00
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.ViewModel
2021-07-12 21:31:46 +02:00
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestBikeViewModelFactory
{
2023-04-19 12:14:14 +02:00
private class BikeInfoMutableUnsupported : BikeInfoMutable
{
/// <summary> Constructs a bike object from source. </summary>
public BikeInfoMutableUnsupported(IBikeInfo bike, string stationName) : base(
bike != null
? bike.Bike
: throw new ArgumentNullException(nameof(bike)),
bike.Drive,
bike.DataSource,
bike.IsDemo,
bike.Group,
bike.StationId,
stationName,
bike.OperatorUri,
bike.TariffDescription,
null /* date time provider */,
bike.State)
{
}
}
2022-09-06 16:08:19 +02:00
[Test]
public void TestCreateBluetoothLock()
{
2024-04-09 12:53:23 +02:00
Assert.That(
2022-09-06 16:08:19 +02:00
BikeViewModelFactory.Create(
() => false, // Is connected delegate,
(isconnected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // lock service
(index) => { }, // bikeRemoveDelegate
null, // viewUpdateManager
2023-08-31 12:20:06 +02:00
Substitute.For<ISmartDevice>(),
2022-09-06 16:08:19 +02:00
null, // viewService
2024-04-09 12:53:23 +02:00
new ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.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 ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo(new ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Bike("42", LockModel.ILockIt), new DriveMutable(), DataSource.Copri, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "42"), "My Station Name"),
2023-08-31 12:20:06 +02:00
Substitute.For<IUser>(), // user
null /*ViewContext*/,
Substitute.For<IInUseStateInfoProvider>(),
Substitute.For<IBikesViewModel>(),
2024-04-09 12:53:23 +02:00
url => { }).GetType(), Is.EqualTo(typeof(ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel))); // stateInfoProvider
2022-09-06 16:08:19 +02:00
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestCreateCopri()
{
2024-04-09 12:53:23 +02:00
Assert.That(
2022-09-06 16:08:19 +02:00
BikeViewModelFactory.Create(
() => false, // Is connected delegate,
(isconnected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // lock service
(index) => { }, // bikeRemoveDelegate
null, // viewUpdateManager
NSubstitute.Substitute.For<ISmartDevice>(),
null, // viewService
2024-04-09 12:53:23 +02:00
new ShareeBike.Model.Bikes.BikeInfoNS.CopriLock.BikeInfoMutable(new ShareeBike.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(new ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Bike("42", LockModel.ILockIt), new DriveMutable(), ShareeBike.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, "17", new ShareeBike.Model.Bikes.BikeInfoNS.CopriLock.LockInfo.Builder { State = ShareeBike.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Closed }.Build()), "My Station Name"),
2023-03-08 13:18:54 +01:00
NSubstitute.Substitute.For<IUser>(), // user
2023-07-04 11:06:38 +02:00
new ViewContext(PageContext.BikesAtStation, "FR1012"), // Context does not matter for this test.
2023-03-08 13:18:54 +01:00
NSubstitute.Substitute.For<IInUseStateInfoProvider>(),
NSubstitute.Substitute.For<IBikesViewModel>(),
2024-04-09 12:53:23 +02:00
url => { }).GetType(), Is.EqualTo(typeof(ShareeBike.ViewModel.Bikes.Bike.CopriLock.BikeViewModel))); // stateInfoProvider
2022-09-06 16:08:19 +02:00
}
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestCreateUnsupported()
{
Assert.That(
BikeViewModelFactory.Create(
() => false, // Is connected delegate,
(isconnected) => null, // connectorFactory
new GeolocationMock(), // geolocation
new LocksServiceMock(), // lock service
(index) => { }, // bikeRemoveDelegate
null, // viewUpdateManager
NSubstitute.Substitute.For<ISmartDevice>(),
null, // viewService
2024-04-09 12:53:23 +02:00
new BikeInfoMutableUnsupported(new ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo(new ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Bike("42", ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.LockModel.ILockIt), new DriveMutable(), DataSource.Copri, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "42"), "My Station Name"),
2023-03-08 13:18:54 +01:00
NSubstitute.Substitute.For<IUser>(), // user
2023-07-04 11:06:38 +02:00
new ViewContext(PageContext.BikesAtStation, "FR1012"), // Context does not matter for this test.
2023-03-08 13:18:54 +01:00
NSubstitute.Substitute.For<IInUseStateInfoProvider>(),
NSubstitute.Substitute.For<IBikesViewModel>(),
2022-09-06 16:08:19 +02:00
url => { }),
Is.Null);
}
}
2021-07-12 21:31:46 +02:00
}