using System; using NSubstitute; using NUnit.Framework; 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; namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.ViewModel { [TestFixture] public class TestBikeViewModelFactory { private class BikeInfoMutableUnsupported : BikeInfoMutable { /// Constructs a bike object from source. 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) { } } [Test] public void TestCreateBluetoothLock() { Assert.That( BikeViewModelFactory.Create( () => false, // Is connected delegate, (isconnected) => null, // connectorFactory new GeolocationMock(), // geolocation new LocksServiceMock(), // lock service (index) => { }, // bikeRemoveDelegate null, // viewUpdateManager Substitute.For(), null, // viewService new ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfoMutable( Substitute.For(), Substitute.For(), () => false /* not connected */, (_) => Substitute.For(), () => Substitute.For(), 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"), Substitute.For(), // user null /*ViewContext*/, Substitute.For(), Substitute.For(), url => { }).GetType(), Is.EqualTo(typeof(ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel))); // stateInfoProvider } [Test] public void TestCreateCopri() { 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(), null, // viewService 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"), NSubstitute.Substitute.For(), // user new ViewContext(PageContext.BikesAtStation, "FR1012"), // Context does not matter for this test. NSubstitute.Substitute.For(), NSubstitute.Substitute.For(), url => { }).GetType(), Is.EqualTo(typeof(ShareeBike.ViewModel.Bikes.Bike.CopriLock.BikeViewModel))); // stateInfoProvider } [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(), null, // viewService 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"), NSubstitute.Substitute.For(), // user new ViewContext(PageContext.BikesAtStation, "FR1012"), // Context does not matter for this test. NSubstitute.Substitute.For(), NSubstitute.Substitute.For(), url => { }), Is.Null); } } }