sharee.bike-App/TestShareeLib/ViewModel/Account/TestAccountPageViewModel.cs

265 lines
13 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;
using System.Threading.Tasks;
2022-08-30 15:42:25 +02:00
using NSubstitute;
using NUnit.Framework;
using Plugin.BLE.Abstractions.Contracts;
using TestFramework.Model.Device;
using TestFramework.Model.Services.Geolocation;
using TestFramework.Model.User.Account;
using TestFramework.Repository;
using TestFramework.Services.BluetoothLock;
2021-07-12 21:31:46 +02:00
using TINK.Model;
using TINK.Model.Connector;
using TINK.Model.Services.CopriApi;
2022-10-17 18:45:38 +02:00
using TINK.Model.Settings;
2021-07-12 21:31:46 +02:00
using TINK.Repository;
2022-08-30 15:42:25 +02:00
using TINK.Repository.Exception;
2021-07-12 21:31:46 +02:00
using TINK.Services;
2022-04-10 17:38:34 +02:00
using TINK.Services.Geolocation;
using TINK.Services.Permissions;
2022-08-30 15:42:25 +02:00
using TINK.View;
using TINK.ViewModel.Account;
using TINK.ViewModel.Map;
using TINK.ViewModel.Settings;
using static TINK.Repository.CopriCallsMemory;
2021-07-12 21:31:46 +02:00
namespace TestTINKLib.Fixtures.ObjectTests.Account
{
2022-09-06 16:08:19 +02:00
public class TestAccountPageViewModel
{
[Test]
public void TestConstruct_NotLoggedIn()
{
const string MERCH_ID = "MyMerchId";
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
var tinkApp = new TinkApp(
new TINK.Model.Settings.Settings(
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
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, sessionCookie)),
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,
postAction: (d, obj) => d(obj),
currentVersion: new Version(3, 2, 0, 115), // Current app version
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion: null); // Whats new page was never shown.
2021-07-12 21:31:46 +02:00
2023-04-05 15:02:10 +02:00
var viewService = Substitute.For<IViewService>();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
var settingsPageViewModel = new AccountPageViewModel(
tinkApp,
(uri) => { },
viewService);
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.AreEqual("No user logged in.", settingsPageViewModel.LoggedInInfo);
Assert.IsFalse(settingsPageViewModel.IsBookingStateInfoVisible, "No user logged in.");
Assert.AreEqual(string.Empty, settingsPageViewModel.BookingStateInfo);
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public async Task TestConstruct()
{
const string MERCH_ID = "MyMerchId";
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
var tinkApp = new TinkApp(
new TINK.Model.Settings.Settings(
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
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(new TINK.Model.User.Account.Account("a@b", "123456789", false, "UnknownCookie", new List<string> { "TINK" })),
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, sessionCookie)),
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,
postAction: (d, obj) => d(obj),
currentVersion: new Version(3, 2, 0, 115), // Current app version
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion: null); // Whats new page was never shown.
2021-07-12 21:31:46 +02:00
2023-04-05 15:02:10 +02:00
var viewService = Substitute.For<IViewService>();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
var settingsPageViewModel = new AccountPageViewModel(
tinkApp,
(uri) => { },
viewService);
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
await settingsPageViewModel.OnAppearing();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.AreEqual("Logged in as a@b.", settingsPageViewModel.LoggedInInfo);
Assert.IsFalse(settingsPageViewModel.IsBookingStateInfoVisible, "A user is logged but no bikes requested/ booked.");
Assert.AreEqual(string.Empty, settingsPageViewModel.BookingStateInfo);
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public async Task TestConstruct_TwoBikes()
{
var tinkApp = new TinkApp(
new TINK.Model.Settings.Settings(
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
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(new TINK.Model.User.Account.Account("a@b", "123456789", false, "6103_112e96b36ba33de245943c5ffaf369cd_", new List<string> { "TINK" })),
isConnectedFunc: () => true,
2023-02-22 14:03:35 +01:00
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory001(sessionCookie)),
2022-09-06 16:08:19 +02:00
merchantId: "MyMerchId",
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,
postAction: (d, obj) => d(obj),
currentVersion: new Version(3, 2, 0, 115), // Current app version
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion: null); // Whats new page was never shown.
2021-07-12 21:31:46 +02:00
2023-04-05 15:02:10 +02:00
var viewService = Substitute.For<IViewService>();
2022-09-06 16:08:19 +02:00
var settingsPageViewModel = new AccountPageViewModel(
tinkApp,
(uri) => { },
viewService);
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
await settingsPageViewModel.OnAppearing();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.AreEqual("Logged in as a@b.", settingsPageViewModel.LoggedInInfo);
Assert.IsTrue(settingsPageViewModel.IsBookingStateInfoVisible, "A user is logged but no bikes requested/ booked.");
2023-08-31 12:20:06 +02:00
Assert.AreEqual("Currently 2 bikes reserved/ booked.", settingsPageViewModel.BookingStateInfo);
2022-09-06 16:08:19 +02:00
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public async Task TestConstruct_TwoBikes_Offline()
{
var tinkApp = new TinkApp(
new TINK.Model.Settings.Settings(
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
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(new TINK.Model.User.Account.Account("a@b", "123456789", false, "6103_112e96b36ba33de245943c5ffaf369cd_", new List<string> { "TINK" })),
isConnectedFunc: () => false,
2023-02-22 14:03:35 +01:00
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory001(sessionCookie)),
2022-09-06 16:08:19 +02:00
merchantId: "MyMerchId",
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, // Offline
theme: null,
postAction: (d, obj) => d(obj),
currentVersion: new Version(3, 2, 0, 115), // Current app version
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion: null); // Whats new page was never shown.
2021-07-12 21:31:46 +02:00
2023-04-05 15:02:10 +02:00
var viewService = Substitute.For<IViewService>();
2022-09-06 16:08:19 +02:00
var settingsPageViewModel = new AccountPageViewModel(
tinkApp,
(uri) => { },
viewService);
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
await settingsPageViewModel.OnAppearing();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.AreEqual("Logged in as a@b.", settingsPageViewModel.LoggedInInfo);
Assert.IsTrue(settingsPageViewModel.IsBookingStateInfoVisible, "A user is logged but no bikes requested/ booked.");
2023-08-31 12:20:06 +02:00
Assert.AreEqual("Currently 2 bikes reserved/ booked. Connectivity: Offline.", settingsPageViewModel.BookingStateInfo);
2022-09-06 16:08:19 +02:00
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public async Task TestConstruct_TwoBikes_WebConnectCommunicationError()
{
var tinkApp = new TinkApp(
new TINK.Model.Settings.Settings(
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
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(new TINK.Model.User.Account.Account("a@b", "123456789", false, "6103_112e96b36ba33de245943c5ffaf369cd_", new List<string> { "TINK" })),
isConnectedFunc: () => false,
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new TINK.Model.Connector.Connector(
uri,
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
sessionCookie,
mail,
server: new CopriProviderHttps(
uri,
TinkApp.MerchantId,
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
sessionCookie: sessionCookie,
cacheServer: new CopriCallsCacheMemory001(sessionCookie: sessionCookie),
2023-08-31 12:20:06 +02:00
httpsServer: new ExceptionServer((msg) => new WebConnectFailureException(msg, new Exception("Source exception."))))),
2022-09-06 16:08:19 +02:00
merchantId: "MyMerchId",
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, // Offline
theme: null,
postAction: (d, obj) => d(obj),
currentVersion: new Version(3, 2, 0, 115), // Current app version
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion: null); // Whats new page was never shown.
2021-07-12 21:31:46 +02:00
2023-04-05 15:02:10 +02:00
var viewService = Substitute.For<IViewService>();
2022-09-06 16:08:19 +02:00
var settingsPageViewModel = new AccountPageViewModel(
tinkApp,
(uri) => { },
viewService);
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
await settingsPageViewModel.OnAppearing();
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.AreEqual("Logged in as a@b.", settingsPageViewModel.LoggedInInfo); // CopriCallsCacheMemory(SampleSets.Set2,
Assert.IsTrue(settingsPageViewModel.IsBookingStateInfoVisible, "A user is logged but no bikes requested/ booked.");
2023-08-31 12:20:06 +02:00
Assert.AreEqual("Currently 2 bikes reserved/ booked. Connectivity: Offline.", settingsPageViewModel.BookingStateInfo);
2022-09-06 16:08:19 +02:00
}
}
2021-07-12 21:31:46 +02:00
}