mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
264 lines
13 KiB
C#
264 lines
13 KiB
C#
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.Repository;
|
|
using SharedBusinessLogic.Tests.Framework.Services.BluetoothLock;
|
|
using ShareeBike.Model;
|
|
using ShareeBike.Model.Connector;
|
|
using ShareeBike.Model.Services.CopriApi;
|
|
using ShareeBike.Model.Settings;
|
|
using ShareeBike.Repository;
|
|
using ShareeBike.Repository.Exception;
|
|
using ShareeBike.Services;
|
|
using ShareeBike.Services.Geolocation;
|
|
using ShareeBike.Services.Permissions;
|
|
using ShareeBike.View;
|
|
using ShareeBike.ViewModel.Account;
|
|
using ShareeBike.ViewModel.Map;
|
|
using ShareeBike.ViewModel.Settings;
|
|
using static ShareeBike.Repository.CopriCallsMemory;
|
|
|
|
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.Account
|
|
{
|
|
public class TestAccountPageViewModel
|
|
{
|
|
[Test]
|
|
public void TestConstruct_NotLoggedIn()
|
|
{
|
|
const string MERCH_ID = "MyMerchId";
|
|
|
|
var shareeBikeApp = new ShareeBikeApp(
|
|
new ShareeBike.Model.Settings.Settings(
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "ShareeBike", FilterState.On }, { "Citybike", FilterState.Off } }),
|
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { "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, sessionCookie)),
|
|
merchantId: MERCH_ID,
|
|
bluetoothService: Substitute.For<IBluetoothLE>(),
|
|
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
|
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocationService>>(),
|
|
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.
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
var settingsPageViewModel = new AccountPageViewModel(
|
|
shareeBikeApp,
|
|
(uri) => { },
|
|
viewService);
|
|
|
|
|
|
Assert.That(settingsPageViewModel.LoggedInInfo, Is.EqualTo("No user logged in."));
|
|
Assert.That(settingsPageViewModel.IsBookingStateInfoVisible, Is.False, "No user logged in.");
|
|
Assert.That(settingsPageViewModel.BookingStateInfo, Is.EqualTo(string.Empty));
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstruct()
|
|
{
|
|
const string MERCH_ID = "MyMerchId";
|
|
|
|
var shareeBikeApp = new ShareeBikeApp(
|
|
new ShareeBike.Model.Settings.Settings(
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "ShareeBike", FilterState.On }, { "Citybike", FilterState.Off } }),
|
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { "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(new ShareeBike.Model.User.Account.Account("a@b", "123456789", false, "UnknownCookie", new List<string> { "ShareeBike" })),
|
|
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, sessionCookie)),
|
|
merchantId: MERCH_ID,
|
|
bluetoothService: Substitute.For<IBluetoothLE>(),
|
|
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
|
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocationService>>(),
|
|
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.
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
var settingsPageViewModel = new AccountPageViewModel(
|
|
shareeBikeApp,
|
|
(uri) => { },
|
|
viewService);
|
|
|
|
await settingsPageViewModel.OnAppearing();
|
|
|
|
Assert.That(settingsPageViewModel.LoggedInInfo, Is.EqualTo("Logged in as a@b."));
|
|
Assert.That(settingsPageViewModel.IsBookingStateInfoVisible, Is.False, "A user is logged but no bikes requested/ booked.");
|
|
Assert.That(settingsPageViewModel.BookingStateInfo, Is.EqualTo(string.Empty));
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstruct_TwoBikes()
|
|
{
|
|
var shareeBikeApp = new ShareeBikeApp(
|
|
new ShareeBike.Model.Settings.Settings(
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "ShareeBike", FilterState.On }, { "Citybike", FilterState.Off } }),
|
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { "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(new ShareeBike.Model.User.Account.Account("a@b", "123456789", false, "6103_112e96b36ba33de245943c5ffaf369cd_", new List<string> { "ShareeBike" })),
|
|
isConnectedFunc: () => true,
|
|
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)),
|
|
merchantId: "MyMerchId",
|
|
bluetoothService: Substitute.For<IBluetoothLE>(),
|
|
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
|
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocationService>>(),
|
|
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.
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
var settingsPageViewModel = new AccountPageViewModel(
|
|
shareeBikeApp,
|
|
(uri) => { },
|
|
viewService);
|
|
|
|
await settingsPageViewModel.OnAppearing();
|
|
|
|
Assert.That(settingsPageViewModel.LoggedInInfo, Is.EqualTo("Logged in as a@b."));
|
|
Assert.That(settingsPageViewModel.IsBookingStateInfoVisible, Is.True, "A user is logged but no bikes requested/ booked.");
|
|
Assert.That(settingsPageViewModel.BookingStateInfo, Is.EqualTo("Currently 2 bikes reserved/ booked."));
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstruct_TwoBikes_Offline()
|
|
{
|
|
var shareeBikeApp = new ShareeBikeApp(
|
|
new ShareeBike.Model.Settings.Settings(
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "ShareeBike", FilterState.On }, { "Citybike", FilterState.Off } }),
|
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { "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(new ShareeBike.Model.User.Account.Account("a@b", "123456789", false, "6103_112e96b36ba33de245943c5ffaf369cd_", new List<string> { "ShareeBike" })),
|
|
isConnectedFunc: () => false,
|
|
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)),
|
|
merchantId: "MyMerchId",
|
|
bluetoothService: Substitute.For<IBluetoothLE>(),
|
|
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
|
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocationService>>(),
|
|
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.
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
var settingsPageViewModel = new AccountPageViewModel(
|
|
shareeBikeApp,
|
|
(uri) => { },
|
|
viewService);
|
|
|
|
await settingsPageViewModel.OnAppearing();
|
|
|
|
Assert.That(settingsPageViewModel.LoggedInInfo, Is.EqualTo("Logged in as a@b."));
|
|
Assert.That(settingsPageViewModel.IsBookingStateInfoVisible, Is.True, "A user is logged but no bikes requested/ booked.");
|
|
Assert.That(settingsPageViewModel.BookingStateInfo, Is.EqualTo("Currently 2 bikes reserved/ booked. Connectivity: Offline."));
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstruct_TwoBikes_WebConnectCommunicationError()
|
|
{
|
|
var shareeBikeApp = new ShareeBikeApp(
|
|
new ShareeBike.Model.Settings.Settings(
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "ShareeBike", FilterState.On }, { "Citybike", FilterState.Off } }),
|
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { "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(new ShareeBike.Model.User.Account.Account("a@b", "123456789", false, "6103_112e96b36ba33de245943c5ffaf369cd_", new List<string> { "ShareeBike" })),
|
|
isConnectedFunc: () => false,
|
|
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ShareeBike.Model.Connector.Connector(
|
|
uri,
|
|
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
|
null /*UI language */,
|
|
sessionCookie,
|
|
mail,
|
|
server: new CopriProviderHttps(
|
|
uri,
|
|
ShareeBikeApp.MerchantId,
|
|
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
|
null /*UI language */,
|
|
sessionCookie: sessionCookie,
|
|
cacheServer: new CopriCallsCacheMemory001(sessionCookie: sessionCookie),
|
|
httpsServer: new ExceptionServer((msg) => new WebConnectFailureException(msg, new Exception("Source exception."))))),
|
|
merchantId: "MyMerchId",
|
|
bluetoothService: Substitute.For<IBluetoothLE>(),
|
|
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
|
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocationService>>(),
|
|
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.
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
var settingsPageViewModel = new AccountPageViewModel(
|
|
shareeBikeApp,
|
|
(uri) => { },
|
|
viewService);
|
|
|
|
await settingsPageViewModel.OnAppearing();
|
|
|
|
Assert.That(settingsPageViewModel.LoggedInInfo, Is.EqualTo("Logged in as a@b.")); // CopriCallsCacheMemory(SampleSets.Set2,
|
|
Assert.That(settingsPageViewModel.IsBookingStateInfoVisible, Is.True, "A user is logged but no bikes requested/ booked.");
|
|
Assert.That(settingsPageViewModel.BookingStateInfo, Is.EqualTo("Currently 2 bikes reserved/ booked. Connectivity: Offline."));
|
|
}
|
|
}
|
|
}
|