2021-07-12 21:31:46 +02:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using TINK.Model;
|
|
|
|
|
using TINK.Model.Connector;
|
|
|
|
|
using TINK.Repository.Exception;
|
|
|
|
|
using TINK.Model.Services.CopriApi;
|
|
|
|
|
using TINK.View;
|
|
|
|
|
using TINK.ViewModel.Map;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using TINK.ViewModel.Settings;
|
|
|
|
|
using TINK.Model.Services.Geolocation;
|
|
|
|
|
using TINK.Services;
|
|
|
|
|
using NSubstitute;
|
2021-11-07 19:42:59 +01:00
|
|
|
|
using TINK.Services.Permissions;
|
2021-11-14 23:27:29 +01:00
|
|
|
|
using TestFramework.Services.BluetoothLock;
|
|
|
|
|
using TestFramework.Model.Services.Geolocation;
|
|
|
|
|
using TestFramework.Model.User.Account;
|
|
|
|
|
using TestFramework.Model.Device;
|
|
|
|
|
using TestFramework.Repository;
|
|
|
|
|
using TestFramework.Services.CopriApi.Connector;
|
|
|
|
|
|
|
|
|
|
namespace TestShareeLib.UseCases.Startup
|
2021-07-12 21:31:46 +02:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class TestMapPageViewModel
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TestConstruct()
|
|
|
|
|
{
|
|
|
|
|
var tinkApp = new TinkApp(
|
|
|
|
|
new TINK.Model.Settings.Settings(
|
2021-11-14 23:27:29 +01:00
|
|
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.FILTERTINKGENERAL, FilterState.On }, { FilterHelper.FILTERKONRAD, FilterState.Off } }),
|
|
|
|
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.FILTERTINKGENERAL, FilterState.On }, { FilterHelper.FILTERKONRAD, FilterState.On } }),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
new Uri("https://tinkwwp.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(),
|
2021-11-14 23:27:29 +01:00
|
|
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory001(sessionCookie)),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
|
|
|
new LocksServiceMock(),
|
|
|
|
|
new DeviceMock(),
|
|
|
|
|
new SpecialFolderMock(),
|
|
|
|
|
null, // Cipher
|
|
|
|
|
isConnectedFunc: () => true,
|
|
|
|
|
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-11-14 23:27:29 +01:00
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
|
var navigationService = Substitute.For<INavigation>();
|
2021-11-07 19:42:59 +01:00
|
|
|
|
var locationPermission = Substitute.For<ILocationPermission>();
|
|
|
|
|
|
|
|
|
|
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
var viewModel = new MapPageViewModel(
|
|
|
|
|
tinkApp,
|
2021-11-07 19:42:59 +01:00
|
|
|
|
locationPermission,
|
|
|
|
|
Substitute.For<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(),
|
|
|
|
|
Substitute.For<IGeolocation>(),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
(mapspan) => { },
|
|
|
|
|
viewService,
|
|
|
|
|
navigationService);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnAppearing(); // Is called when page shows.
|
|
|
|
|
|
|
|
|
|
Assert.IsNull(viewModel.Exception);
|
|
|
|
|
|
|
|
|
|
// Verify pins on map
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Assert.AreEqual(21, viewModel.Pins.Count); // Were 8 pins when loading from CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Green")).Tag,
|
2021-11-21 12:34:25 +01:00
|
|
|
|
Is.EqualTo("FR103"),
|
2021-11-14 23:27:29 +01:00
|
|
|
|
"Station FR105 must be marked green because there is are bike.");
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Red")).Tag,
|
|
|
|
|
Is.EqualTo("KN12"),
|
|
|
|
|
"Station KN12 must be marked red because there is no bike."); // Was station id 31
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
// Verify buttons
|
|
|
|
|
Assert.IsTrue(viewModel.IsToggleVisible, "TINK and Konrad are activated in settings.");
|
|
|
|
|
Assert.AreEqual(Color.Blue, viewModel.TinkColor, "TINK bikes are shown.");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Color.Gray, viewModel.KonradColor, "Konrad bikes are hidden.");
|
|
|
|
|
|
|
|
|
|
var statusInfoText = viewModel.StatusInfoText;
|
|
|
|
|
Assert.That(
|
|
|
|
|
statusInfoText,
|
|
|
|
|
Does.Contain("Updating...").Or.Contain(""),
|
|
|
|
|
$"Unexpected text {statusInfoText} detected.",
|
|
|
|
|
"Text might be \"Updating...\" or empty depending on acivity of update thread.");
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnDisappearing();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TestConstruct_KonradActive()
|
|
|
|
|
{
|
|
|
|
|
var tinkApp = new TinkApp(
|
|
|
|
|
new TINK.Model.Settings.Settings(
|
2021-11-14 23:27:29 +01:00
|
|
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.FILTERTINKGENERAL, FilterState.Off }, { FilterHelper.FILTERKONRAD, FilterState.On } }),
|
|
|
|
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.FILTERTINKGENERAL, FilterState.On }, { FilterHelper.FILTERKONRAD, FilterState.On } }),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
new Uri("https://tinkwwp.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(),
|
2021-11-14 23:27:29 +01:00
|
|
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory001(sessionCookie)),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
|
|
|
new LocksServiceMock(),
|
|
|
|
|
new DeviceMock(),
|
|
|
|
|
new SpecialFolderMock(),
|
|
|
|
|
null, // Cipher
|
|
|
|
|
isConnectedFunc: () => true,
|
|
|
|
|
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-11-14 23:27:29 +01:00
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
|
var navigationService = Substitute.For<INavigation>();
|
2021-11-07 19:42:59 +01:00
|
|
|
|
var locationPermission = Substitute.For<ILocationPermission>();
|
|
|
|
|
|
|
|
|
|
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
var viewModel = new MapPageViewModel(
|
|
|
|
|
tinkApp,
|
2021-11-07 19:42:59 +01:00
|
|
|
|
locationPermission,
|
2021-07-12 21:31:46 +02:00
|
|
|
|
NSubstitute.Substitute.For<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(),
|
|
|
|
|
NSubstitute.Substitute.For<IGeolocation>(),
|
|
|
|
|
(mapspan) => { },
|
|
|
|
|
viewService,
|
|
|
|
|
navigationService);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnAppearing(); // Is called when page shows.
|
|
|
|
|
|
|
|
|
|
Assert.IsNull(viewModel.Exception);
|
|
|
|
|
|
|
|
|
|
// Verify pins on map
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Assert.AreEqual(27, viewModel.Pins.Count); // Were 2 pins when loading from CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Green")).Tag, // Was station 5
|
|
|
|
|
Is.EqualTo("FR101"),
|
|
|
|
|
"Station FR101 must be marked green because there is are bike.");
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Red")).Tag, // Was station 14
|
|
|
|
|
Is.EqualTo("KN12"),
|
|
|
|
|
"Station KN12 must be marked red because there is no bike.");
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
// Verify buttons
|
|
|
|
|
Assert.IsTrue(viewModel.IsToggleVisible, "TINK and Konrad are activated in settings.");
|
|
|
|
|
Assert.AreEqual(Color.Gray, viewModel.TinkColor, "TINK bikes are hidden.");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Color.Red, viewModel.KonradColor, "Konrad bikes are shown.");
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(
|
|
|
|
|
new[] { "Updating...", "" }.Contains(viewModel.StatusInfoText),
|
|
|
|
|
"Text might be \"Updating...\" or empty depending on acivity of update thread.");
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnDisappearing();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TestConstruct_KonradOnly()
|
|
|
|
|
{
|
|
|
|
|
var tinkApp = new TinkApp(
|
|
|
|
|
new TINK.Model.Settings.Settings(
|
2021-11-14 23:27:29 +01:00
|
|
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.FILTERKONRAD, FilterState.On } }),
|
|
|
|
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.FILTERTINKGENERAL, FilterState.Off }, { FilterHelper.FILTERKONRAD, FilterState.On } }),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
new Uri("https://tinkwwp.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(),
|
2021-11-14 23:27:29 +01:00
|
|
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory001(sessionCookie)),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
|
|
|
new LocksServiceMock(),
|
|
|
|
|
new DeviceMock(),
|
|
|
|
|
new SpecialFolderMock(),
|
|
|
|
|
null, // Cipher
|
|
|
|
|
isConnectedFunc: () => true,
|
|
|
|
|
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
|
|
|
|
|
|
2021-11-14 23:27:29 +01:00
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
|
var navigationService = Substitute.For<INavigation>();
|
2021-11-07 19:42:59 +01:00
|
|
|
|
var locationPermission = Substitute.For<ILocationPermission>();
|
|
|
|
|
|
|
|
|
|
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
var viewModel = new MapPageViewModel(
|
|
|
|
|
tinkApp,
|
2021-11-07 19:42:59 +01:00
|
|
|
|
locationPermission,
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Substitute.For<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(),
|
|
|
|
|
Substitute.For<IGeolocation>(),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
(mapspan) => { },
|
|
|
|
|
viewService,
|
|
|
|
|
navigationService);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnAppearing(); // Is called when page shows.
|
|
|
|
|
|
|
|
|
|
Assert.IsNull(viewModel.Exception);
|
|
|
|
|
|
|
|
|
|
// Verify pins on map
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Assert.AreEqual(27, viewModel.Pins.Count); // Were 2 when loading from CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Green")).Tag, // Was station id 31
|
|
|
|
|
Is.EqualTo("FR101"),
|
|
|
|
|
"Station FR101 must be marked green because there is are bike.");
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Red")).Tag, // Was 14
|
|
|
|
|
Is.EqualTo("KN12"),
|
|
|
|
|
"Station KN12 must be marked red because there is no bike.");
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
// Verify buttons
|
|
|
|
|
Assert.IsFalse(viewModel.IsToggleVisible, "TINK and Konrad is deactivated from settings.");
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(
|
|
|
|
|
new[] { "Updating...", "" }.Contains(viewModel.StatusInfoText),
|
|
|
|
|
"Text might be \"Updating...\" or empty depending on acivity of update thread.");
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnDisappearing();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TestConstruct_TinkOnly()
|
|
|
|
|
{
|
|
|
|
|
var tinkApp = new TinkApp(
|
|
|
|
|
new TINK.Model.Settings.Settings(
|
2021-11-14 23:27:29 +01:00
|
|
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.FILTERTINKGENERAL, FilterState.On } }),
|
|
|
|
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.FILTERTINKGENERAL, FilterState.On }, { FilterHelper.FILTERKONRAD, FilterState.On } }),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
new Uri("https://tinkwwp.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(),
|
2021-11-14 23:27:29 +01:00
|
|
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory001( sessionCookie)),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
|
|
|
new LocksServiceMock(),
|
|
|
|
|
new DeviceMock(),
|
|
|
|
|
new SpecialFolderMock(),
|
|
|
|
|
null, // Cipher
|
|
|
|
|
isConnectedFunc: () => true,
|
|
|
|
|
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
|
|
|
|
lastVersion: new Version(3, 0, 173));
|
|
|
|
|
|
2021-11-14 23:27:29 +01:00
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
|
var navigationService = Substitute.For<INavigation>();
|
2021-11-07 19:42:59 +01:00
|
|
|
|
var locationPermission = Substitute.For<ILocationPermission>();
|
|
|
|
|
|
|
|
|
|
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
var viewModel = new MapPageViewModel(
|
|
|
|
|
tinkApp,
|
2021-11-07 19:42:59 +01:00
|
|
|
|
locationPermission,
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Substitute.For<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(),
|
|
|
|
|
Substitute.For<IGeolocation>(),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
(mapspan) => { },
|
|
|
|
|
viewService,
|
|
|
|
|
navigationService);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnAppearing(); // Is called when page shows.
|
|
|
|
|
|
|
|
|
|
Assert.IsNull(viewModel.Exception);
|
|
|
|
|
|
|
|
|
|
// Verify pins on map
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Assert.AreEqual(21, viewModel.Pins.Count); // Were 8 pin when loading from CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Green")).Tag,
|
|
|
|
|
Is.EqualTo("FR103"), // Was station id 4
|
|
|
|
|
"Station FR101 must be marked green because there is are bike.");
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Red")).Tag, // Was 31
|
|
|
|
|
Is.EqualTo("KN12"), // Was station id 31
|
|
|
|
|
"Station KN12 must be marked red because there is no bike.");
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
// Verify buttons
|
|
|
|
|
Assert.IsFalse(viewModel.IsToggleVisible, "TINK and Konrad is deactivated from settings.");
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(
|
|
|
|
|
new[] { "Updating...", "" }.Contains(viewModel.StatusInfoText),
|
|
|
|
|
"Text might be \"Updating...\" or empty depending on acivity of update thread.");
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnDisappearing();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TestConstruct_Offline()
|
|
|
|
|
{
|
|
|
|
|
var tinkApp = new TinkApp(
|
|
|
|
|
new TINK.Model.Settings.Settings(
|
2021-11-14 23:27:29 +01:00
|
|
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.FILTERTINKGENERAL, FilterState.On }, { FilterHelper.FILTERKONRAD, FilterState.Off } }),
|
|
|
|
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.FILTERTINKGENERAL, FilterState.On }, { FilterHelper.FILTERKONRAD, FilterState.On } }),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
new Uri("https://tinkwwp.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(),
|
2021-11-14 23:27:29 +01:00
|
|
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory001( sessionCookie)),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
|
|
|
new LocksServiceMock(),
|
|
|
|
|
new DeviceMock(),
|
|
|
|
|
new SpecialFolderMock(),
|
|
|
|
|
null, // Cipher
|
|
|
|
|
isConnectedFunc: () => false,
|
|
|
|
|
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
|
|
|
|
|
|
2021-11-14 23:27:29 +01:00
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
|
var navigationService = Substitute.For<INavigation>();
|
2021-11-07 19:42:59 +01:00
|
|
|
|
var locationPermission = Substitute.For<ILocationPermission>();
|
|
|
|
|
|
|
|
|
|
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
var viewModel = new MapPageViewModel(
|
|
|
|
|
tinkApp,
|
2021-11-07 19:42:59 +01:00
|
|
|
|
locationPermission,
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Substitute.For<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(),
|
|
|
|
|
Substitute.For<IGeolocation>(),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
(mapspan) => { },
|
|
|
|
|
viewService,
|
|
|
|
|
navigationService);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnAppearing(); // Is called when page shows.
|
|
|
|
|
|
|
|
|
|
Assert.IsNull(viewModel.Exception);
|
|
|
|
|
|
|
|
|
|
// Verify pins on map
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Assert.AreEqual(21, viewModel.Pins.Count); // Were 8 pins when loading from CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Green")).Tag, // Was station id 4
|
|
|
|
|
Is.EqualTo("FR103"),
|
|
|
|
|
"Station FR101 must be marked green because there is are bike.");
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Red")).Tag, // Was 31
|
|
|
|
|
Is.EqualTo("KN12"),
|
|
|
|
|
"Station KN12 must be marked red because there is no bike.");
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
// Verify buttons
|
|
|
|
|
Assert.IsTrue(viewModel.IsToggleVisible, "TINK and Konrad are activated in settings.");
|
|
|
|
|
Assert.AreEqual(Color.Blue, viewModel.TinkColor, "TINK bikes are hidden.");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Color.Gray, viewModel.KonradColor, "Konrad bikes are shown.");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("Offline.", viewModel.StatusInfoText);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnDisappearing();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TestConstruct_WebConnectCommunicationError()
|
|
|
|
|
{
|
|
|
|
|
var tinkApp = new TinkApp(
|
|
|
|
|
new TINK.Model.Settings.Settings(
|
2021-11-14 23:27:29 +01:00
|
|
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.FILTERTINKGENERAL, FilterState.On }, { FilterHelper.FILTERKONRAD, FilterState.Off } }),
|
|
|
|
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.FILTERTINKGENERAL, FilterState.On }, { FilterHelper.FILTERKONRAD, FilterState.On } }),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
new Uri("https://tinkwwp.copri-bike.de/APIjsonserver"),
|
|
|
|
|
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
|
|
|
|
Serilog.Events.LogEventLevel.Error,
|
|
|
|
|
true /* IsReportLevelVerbose */,
|
|
|
|
|
activeLockService: typeof(LocksServiceMock).FullName,
|
|
|
|
|
activeGeolocationService: typeof(GeolocationMock).FullName),
|
|
|
|
|
new StoreMock(),
|
|
|
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new TINK.Model.Connector.Connector(
|
|
|
|
|
uri,
|
|
|
|
|
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
|
|
|
|
sessionCookie,
|
|
|
|
|
mail,
|
|
|
|
|
server: new CopriProviderHttps(
|
|
|
|
|
uri,
|
|
|
|
|
TinkApp.MerchantId,
|
|
|
|
|
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
|
|
|
|
sessionCookie: sessionCookie,
|
2021-11-14 23:27:29 +01:00
|
|
|
|
cacheServer: new CopriCallsCacheMemory001(sessionCookie: sessionCookie),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
httpsServer: new ExceptionServer((msg) => new WebConnectFailureException(msg, new Exception("Source expection."))))),
|
|
|
|
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
|
|
|
new LocksServiceMock(),
|
|
|
|
|
new DeviceMock(),
|
|
|
|
|
new SpecialFolderMock(),
|
|
|
|
|
null, // Cipher
|
|
|
|
|
isConnectedFunc: () => false,
|
|
|
|
|
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
|
|
|
|
|
|
2021-11-14 23:27:29 +01:00
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
|
var navigationService = Substitute.For<INavigation>();
|
2021-11-07 19:42:59 +01:00
|
|
|
|
var locationPermission = Substitute.For<ILocationPermission>();
|
|
|
|
|
|
|
|
|
|
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
var viewModel = new MapPageViewModel(
|
|
|
|
|
tinkApp,
|
2021-11-07 19:42:59 +01:00
|
|
|
|
locationPermission,
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Substitute.For<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(),
|
|
|
|
|
Substitute.For<IGeolocation>(),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
(mapspan) => { },
|
|
|
|
|
viewService,
|
|
|
|
|
navigationService);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnAppearing(); // Is called when page shows.
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
"Simulated error thrown at GetStationsAsync.",
|
|
|
|
|
viewModel.Exception.Message);
|
|
|
|
|
|
|
|
|
|
// Verify pins on map
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Assert.AreEqual(21, viewModel.Pins.Count);
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Green")).Tag, // Was station id 4
|
|
|
|
|
Is.EqualTo("FR103"),
|
|
|
|
|
"Station FR101 must be marked green because there is are bike.");
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Red")).Tag, // Was 31
|
|
|
|
|
Is.EqualTo("KN12"),
|
|
|
|
|
"Station KN12 must be marked red because there is no bike.");
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
// Verify buttons
|
|
|
|
|
Assert.IsTrue(viewModel.IsToggleVisible, "TINK and Konrad are activated in settings.");
|
|
|
|
|
Assert.AreEqual(Color.Blue, viewModel.TinkColor, "TINK bikes are hidden.");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Color.Gray, viewModel.KonradColor, "Konrad bikes are shown.");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("Connection interrupted, server unreachable.", viewModel.StatusInfoText);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnDisappearing();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TestConstruct_GeneralPurposeCommunicationError()
|
|
|
|
|
{
|
|
|
|
|
var tinkApp = new TinkApp(
|
|
|
|
|
new TINK.Model.Settings.Settings(
|
2021-11-14 23:27:29 +01:00
|
|
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.FILTERTINKGENERAL, FilterState.On }, { FilterHelper.FILTERKONRAD, FilterState.Off } }),
|
|
|
|
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.FILTERTINKGENERAL, FilterState.On }, { FilterHelper.FILTERKONRAD, FilterState.On } }),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
new Uri("https://tinkwwp.copri-bike.de/APIjsonserver"),
|
|
|
|
|
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
|
|
|
|
Serilog.Events.LogEventLevel.Error,
|
|
|
|
|
true /* IsReportLevelVerbose */,
|
|
|
|
|
activeLockService: typeof(LocksServiceMock).FullName,
|
|
|
|
|
activeGeolocationService: typeof(GeolocationMock).FullName),
|
|
|
|
|
new StoreMock(),
|
|
|
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new TINK.Model.Connector.Connector(
|
|
|
|
|
uri,
|
|
|
|
|
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
|
|
|
|
sessionCookie,
|
|
|
|
|
mail,
|
|
|
|
|
server: new CopriProviderHttps(
|
|
|
|
|
uri,
|
|
|
|
|
TinkApp.MerchantId,
|
|
|
|
|
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
|
|
|
|
sessionCookie: sessionCookie,
|
2021-11-14 23:27:29 +01:00
|
|
|
|
cacheServer: new CopriCallsCacheMemory001(sessionCookie: sessionCookie),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
httpsServer: new ExceptionServer((msg) => new Exception(msg)))),
|
|
|
|
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
|
|
|
new LocksServiceMock(),
|
|
|
|
|
new DeviceMock(),
|
|
|
|
|
new SpecialFolderMock(),
|
|
|
|
|
null, // Cipher
|
|
|
|
|
isConnectedFunc: () => false,
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2021-11-14 23:27:29 +01:00
|
|
|
|
var viewService = Substitute.For<IViewService>();
|
|
|
|
|
var navigationService = Substitute.For<INavigation>();
|
2021-11-07 19:42:59 +01:00
|
|
|
|
var locationPermission = Substitute.For<ILocationPermission>();
|
|
|
|
|
|
|
|
|
|
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
|
|
|
|
|
var viewModel = new MapPageViewModel(
|
|
|
|
|
tinkApp,
|
2021-11-07 19:42:59 +01:00
|
|
|
|
locationPermission,
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Substitute.For<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(),
|
|
|
|
|
Substitute.For<IGeolocation>(),
|
2021-07-12 21:31:46 +02:00
|
|
|
|
(mapspan) => { },
|
|
|
|
|
viewService,
|
|
|
|
|
navigationService);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnAppearing(); // Is called when page shows.
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(
|
|
|
|
|
"Simulated error thrown at GetStationsAsync.",
|
|
|
|
|
viewModel.Exception.Message);
|
|
|
|
|
|
|
|
|
|
// Verify pins on map
|
2021-11-14 23:27:29 +01:00
|
|
|
|
Assert.AreEqual(21, viewModel.Pins.Count);
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.Where(pin => pin.Icon.Id.Contains("Open_Green")).Select(pin => pin.Tag.ToString()),
|
|
|
|
|
Does.Contain("FR103"), // Was station id 4
|
|
|
|
|
"Station FR103 must be marked green because there is are bike.");
|
|
|
|
|
Assert.That(
|
|
|
|
|
viewModel.Pins.Where(pin => pin.Icon.Id.Contains("Open_Red")).Select(pin => pin.Tag.ToString()),
|
|
|
|
|
Does.Contain("KN12"), // Was station id 31
|
2021-07-12 21:31:46 +02:00
|
|
|
|
"Station 31 must be marked red because there is no bike.");
|
|
|
|
|
|
|
|
|
|
// Verify buttons
|
|
|
|
|
Assert.IsTrue(viewModel.IsToggleVisible, "TINK and Konrad are activated in settings.");
|
|
|
|
|
Assert.AreEqual(Color.Blue , viewModel.TinkColor, "TINK bikes are hidden.");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Color.Gray, viewModel.KonradColor, "Konrad bikes are shown.");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("Connection interrupted.", viewModel.StatusInfoText);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
await viewModel.OnDisappearing();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|