using System; using System.Collections.Generic; using System.Threading.Tasks; using NSubstitute; using NUnit.Framework; using Plugin.BLE.Abstractions.Contracts; using SharedBusinessLogic.Tests.Framework.Model.Device; using SharedBusinessLogic.Tests.Framework.Model.Services.Geolocation; using SharedBusinessLogic.Tests.Framework.Model.User.Account; using SharedBusinessLogic.Tests.Framework.Services.BluetoothLock; using ShareeBike.Model; using ShareeBike.Model.Bikes; using ShareeBike.Model.Connector; using ShareeBike.Model.Settings; using ShareeBike.Model.Stations.StationNS; using ShareeBike.Model.User; using ShareeBike.Repository; using ShareeBike.Services; using ShareeBike.Services.BluetoothLock; using ShareeBike.Services.Geolocation; using ShareeBike.Services.Permissions; using ShareeBike.ViewModel; using ShareeBike.ViewModel.Settings; using static ShareeBike.Repository.CopriCallsMemory; namespace SharedBusinessLogic.Tests.Fixtures.UseCases.SelectStation { [TestFixture] public class TestShareeBikeApp { /// /// Get all bikes at a given station from copri. /// private static async Task GetBikesAtStation( User user, ShareeBike.Model.Connector.IConnector connector, IEnumerable stations, string selectedStationId) { var l_oBikesAtStation = new BikeCollectionMutable( Substitute.For(), Substitute.For(), () => false /* not connected */, (_) => Substitute.For(), () => Substitute.For()); var l_oBikesAvailable = (await connector.Query.GetBikesAsync()).Response; l_oBikesAtStation.Update(l_oBikesAvailable.GetAtStation(selectedStationId), stations); return l_oBikesAtStation; } [Test] public void TestBikesAtStation_AccountStoreMock_NoUser_CopriMock_Set2() { const string MERCH_ID = "MyMerchId"; var l_oConnector = new ConnectorCache( new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)), null /*UI language */, string.Empty, string.Empty, server: new CopriCallsMemory(MERCH_ID, SampleSets.Set2, 1)); var l_oShareeBikeApp = new ShareeBikeApp( new Settings( new ShareeBike.ViewModel.Map.GroupFilterMapPage(new Dictionary { { "ShareeBike", FilterState.On } }), new GroupFilterSettings(new Dictionary { { "ShareeBike", FilterState.On }, { "Citybike", FilterState.On } }), new StartupSettings(), new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"), new ShareeBike.Settings.PollingParameters(new TimeSpan(10000), true), Serilog.Events.LogEventLevel.Error, activeLockService: typeof(LocksServiceMock).FullName, activeGeolocationService: typeof(GeolocationMock).FullName), new StoreMock(), isConnectedFunc: () => true, connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory(MERCH_ID, SampleSets.Set2, 1)), merchantId: MERCH_ID, bluetoothService: Substitute.For(), locationPermissionsService: Substitute.For(), locationServicesContainer: Substitute.For>(), locksService: new LocksServiceMock(), // Cipher device: new DeviceMock(), specialFolder: new SpecialFolderMock(), cipher: null, theme: null, currentVersion: new Version(3, 2, 0, 115), lastVersion: new Version(3, 0, 173)); // Current app version. Must be larger or equal 3.0.173 to Assert.That(GetBikesAtStation(l_oShareeBikeApp.ActiveUser, l_oConnector, l_oShareeBikeApp.Stations, l_oShareeBikeApp.SelectedStation.Id).Result.Count, Is.EqualTo(0)); l_oShareeBikeApp.SelectedStation = new ShareeBike.Model.Stations.StationNS.Station("5", new List(), null); Assert.That(GetBikesAtStation(l_oShareeBikeApp.ActiveUser, l_oConnector, l_oShareeBikeApp.Stations, l_oShareeBikeApp.SelectedStation.Id).Result.Count, Is.EqualTo(3)); Assert.That(GetBikesAtStation(l_oShareeBikeApp.ActiveUser, l_oConnector, l_oShareeBikeApp.Stations, l_oShareeBikeApp.SelectedStation.Id).Result.GetById("25").Id, Is.EqualTo("25")); Assert.That(GetBikesAtStation(l_oShareeBikeApp.ActiveUser, l_oConnector, l_oShareeBikeApp.Stations, l_oShareeBikeApp.SelectedStation.Id).Result.GetById("11").Id, Is.EqualTo("11")); Assert.That(GetBikesAtStation(l_oShareeBikeApp.ActiveUser, l_oConnector, l_oShareeBikeApp.Stations, l_oShareeBikeApp.SelectedStation.Id).Result.GetById("2").Id, Is.EqualTo("2")); l_oShareeBikeApp.SelectedStation = new ShareeBike.Model.Stations.StationNS.Station("10", new List(), null); Assert.That( GetBikesAtStation(l_oShareeBikeApp.ActiveUser, l_oConnector, l_oShareeBikeApp.Stations, l_oShareeBikeApp.SelectedStation.Id).Result.Count, Is.EqualTo(1)); Assert.That(GetBikesAtStation(l_oShareeBikeApp.ActiveUser, l_oConnector, l_oShareeBikeApp.Stations, l_oShareeBikeApp.SelectedStation.Id).Result.GetById("18").Id, Is.EqualTo("18")); l_oShareeBikeApp.SelectedStation = new ShareeBike.Model.Stations.StationNS.Station("91345", new List(), null); Assert.That(GetBikesAtStation(l_oShareeBikeApp.ActiveUser, l_oConnector, l_oShareeBikeApp.Stations, l_oShareeBikeApp.SelectedStation.Id).Result.Count, Is.EqualTo(0)); } } }