2021-07-12 21:31:46 +02:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Rhino.Mocks;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using TINK.Model;
|
|
|
|
|
using TINK.Model.Connector;
|
|
|
|
|
using TINK.Repository.Exception;
|
|
|
|
|
using TINK.View;
|
|
|
|
|
using TINK.Model.Services.CopriApi;
|
|
|
|
|
using TINK.Repository;
|
|
|
|
|
|
|
|
|
|
using static TINK.Repository.CopriCallsMemory;
|
|
|
|
|
using TINK.ViewModel.Map;
|
|
|
|
|
using TINK.ViewModel.Settings;
|
|
|
|
|
using TINK.ViewModel.Account;
|
|
|
|
|
using TINK.Services;
|
2022-04-10 17:38:34 +02:00
|
|
|
|
using TINK.Services.Geolocation;
|
2021-07-12 21:31:46 +02:00
|
|
|
|
using NSubstitute;
|
2021-11-14 23:27:29 +01:00
|
|
|
|
using TestFramework.Model.Device;
|
|
|
|
|
using TestFramework.Repository;
|
|
|
|
|
using TestFramework.Model.User.Account;
|
|
|
|
|
using TestFramework.Model.Services.Geolocation;
|
|
|
|
|
using TestFramework.Services.BluetoothLock;
|
|
|
|
|
using TestFramework.Services.CopriApi.Connector;
|
2022-04-10 17:38:34 +02:00
|
|
|
|
using TINK.Services.Permissions;
|
|
|
|
|
using Plugin.BLE.Abstractions.Contracts;
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
namespace TestTINKLib.Fixtures.ObjectTests.Account
|
|
|
|
|
{
|
|
|
|
|
public class TestAccountPageViewModel
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestConstruct_NotLoggedIn()
|
|
|
|
|
{
|
|
|
|
|
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 } }),
|
|
|
|
|
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,
|
2022-04-10 17:38:34 +02:00
|
|
|
|
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)),
|
|
|
|
|
merchantId: "MyMerchId",
|
|
|
|
|
bluetoothService: Substitute.For<IBluetoothLE>(),
|
|
|
|
|
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
|
|
|
|
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
|
|
|
locksService: new LocksServiceMock(), // Cipher
|
|
|
|
|
device: new DeviceMock(),
|
|
|
|
|
specialFolder: new SpecialFolderMock(),
|
|
|
|
|
cipher: null,
|
2021-07-12 21:31:46 +02:00
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
var viewService = MockRepository.GenerateStub<IViewService>();
|
|
|
|
|
|
|
|
|
|
var settingsPageViewModel = new AccountPageViewModel(
|
|
|
|
|
tinkApp,
|
|
|
|
|
(uri) => { },
|
|
|
|
|
viewService);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("No user logged in.", settingsPageViewModel.LoggedInInfo);
|
|
|
|
|
Assert.IsFalse(settingsPageViewModel.IsBookingStateInfoVisible, "No user logged in.");
|
|
|
|
|
Assert.AreEqual(string.Empty, settingsPageViewModel.BookingStateInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TestConstruct()
|
|
|
|
|
{
|
|
|
|
|
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 } }),
|
|
|
|
|
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),
|
2022-01-04 18:59:16 +01:00
|
|
|
|
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "UnknownCookie", new List<string> { "TINK" })),
|
2022-04-10 17:38:34 +02:00
|
|
|
|
isConnectedFunc: () => true,
|
|
|
|
|
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)),
|
|
|
|
|
merchantId: "MyMerchId",
|
|
|
|
|
bluetoothService: Substitute.For<IBluetoothLE>(),
|
|
|
|
|
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
|
|
|
|
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
|
|
|
locksService: new LocksServiceMock(), // Cipher
|
|
|
|
|
device: new DeviceMock(),
|
|
|
|
|
specialFolder: new SpecialFolderMock(),
|
|
|
|
|
cipher: null,
|
2021-07-12 21:31:46 +02:00
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
var viewService = MockRepository.GenerateStub<IViewService>();
|
|
|
|
|
|
|
|
|
|
var settingsPageViewModel = new AccountPageViewModel(
|
|
|
|
|
tinkApp,
|
|
|
|
|
(uri) => { },
|
|
|
|
|
viewService);
|
|
|
|
|
|
|
|
|
|
await settingsPageViewModel.OnAppearing();
|
|
|
|
|
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Assert.AreEqual("Logged in as a@b.", settingsPageViewModel.LoggedInInfo);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
Assert.IsFalse(settingsPageViewModel.IsBookingStateInfoVisible, "A user is logged but no bikes requested/ booked.");
|
|
|
|
|
Assert.AreEqual(string.Empty, settingsPageViewModel.BookingStateInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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 } }),
|
|
|
|
|
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),
|
2022-01-04 18:59:16 +01:00
|
|
|
|
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "6103_112e96b36ba33de245943c5ffaf369cd_", new List<string> { "TINK" })),
|
2022-04-10 17:38:34 +02:00
|
|
|
|
isConnectedFunc: () => true,
|
|
|
|
|
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), sessionCookie, mail, new CopriCallsMemory001(sessionCookie)),
|
|
|
|
|
merchantId: "MyMerchId",
|
|
|
|
|
bluetoothService: Substitute.For<IBluetoothLE>(),
|
|
|
|
|
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
|
|
|
|
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
|
|
|
locksService: new LocksServiceMock(), // Cipher
|
|
|
|
|
device: new DeviceMock(),
|
|
|
|
|
specialFolder: new SpecialFolderMock(),
|
|
|
|
|
cipher: null,
|
2021-07-12 21:31:46 +02:00
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
var viewService = MockRepository.GenerateStub<IViewService>();
|
|
|
|
|
var settingsPageViewModel = new AccountPageViewModel(
|
|
|
|
|
tinkApp,
|
|
|
|
|
(uri) => { },
|
|
|
|
|
viewService);
|
|
|
|
|
|
|
|
|
|
await settingsPageViewModel.OnAppearing();
|
|
|
|
|
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Assert.AreEqual("Logged in as a@b.", settingsPageViewModel.LoggedInInfo);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
Assert.IsTrue(settingsPageViewModel.IsBookingStateInfoVisible, "A user is logged but no bikes requested/ booked.");
|
|
|
|
|
Assert.AreEqual("Aktuell 2 Fahrräder reserviert/ gebucht.", settingsPageViewModel.BookingStateInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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 } }),
|
|
|
|
|
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),
|
2022-01-04 18:59:16 +01:00
|
|
|
|
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "6103_112e96b36ba33de245943c5ffaf369cd_", new List<string> { "TINK" })),
|
2022-04-10 17:38:34 +02:00
|
|
|
|
isConnectedFunc: () => false,
|
|
|
|
|
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), sessionCookie, mail, new CopriCallsMemory001(sessionCookie)),
|
|
|
|
|
merchantId: "MyMerchId",
|
|
|
|
|
bluetoothService: Substitute.For<IBluetoothLE>(),
|
|
|
|
|
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
|
|
|
|
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
|
|
|
locksService: new LocksServiceMock(), // Cipher
|
|
|
|
|
device: new DeviceMock(),
|
|
|
|
|
specialFolder: new SpecialFolderMock(),
|
|
|
|
|
cipher: null, // Offline
|
2021-07-12 21:31:46 +02:00
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
var viewService = MockRepository.GenerateStub<IViewService>();
|
|
|
|
|
var settingsPageViewModel = new AccountPageViewModel(
|
|
|
|
|
tinkApp,
|
|
|
|
|
(uri) => { },
|
|
|
|
|
viewService);
|
|
|
|
|
|
|
|
|
|
await settingsPageViewModel.OnAppearing();
|
|
|
|
|
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Assert.AreEqual("Logged in as a@b.", settingsPageViewModel.LoggedInInfo);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
Assert.IsTrue(settingsPageViewModel.IsBookingStateInfoVisible, "A user is logged but no bikes requested/ booked.");
|
|
|
|
|
Assert.AreEqual("Aktuell 2 Fahrräder reserviert/ gebucht. Verbindungsstatus: Offline.", settingsPageViewModel.BookingStateInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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 } }),
|
|
|
|
|
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),
|
2022-01-04 18:59:16 +01:00
|
|
|
|
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "6103_112e96b36ba33de245943c5ffaf369cd_", new List<string> { "TINK" })),
|
2022-04-10 17:38:34 +02:00
|
|
|
|
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)),
|
|
|
|
|
sessionCookie,
|
|
|
|
|
mail,
|
|
|
|
|
server: new CopriProviderHttps(
|
|
|
|
|
uri,
|
|
|
|
|
TinkApp.MerchantId,
|
|
|
|
|
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
|
|
|
|
sessionCookie: sessionCookie,
|
|
|
|
|
cacheServer: new CopriCallsCacheMemory001(sessionCookie: sessionCookie),
|
|
|
|
|
httpsServer: new ExceptionServer((msg) => new WebConnectFailureException(msg, new Exception("Source expection."))))),
|
|
|
|
|
merchantId: "MyMerchId",
|
|
|
|
|
bluetoothService: Substitute.For<IBluetoothLE>(),
|
|
|
|
|
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
|
|
|
|
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
|
|
|
locksService: new LocksServiceMock(), // Cipher
|
|
|
|
|
device: new DeviceMock(),
|
|
|
|
|
specialFolder: new SpecialFolderMock(),
|
|
|
|
|
cipher: null, // Offline
|
2021-07-12 21:31:46 +02:00
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
var viewService = MockRepository.GenerateStub<IViewService>();
|
|
|
|
|
var settingsPageViewModel = new AccountPageViewModel(
|
|
|
|
|
tinkApp,
|
|
|
|
|
(uri) => { },
|
|
|
|
|
viewService);
|
|
|
|
|
|
|
|
|
|
await settingsPageViewModel.OnAppearing();
|
|
|
|
|
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Assert.AreEqual("Logged in as a@b.", settingsPageViewModel.LoggedInInfo); // CopriCallsCacheMemory(SampleSets.Set2,
|
2021-07-12 21:31:46 +02:00
|
|
|
|
Assert.IsTrue(settingsPageViewModel.IsBookingStateInfoVisible, "A user is logged but no bikes requested/ booked.");
|
|
|
|
|
Assert.AreEqual("Aktuell 2 Fahrräder reserviert/ gebucht. Verbindungsstatus: Offline.", settingsPageViewModel.BookingStateInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|