sharee.bike-App/SharedBusinessLogic.Tests/ViewModel/Bikes/Bike/CopriLock/TestReqeustHandlerFactory.cs
2024-04-09 12:53:23 +02:00

147 lines
4.3 KiB
C#

using System;
using NSubstitute;
using NUnit.Framework;
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
{
[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>();
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.Disposable);
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>();
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.Reserved);
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>();
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.Booked);
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>();
bike.State.Value.Returns(ShareeBike.Model.State.InUseStateEnum.FeedbackPending);
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)));
}
}
}
}