sharee.bike-App/TestShareeLib/Model/TestTinkAppSelectStation.cs

107 lines
4.6 KiB
C#
Raw Normal View History

2022-10-17 18:45:38 +02:00
using System;
2021-07-12 21:31:46 +02:00
using System.Collections.Generic;
2023-04-05 15:02:10 +02:00
using System.Threading.Tasks;
2021-07-12 21:31:46 +02:00
using NSubstitute;
2022-08-30 15:42:25 +02:00
using NUnit.Framework;
using Plugin.BLE.Abstractions.Contracts;
2021-11-14 23:27:29 +01:00
using TestFramework.Model.Device;
using TestFramework.Model.Services.Geolocation;
2022-08-30 15:42:25 +02:00
using TestFramework.Model.User.Account;
2021-11-14 23:27:29 +01:00
using TestFramework.Services.BluetoothLock;
2022-08-30 15:42:25 +02:00
using TINK.Model;
2023-04-05 15:02:10 +02:00
using TINK.Model.Bikes;
2022-08-30 15:42:25 +02:00
using TINK.Model.Connector;
2022-10-17 18:45:38 +02:00
using TINK.Model.Settings;
2023-04-19 12:14:14 +02:00
using TINK.Model.Stations.StationNS;
2023-04-05 15:02:10 +02:00
using TINK.Model.User;
2022-08-30 15:42:25 +02:00
using TINK.Repository;
using TINK.Services;
using TINK.Services.Geolocation;
2022-04-10 17:38:34 +02:00
using TINK.Services.Permissions;
2022-08-30 15:42:25 +02:00
using TINK.ViewModel.Settings;
using static TINK.Repository.CopriCallsMemory;
2021-07-12 21:31:46 +02:00
namespace TestTINKLib.Fixtures.UseCases.SelectStation
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestTinkApp
{
2023-04-05 15:02:10 +02:00
/// <summary>
/// Get all bikes at a given station from copri.
/// </summary>
private static async Task<BikeCollectionMutable> GetBikesAtStation(
User user,
TINK.Model.Connector.IConnector connector,
IEnumerable<IStation> stations,
string selectedStationId)
{
var l_oBikesAtStation = new BikeCollectionMutable();
var l_oBikesAvailable = (await connector.Query.GetBikesAsync()).Response;
l_oBikesAtStation.Update(l_oBikesAvailable.GetAtStation(selectedStationId), stations);
return l_oBikesAtStation;
}
2022-09-06 16:08:19 +02:00
[Test]
public void TestBikesAtStation_AccountStoreMock_NoUser_CopriMock_Set2()
{
const string MERCH_ID = "MyMerchId";
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
var l_oConnector = new ConnectorCache(
new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)),
null /*UI language */,
string.Empty,
string.Empty,
2023-02-22 14:03:35 +01:00
server: new CopriCallsMemory(MERCH_ID, SampleSets.Set2, 1));
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
var l_oTinkApp = new TinkApp(
2022-10-17 18:45:38 +02:00
new Settings(
2022-09-06 16:08:19 +02:00
new TINK.ViewModel.Map.GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On } }),
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
2022-10-17 18:45:38 +02:00
new StartupSettings(),
2022-09-06 16:08:19 +02:00
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
Serilog.Events.LogEventLevel.Error,
activeLockService: typeof(LocksServiceMock).FullName,
activeGeolocationService: typeof(GeolocationMock).FullName),
new StoreMock(),
isConnectedFunc: () => true,
2023-02-22 14:03:35 +01:00
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)),
2022-09-06 16:08:19 +02:00
merchantId: MERCH_ID,
bluetoothService: Substitute.For<IBluetoothLE>(),
locationPermissionsService: Substitute.For<ILocationPermission>(),
2023-04-05 15:02:10 +02:00
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocationService>>(),
2022-09-06 16:08:19 +02:00
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
2021-07-12 21:31:46 +02:00
2023-04-05 15:02:10 +02:00
Assert.AreEqual(0, GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.Count);
2021-07-12 21:31:46 +02:00
2023-04-19 12:14:14 +02:00
l_oTinkApp.SelectedStation = new TINK.Model.Stations.StationNS.Station("5", new List<string>(), null);
2023-04-05 15:02:10 +02:00
Assert.AreEqual(3, GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.Count);
Assert.AreEqual("25", GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.GetById("25").Id);
Assert.AreEqual("11", GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.GetById("11").Id);
Assert.AreEqual("2", GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.GetById("2").Id);
2021-07-12 21:31:46 +02:00
2023-04-19 12:14:14 +02:00
l_oTinkApp.SelectedStation = new TINK.Model.Stations.StationNS.Station("10", new List<string>(), null);
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.AreEqual(
1,
2023-04-05 15:02:10 +02:00
GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.Count);
2021-07-12 21:31:46 +02:00
2023-04-05 15:02:10 +02:00
Assert.AreEqual("18", GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.GetById("18").Id);
2021-07-12 21:31:46 +02:00
2023-04-19 12:14:14 +02:00
l_oTinkApp.SelectedStation = new TINK.Model.Stations.StationNS.Station("91345", new List<string>(), null);
2021-07-12 21:31:46 +02:00
2023-04-05 15:02:10 +02:00
Assert.AreEqual(0, GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.Count);
2022-09-06 16:08:19 +02:00
}
}
2022-10-17 18:45:38 +02:00
}