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

148 lines
4.3 KiB
C#
Raw Normal View History

2022-08-30 15:42:25 +02:00
using System;
using NSubstitute;
using NUnit.Framework;
2024-04-09 12:53:23 +02:00
using ShareeBike.Model.Bikes.BikeInfoNS.CopriLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.User;
using ShareeBike.View;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
using ShareeBike.ViewModel.Bikes.Bike.CopriLock;
using ShareeBike.ViewModel.Bikes.Bike.CopriLock.RequestHandler;
namespace SharedBusinessLogic.Tests.ViewModel.Bikes.Bike.CopriLock
2022-08-30 15:42:25 +02:00
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestReqeustHandlerFactory
{
[Test]
public void TestCreateDisposable()
{
var bike = Substitute.For<IBikeInfoMutable>();
var connector = Substitute.For<IConnector>();
var command = Substitute.For<ICommand>();
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
var smartDevice = Substitute.For<ISmartDevice>();
var viewService = Substitute.For<IViewService>();
var bikesViewModel = Substitute.For<IBikesViewModel>();
var activeUser = Substitute.For<IUser>();
2024-04-09 12:53:23 +02:00
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.Disposable);
2022-09-06 16:08:19 +02:00
var requestHandler = RequestHandlerFactory.Create(
bike,
() => true /*isConnectedDelegate*/,
(isconnected) => connector,
() => pollingManager,
smartDevice,
viewService,
bikesViewModel,
activeUser);
Assert.That(
requestHandler.GetType(),
Is.EqualTo(typeof(DisposableClosed)));
}
[Test]
public void TestCreateReserved()
{
var bike = Substitute.For<IBikeInfoMutable>();
var connector = Substitute.For<IConnector>();
var command = Substitute.For<ICommand>();
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
var smartDevice = Substitute.For<ISmartDevice>();
var viewService = Substitute.For<IViewService>();
var bikesViewModel = Substitute.For<IBikesViewModel>();
var activeUser = Substitute.For<IUser>();
2024-04-09 12:53:23 +02:00
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.Reserved);
2022-09-06 16:08:19 +02:00
var requestHandler = RequestHandlerFactory.Create(
bike,
() => true /*isConnectedDelegate*/,
(isconnected) => connector,
() => pollingManager,
smartDevice,
viewService,
bikesViewModel,
activeUser);
Assert.That(
requestHandler.GetType(),
Is.EqualTo(typeof(ReservedClosed)));
}
[Test]
public void TestCreateBooked()
{
var bike = Substitute.For<IBikeInfoMutable>();
var connector = Substitute.For<IConnector>();
var command = Substitute.For<ICommand>();
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
var smartDevice = Substitute.For<ISmartDevice>();
var viewService = Substitute.For<IViewService>();
var bikesViewModel = Substitute.For<IBikesViewModel>();
var activeUser = Substitute.For<IUser>();
2024-04-09 12:53:23 +02:00
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.Booked);
2022-09-06 16:08:19 +02:00
foreach (LockingState state in Enum.GetValues(typeof(LockingState)))
{
bike.LockInfo.State.Returns(state);
var requestHandler = RequestHandlerFactory.Create(
bike,
() => true /*isConnectedDelegate*/,
(isconnected) => connector,
() => pollingManager,
smartDevice,
viewService,
bikesViewModel,
activeUser);
Assert.That(
requestHandler.GetType(),
Is.EqualTo(state == LockingState.Closed
? typeof(BookedClosed)
: typeof(BookedOpen)));
}
}
[Test]
public void TestCreateFeedbackPending()
{
var bike = Substitute.For<IBikeInfoMutable>();
var connector = Substitute.For<IConnector>();
var command = Substitute.For<ICommand>();
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
var smartDevice = Substitute.For<ISmartDevice>();
var viewService = Substitute.For<IViewService>();
var bikesViewModel = Substitute.For<IBikesViewModel>();
var activeUser = Substitute.For<IUser>();
2024-04-09 12:53:23 +02:00
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.FeedbackPending);
2022-09-06 16:08:19 +02:00
foreach (LockingState state in Enum.GetValues(typeof(LockingState)))
{
bike.LockInfo.State.Returns(state);
var requestHandler = RequestHandlerFactory.Create(
bike,
() => true /*isConnectedDelegate*/,
(isconnected) => connector,
() => pollingManager,
smartDevice,
viewService,
bikesViewModel,
activeUser);
Assert.That(
requestHandler.GetType(),
Is.EqualTo(typeof(FeedbackPending)));
}
}
}
2022-08-30 15:42:25 +02:00
}