mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-16 07:06:33 +01:00
387 lines
19 KiB
C#
387 lines
19 KiB
C#
|
using NUnit.Framework;
|
|||
|
using TINK.Model;
|
|||
|
|
|||
|
using TINK.Model.User.Account;
|
|||
|
using TestTINKLib.Model.User.Account;
|
|||
|
using TINK.Model.Connector;
|
|||
|
using TestTINKLib.Mocks.Device;
|
|||
|
using System;
|
|||
|
using TINK.Model.Station;
|
|||
|
using TINK.Model.Bike;
|
|||
|
using static TINK.Repository.CopriCallsMemory;
|
|||
|
using TINK.Model.State;
|
|||
|
using System.Collections.Generic;
|
|||
|
using TestTINKLib.Mocks.Services;
|
|||
|
using TINK.Repository;
|
|||
|
using TINK.ViewModel.Map;
|
|||
|
using TINK.ViewModel.Settings;
|
|||
|
using NSubstitute;
|
|||
|
using TINK.Services;
|
|||
|
using TINK.Model.Services.Geolocation;
|
|||
|
|
|||
|
namespace TestTINKLib.Fixtures.UseCases.Startup
|
|||
|
{
|
|||
|
[TestFixture]
|
|||
|
public class TestTinkApp
|
|||
|
{
|
|||
|
[Test]
|
|||
|
public void NotLoggedIn()
|
|||
|
{
|
|||
|
var l_oConnector = new ConnectorCache(
|
|||
|
string.Empty,
|
|||
|
string.Empty,
|
|||
|
new CopriCallsMemory(SampleSets.Set2, 1));
|
|||
|
|
|||
|
var l_oTinkApp = new TinkApp(
|
|||
|
new TINK.Model.Settings.Settings(
|
|||
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On } }),
|
|||
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
|||
|
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(),
|
|||
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1)),
|
|||
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|||
|
new LocksServiceMock(),
|
|||
|
new DeviceMock(),
|
|||
|
new SpecialFolderMock(),
|
|||
|
null, // Cipher
|
|||
|
new PermissionsMock(),
|
|||
|
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
|
|||
|
|
|||
|
var l_oStations = l_oTinkApp.GetConnector(true).Query.GetBikesAndStationsAsync().Result.Response;
|
|||
|
|
|||
|
// Check stations.
|
|||
|
Assert.AreEqual(8, l_oStations.StationsAll.Count);
|
|||
|
Assert.NotNull(l_oStations.StationsAll.GetById("4"));
|
|||
|
Assert.AreEqual("4", l_oStations.StationsAll.GetById("4").Id);
|
|||
|
Assert.AreEqual(new Position(47.6586936667, 9.16863116667), l_oStations.StationsAll.GetById("4").Position);
|
|||
|
|
|||
|
// Verify selected station.
|
|||
|
Assert.AreEqual(
|
|||
|
null,
|
|||
|
l_oTinkApp.SelectedStation.Id,
|
|||
|
"When starting app selected station must always be invlid");
|
|||
|
|
|||
|
// Verify bikes at station.
|
|||
|
Assert.AreEqual(
|
|||
|
0,
|
|||
|
TestHelper.GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.SelectedStation.Id).Result.Count,
|
|||
|
"If no station is selected BikesAtStation- list count must be zero");
|
|||
|
|
|||
|
// Check my bikes.
|
|||
|
Assert.IsFalse(l_oTinkApp.ActiveUser.IsLoggedIn);
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void LoggedIn_BikesReservedBooked()
|
|||
|
{
|
|||
|
var l_oConnector = new ConnectorCache(
|
|||
|
"4da3044c8657a04ba60e2eaa753bc51a",
|
|||
|
"javaminister@gmail.com",
|
|||
|
new CopriCallsMemory(SampleSets.Set2, 1, "4da3044c8657a04ba60e2eaa753bc51a"));
|
|||
|
|
|||
|
// User logged in is initial state to verify.
|
|||
|
var l_oTinkApp = new TinkApp(
|
|||
|
new TINK.Model.Settings.Settings(
|
|||
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On } }),
|
|||
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
|||
|
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(new Account("javaminister@gmail.com", "javaminister" /* password */, "4da3044c8657a04ba60e2eaa753bc51a" /* session cookie */, new List<string> { "TINK", "Konrad" })),
|
|||
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1, "4da3044c8657a04ba60e2eaa753bc51a")),
|
|||
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|||
|
new LocksServiceMock(),
|
|||
|
new DeviceMock(),
|
|||
|
new SpecialFolderMock(),
|
|||
|
null, // Cipher
|
|||
|
new PermissionsMock(),
|
|||
|
isConnectedFunc: () => true,
|
|||
|
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
|
|||
|
|
|||
|
var l_oStations = l_oTinkApp.GetConnector(true).Query.GetBikesAndStationsAsync().Result.Response;
|
|||
|
|
|||
|
// Check stations.
|
|||
|
Assert.AreEqual(8, l_oStations.StationsAll.Count);
|
|||
|
Assert.NotNull(l_oStations.StationsAll.GetById("4"));
|
|||
|
Assert.AreEqual("4", l_oStations.StationsAll.GetById("4").Id);
|
|||
|
Assert.AreEqual(new Position(47.6586936667, 9.16863116667), l_oStations.StationsAll.GetById("4").Position);
|
|||
|
|
|||
|
// Verify selected station.
|
|||
|
Assert.AreEqual(
|
|||
|
null,
|
|||
|
l_oTinkApp.SelectedStation.Id,
|
|||
|
"When starting app selected station must always be invlid");
|
|||
|
|
|||
|
// Verify bikes at station.
|
|||
|
Assert.AreEqual(
|
|||
|
0,
|
|||
|
TestHelper.GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.SelectedStation.Id).Result.Count,
|
|||
|
"If no station is selected BikesAtStation- list count must be zero");
|
|||
|
|
|||
|
// Check my bikes
|
|||
|
var l_oBikes = l_oTinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response;
|
|||
|
Assert.AreEqual(2, l_oBikes.Count);
|
|||
|
Assert.AreEqual("8", l_oBikes.GetById("8").Id);
|
|||
|
Assert.AreEqual(InUseStateEnum.Booked, l_oBikes.GetById("8").State.Value);
|
|||
|
Assert.AreEqual("5", l_oBikes.GetById("8").CurrentStation);
|
|||
|
Assert.AreEqual(TypeOfBike.Cargo, l_oBikes.GetById("8").TypeOfBike);
|
|||
|
Assert.AreEqual(WheelType.Two, l_oBikes.GetById("8").WheelType);
|
|||
|
Assert.AreEqual("7", l_oBikes.GetById("7").Id);
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void LoggedIn_AllBikesDisposable_FilterTINK()
|
|||
|
{
|
|||
|
var l_oConnector = new ConnectorCache(
|
|||
|
"1234",
|
|||
|
"mgrimm@gmail.com",
|
|||
|
new CopriCallsMemory(SampleSets.Set2, 1));
|
|||
|
|
|||
|
// No user logged in is initial state to verify.
|
|||
|
var l_oTinkApp = new TinkApp(
|
|||
|
new TINK.Model.Settings.Settings(
|
|||
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On } }),
|
|||
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
|||
|
new Uri("https://app.tink-konstanz.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 Account("mgrimm@gmail.com", "123456789" /* password */, "1234" /* session cookie */, new List<string> { "TINK", "Konrad" })),
|
|||
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1)),
|
|||
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|||
|
new LocksServiceMock(),
|
|||
|
new DeviceMock(),
|
|||
|
new SpecialFolderMock(),
|
|||
|
null, // Cipher
|
|||
|
new PermissionsMock(),
|
|||
|
isConnectedFunc: () => true,
|
|||
|
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
|
|||
|
|
|||
|
var l_oStations = l_oTinkApp.GetConnector(true).Query.GetBikesAndStationsAsync().Result.Response;
|
|||
|
|
|||
|
// Check stations.
|
|||
|
Assert.AreEqual(8, l_oStations.StationsAll.Count);
|
|||
|
Assert.NotNull(l_oStations.StationsAll.GetById("4"));
|
|||
|
Assert.AreEqual("4", l_oStations.StationsAll.GetById("4").Id);
|
|||
|
Assert.AreEqual(new Position(47.6586936667, 9.16863116667), l_oStations.StationsAll.GetById("4").Position);
|
|||
|
|
|||
|
// Verify selected station.
|
|||
|
Assert.AreEqual(
|
|||
|
null,
|
|||
|
l_oTinkApp.SelectedStation.Id,
|
|||
|
"When starting app selected station must always be invlid");
|
|||
|
|
|||
|
// Verify bikes at station.
|
|||
|
Assert.AreEqual(
|
|||
|
0,
|
|||
|
TestHelper.GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.SelectedStation.Id).Result.Count,
|
|||
|
"If no station is selected BikesAtStation- list count must be zero");
|
|||
|
|
|||
|
// Check my bikes
|
|||
|
Assert.IsTrue(l_oTinkApp.ActiveUser.IsLoggedIn);
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void LoggedIn_AllBikesDisposable_FilterKonrad()
|
|||
|
{
|
|||
|
var l_oCopriServer = new CopriCallsMemory(SampleSets.Set2, 1);
|
|||
|
var l_oConnector = new ConnectorCache(
|
|||
|
"1234",
|
|||
|
"mgrimm@gmail.com",
|
|||
|
new CopriCallsMemory(SampleSets.Set2, 1));
|
|||
|
|
|||
|
// No user logged in is initial state to verify.
|
|||
|
var l_oTinkApp = new TinkApp(
|
|||
|
new TINK.Model.Settings.Settings(
|
|||
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "Konrad", FilterState.On } }),
|
|||
|
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
|||
|
new Uri("https://app.tink-konstanz.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 Account("mgrimm@gmail.com", "123456789" /* password */, "1234" /* session cookie */, new List<string> { "TINK", "Konrad" })),
|
|||
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1)),
|
|||
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|||
|
new LocksServiceMock(),
|
|||
|
new DeviceMock(),
|
|||
|
new SpecialFolderMock(),
|
|||
|
null, // Cipher
|
|||
|
new PermissionsMock(),
|
|||
|
isConnectedFunc: () => true,
|
|||
|
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
|
|||
|
|
|||
|
var l_oStations = l_oTinkApp.GetConnector(true).Query.GetBikesAndStationsAsync().Result.Response;
|
|||
|
|
|||
|
// Check stations.
|
|||
|
Assert.AreEqual(2, l_oStations.StationsAll.Count);
|
|||
|
Assert.NotNull(l_oStations.StationsAll.GetById("14"));
|
|||
|
Assert.AreEqual("14", l_oStations.StationsAll.GetById("14").Id);
|
|||
|
Assert.AreEqual(new Position(47.66698054007847, 9.169303178787231), l_oStations.StationsAll.GetById("14").Position);
|
|||
|
|
|||
|
// Verify selected station.
|
|||
|
Assert.AreEqual(
|
|||
|
null,
|
|||
|
l_oTinkApp.SelectedStation.Id,
|
|||
|
"When starting app selected station must always be invlid");
|
|||
|
|
|||
|
// Verify bikes at station.
|
|||
|
Assert.AreEqual(
|
|||
|
0,
|
|||
|
TestHelper.GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.SelectedStation.Id).Result.Count,
|
|||
|
"If no station is selected BikesAtStation- list count must be zero");
|
|||
|
|
|||
|
// Check my bikes
|
|||
|
Assert.IsTrue(l_oTinkApp.ActiveUser.IsLoggedIn);
|
|||
|
}
|
|||
|
|
|||
|
[Test, Ignore("Todo: Check if reserved bikes are released even if system is offline.")]
|
|||
|
public void LoggedIn_BikesReserved_OfflineAfterStart()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Test if Whats New logic works as expected. Form version 3.0.0.115 or smaller no Whats New dialog existed.
|
|||
|
/// </summary>
|
|||
|
[Test]
|
|||
|
public void FirstInstall_WhatsNew()
|
|||
|
{
|
|||
|
var l_oAppVersion = new Version(3, 2, 0, 120);
|
|||
|
|
|||
|
var l_oTinkApp = new TinkApp(
|
|||
|
new TINK.Model.Settings.Settings(
|
|||
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On } }),
|
|||
|
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),
|
|||
|
new StoreMock(),
|
|||
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1)),
|
|||
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|||
|
null, // use default locks service
|
|||
|
new DeviceMock(),
|
|||
|
new SpecialFolderMock(),
|
|||
|
null, // Cipher
|
|||
|
new PermissionsMock(),
|
|||
|
#if ARENDI
|
|||
|
Substitute.For<ICentral>(),
|
|||
|
#endif
|
|||
|
isConnectedFunc: () => true,
|
|||
|
currentVersion: l_oAppVersion, // Current app version
|
|||
|
lastVersion: null, // Last version.
|
|||
|
whatsNewShownInVersion: null); // First install.
|
|||
|
|
|||
|
// Whats new page
|
|||
|
Assert.IsFalse(
|
|||
|
l_oTinkApp.WhatsNew.IsShowRequired,
|
|||
|
$"Whats new should not be displayed because first install has been detected.");
|
|||
|
|
|||
|
// Call member which view model calls when using app.
|
|||
|
l_oTinkApp.SetWhatsNewWasShown();
|
|||
|
|
|||
|
// Whats new page
|
|||
|
Assert.IsFalse(
|
|||
|
l_oTinkApp.WhatsNew.IsShowRequired,
|
|||
|
$"Whats new should mot be displayed first install detected.");
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void Upgrade120_WhatsNew()
|
|||
|
{
|
|||
|
var l_oAppVersion = new Version(3, 0, 0, 120);
|
|||
|
Version lastVersion = new Version(3, 0, 0, 116);
|
|||
|
|
|||
|
var l_oTinkApp = new TinkApp(
|
|||
|
new TINK.Model.Settings.Settings(
|
|||
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On } }),
|
|||
|
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),
|
|||
|
new StoreMock(),
|
|||
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1)),
|
|||
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|||
|
null, // use default locks service
|
|||
|
new DeviceMock(),
|
|||
|
new SpecialFolderMock(),
|
|||
|
null, // Cipher
|
|||
|
new PermissionsMock(),
|
|||
|
#if ARENDI // Requires LockItArendi library.
|
|||
|
Substitute.For<ICentral>(),
|
|||
|
#endif
|
|||
|
isConnectedFunc: () => true,
|
|||
|
currentVersion: l_oAppVersion, // Current app version
|
|||
|
lastVersion: lastVersion,
|
|||
|
whatsNewShownInVersion: null); // Whats new page was never shown.
|
|||
|
|
|||
|
// Whats new page
|
|||
|
Assert.IsTrue(
|
|||
|
l_oTinkApp.WhatsNew.IsShowRequired,
|
|||
|
$"Whats new should be displayed because app version is {l_oAppVersion} and version when \"Whats New\" was shown last is {lastVersion} (null means never).");
|
|||
|
|
|||
|
// Call member which view model calls when using app.
|
|||
|
l_oTinkApp.SetWhatsNewWasShown();
|
|||
|
|
|||
|
// Whats new page
|
|||
|
Assert.IsFalse(
|
|||
|
l_oTinkApp.WhatsNew.IsShowRequired,
|
|||
|
$"Whats new should mot be displayed because app version is {l_oAppVersion} and version when \"Whats New\" was shown last is {lastVersion} equals.");
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void SubsequentStart_WhatsNew()
|
|||
|
{
|
|||
|
var l_oAppVersion = new Version(3, 2, 0, 115);
|
|||
|
var l_oWhatsNewVersion = new Version(3, 2, 0, 115);
|
|||
|
|
|||
|
var l_oTinkApp = new TinkApp(
|
|||
|
new TINK.Model.Settings.Settings(
|
|||
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On } }),
|
|||
|
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(TINK.Services.BluetoothLock.BLE.LockItByGuidService).FullName,
|
|||
|
activeGeolocationService: typeof(TINK.Model.Services.Geolocation.LastKnownGeolocationService).FullName),
|
|||
|
new StoreMock(),
|
|||
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1)),
|
|||
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|||
|
null, // use default locks service
|
|||
|
new DeviceMock(),
|
|||
|
new SpecialFolderMock(),
|
|||
|
null, // Cipher
|
|||
|
new PermissionsMock(),
|
|||
|
#if ARENDI // Requires LockItArendi library.
|
|||
|
Substitute.For<ICentral>(),
|
|||
|
#endif
|
|||
|
isConnectedFunc: () => true,
|
|||
|
currentVersion: l_oAppVersion, // Current app version<
|
|||
|
lastVersion: l_oWhatsNewVersion); // Whats new page was never shown.
|
|||
|
|
|||
|
// Whats new page
|
|||
|
Assert.IsFalse(
|
|||
|
l_oTinkApp.WhatsNew.IsShowRequired,
|
|||
|
$"Whats new should not be displayed because app version is {l_oAppVersion} and version when \"Whats New\" was shown last is {l_oWhatsNewVersion} equals.");
|
|||
|
|
|||
|
// Call member which view model would call if Whats New would have been shonw.
|
|||
|
l_oTinkApp.SetWhatsNewWasShown();
|
|||
|
|
|||
|
// Whats new page
|
|||
|
Assert.IsFalse(
|
|||
|
l_oTinkApp.WhatsNew.IsShowRequired,
|
|||
|
$"Whats new should mot be displayed because app version is {l_oAppVersion} and version when \"Whats New\" was shown last is {l_oWhatsNewVersion} equals.");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|