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(); var connector = Substitute.For(); var command = Substitute.For(); var pollingManager = Substitute.For(); var smartDevice = Substitute.For(); var viewService = Substitute.For(); var bikesViewModel = Substitute.For(); var activeUser = Substitute.For(); 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(); var connector = Substitute.For(); var command = Substitute.For(); var pollingManager = Substitute.For(); var smartDevice = Substitute.For(); var viewService = Substitute.For(); var bikesViewModel = Substitute.For(); var activeUser = Substitute.For(); 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(); var connector = Substitute.For(); var command = Substitute.For(); var pollingManager = Substitute.For(); var smartDevice = Substitute.For(); var viewService = Substitute.For(); var bikesViewModel = Substitute.For(); var activeUser = Substitute.For(); 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(); var connector = Substitute.For(); var command = Substitute.For(); var pollingManager = Substitute.For(); var smartDevice = Substitute.For(); var viewService = Substitute.For(); var bikesViewModel = Substitute.For(); var activeUser = Substitute.For(); 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))); } } } }