sharee.bike-App/TestShareeLib/ViewModel/Bikes/Bike/CopriLock/TestReqeustHandlerFactory.cs
Anja Müller-Meißner 0468955d49 Version 3.0.338
2022-09-08 09:55:14 +02:00

147 lines
4.2 KiB
C#

using System;
using NSubstitute;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.CopriLock;
using TINK.Model.Connector;
using TINK.Model.Device;
using TINK.Model.User;
using TINK.View;
using TINK.ViewModel;
using TINK.ViewModel.Bikes;
using TINK.ViewModel.Bikes.Bike.CopriLock;
using TINK.ViewModel.Bikes.Bike.CopriLock.RequestHandler;
namespace TestShareeLib.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(TINK.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(TINK.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(TINK.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(TINK.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)));
}
}
}
}