using System; using System.Collections.Generic; using NUnit.Framework; using SharedBusinessLogic.Tests.Framework.Model.User.Account; using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS; using ShareeBike.Model.State; using ShareeBike.Model.User; using ShareeBike.Model.User.Account; using ShareeBike.Repository; using ShareeBike.ViewModel.Bikes.Bike; using static ShareeBike.Repository.CopriCallsMemory; namespace UITest.Fixtures.ViewModel { public class TestBikeViewModel { private class BikeInfoMutable : ShareeBike.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable { public BikeInfoMutable( string id, LockModel lockModel, bool pisDemo = false, IEnumerable group = null, WheelType? wheelType = null, TypeOfBike? typeOfBike = null, AaRideType? aaRideType = null, string description = null, string stationId = null, string stationName = null, Uri operatorUri = null, Func dateTimeProvider = null, IStateInfo stateInfo = null) : base( new Bike(id, lockModel, wheelType, typeOfBike, aaRideType, description), new ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.DriveMutable(), ShareeBike.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, pisDemo, group, stationId, stationName, operatorUri, null, dateTimeProvider, stateInfo) { } } /// /// Tests base class functionality by using child. /// public static BikeViewModelBase TestStateText_LoggedIn_Reserved(Func p_oFactory) { var l_oBike = new BikeInfoMutable( "2", LockModel.ILockIt, false, new List { "ShareeBike" }, WheelType.Trike, TypeOfBike.Cargo, AaRideType.NoAaRide, "Test description", "3", "Radstation", null, () => new DateTime(1980, 1, 1)); // Now time stamp // Update state from Copri. l_oBike.State.Load( InUseStateEnum.Reserved, // Copri acknowledges state reserved. new DateTime(1980, 1, 1), // Date when bike was booked. TimeSpan.FromMinutes(15), "ragu@gnu-systems.de"); // Owner from Copri. var l_oStoreMock = new StoreMock(new Account("ragu@gnu-systems.de", "123456789" /* password */, false, "987654321" /* session cookie */, new List { "ShareeBike" })); var l_oUser = new User( l_oStoreMock, l_oStoreMock.Load().Result, "123456789"); // Verify prerequisites Assert.That(l_oBike.State.Value, Is.EqualTo(InUseStateEnum.Reserved)); Assert.That(l_oUser.IsLoggedIn, Is.True); Assert.That(l_oUser.Mail, Is.EqualTo(l_oBike.State.MailAddress)); // Do not update from Copri var l_oViewModel = p_oFactory(l_oBike, l_oUser); return l_oViewModel; } /// /// Tests base class functionality by using child. /// public static BikeViewModelBase TestStateText_LoggedIn_ReservedWithCopriConnect(Func p_oFactory) { var l_oBike = new BikeInfoMutable( "2", LockModel.ILockIt, false, new List { "ShareeBike" }, WheelType.Trike, TypeOfBike.Cargo, AaRideType.NoAaRide, "Test description", "3", "Radstation", null, () => (new DateTime(1980, 1, 1)).Add(new TimeSpan(0, 8, 0))); // Update state from Copri. l_oBike.State.Load( InUseStateEnum.Reserved, // Copri acknowledges state reserved. new DateTime(1980, 1, 1), TimeSpan.FromMinutes(15), "ragu@gnu-systems.de", // Owner from Copri. "4asdfA"); // Reservation code from Copri var l_oStoreMock = new StoreMock(new Account("ragu@gnu-systems.de", "123456789" /* password */, false, "987654321" /* session cookie */, new List { "ShareeBike" })); var l_oUser = new User( l_oStoreMock, // Mocks account store functionality. l_oStoreMock.Load().Result, "123456789"); // Verify prerequisites Assert.That(l_oBike.State.Value, Is.EqualTo(InUseStateEnum.Reserved)); Assert.That(l_oUser.IsLoggedIn, Is.True); Assert.That(l_oUser.Mail, Is.EqualTo(l_oBike.State.MailAddress)); var l_oViewModel = p_oFactory(l_oBike, l_oUser); // Bikes collection mock. return l_oViewModel; } /// /// Tests base class functionality by using child. /// public static BikeViewModelBase TestStateText_LoggedIn_Booked(Func p_oFactory) { var l_oBike = new BikeInfoMutable("2", LockModel.ILockIt, false, new List { "ShareeBike" }, WheelType.Two, TypeOfBike.Cargo, AaRideType.NoAaRide, "Test description", "3"); // Update from Copri. l_oBike.State.Load( InUseStateEnum.Booked, new DateTime(2017, 10, 24, 21, 49, 3), TimeSpan.FromMinutes(15), "ragu@gnu-systems.de", "4asdfA"); var l_oCopriServer = new CopriCallsMemory("MyMerchId", SampleSets.Set1, 1); var l_oStoreMock = new StoreMock(new Account("ragu@gnu-systems.de", "123456789" /* password */, false, "987654321" /* session cookie */, new List { "ShareeBike" })); var l_oUser = new User( l_oStoreMock, l_oStoreMock.Load().Result, "123456789"); // Device id // Verify prerequisites Assert.That(l_oBike.State.Value, Is.EqualTo(InUseStateEnum.Booked)); Assert.That(l_oUser.IsLoggedIn, Is.True); Assert.That(l_oUser.Mail, Is.EqualTo(l_oBike.State.MailAddress)); var l_oViewModel = p_oFactory(l_oBike, l_oUser); return l_oViewModel; } } }