mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-23 15:46:29 +01:00
1152 lines
61 KiB
C#
1152 lines
61 KiB
C#
using NUnit.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using TestTINKLib.Mocks.Connector;
|
|
using TestTINKLib.Mocks.Device;
|
|
using TestTINKLib.Mocks.Services;
|
|
using TestTINKLib.Model.User.Account;
|
|
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 Plugin.Permissions.Abstractions;
|
|
using Plugin.BLE.Abstractions.Contracts;
|
|
using TINK.Services.BluetoothLock;
|
|
using NSubstitute;
|
|
using TINK.ViewModel.BikesAtStation;
|
|
using Xamarin.Forms;
|
|
using TINK.Services.BluetoothLock.Tdo;
|
|
using Plugin.Permissions;
|
|
using TINK.Model.Services.Geolocation;
|
|
using NSubstitute.ExceptionExtensions;
|
|
using TINK.Services;
|
|
using TINK.Model.Device;
|
|
|
|
namespace TestTINKLib.Fixtures.ObjectTests.ViewModel
|
|
{
|
|
[TestFixture]
|
|
public class TestBikesAtStationPageViewModel
|
|
{
|
|
[Test]
|
|
public async Task TestConstruct_Droid_NotLoggedIn()
|
|
{
|
|
var geolocation = Substitute.For<IServicesContainer<IGeolocation>>();
|
|
var locksService = Substitute.For<ILocksService>();
|
|
var timeOut = Substitute.For<ITimeOutProvider>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var permissions = Substitute.For<IPermissions>();
|
|
var bluetooth = Substitute.For<IBluetoothLE>();
|
|
|
|
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: locksService.GetType().FullName,
|
|
activeGeolocationService: typeof(GeolocationMock).FullName),
|
|
new StoreMock(new TINK.Model.User.Account.Account("", null, null, new List<string> ())),
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.ShareeFr01_Set1, 1, sessionCookie)),
|
|
geolocation,
|
|
locksService,
|
|
new DeviceMock(),
|
|
new SpecialFolderMock(),
|
|
null, // Cipher
|
|
permissions,
|
|
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.
|
|
|
|
var bikesAtStation = new BikesAtStationPageViewModel(
|
|
tinkApp.ActiveUser,
|
|
permissions,
|
|
bluetooth,
|
|
Device.Android,
|
|
new TINK.Model.Station.Station("103", new List<string>(), null), // Station 103
|
|
() => tinkApp.GetIsConnected(),
|
|
(isConnected) => tinkApp.GetConnector(isConnected),
|
|
geolocation.Active, // geolocation
|
|
locksService,
|
|
tinkApp.Polling,
|
|
(url) => { },
|
|
(d, obj) => d(obj),
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService);
|
|
|
|
await bikesAtStation.OnAppearing();
|
|
|
|
Assert.IsEmpty(bikesAtStation.StatusInfoText);
|
|
|
|
// Verify list of bikes
|
|
Assert.AreEqual(2, bikesAtStation.Count);
|
|
Assert.IsTrue(bikesAtStation.IsIdle);
|
|
Assert.IsTrue(bikesAtStation.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
|
|
|
var bike1315 = bikesAtStation.FirstOrDefault(x => x.Id == "1315") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1543 = bikesAtStation.FirstOrDefault(x => x.Id == "1543") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
|
|
Assert.AreEqual("Available.", bike1315.StateText);
|
|
Assert.AreEqual("Available.", bike1543.StateText);
|
|
Assert.AreEqual("NotLoggedIn", bike1315.LockitButtonText);
|
|
Assert.AreEqual("NotLoggedIn", bike1543.LockitButtonText);
|
|
|
|
// Login hint/ no bikes frame
|
|
Assert.IsTrue(bikesAtStation.IsLoginRequiredHintVisible);
|
|
Assert.IsFalse(bikesAtStation.IsNoBikesAtStationVisible);
|
|
Assert.AreEqual(string.Empty, bikesAtStation.NoBikesAtStationText);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstruct_Droid_NoBikes()
|
|
{
|
|
var geolocation = Substitute.For<IServicesContainer<IGeolocation>>();
|
|
var locksService = Substitute.For<ILocksService>();
|
|
var timeOut = Substitute.For<ITimeOutProvider>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var permissions = Substitute.For<IPermissions>();
|
|
var bluetooth = Substitute.For<IBluetoothLE>();
|
|
|
|
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: locksService.GetType().FullName,
|
|
activeGeolocationService: typeof(GeolocationMock).FullName),
|
|
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH", new List<string> { "300001", "300029" })),
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.ShareeFr01_Set1, 1, sessionCookie)),
|
|
geolocation,
|
|
locksService,
|
|
new DeviceMock(),
|
|
new SpecialFolderMock(),
|
|
null, // Cipher
|
|
permissions,
|
|
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.
|
|
|
|
var bikesAtStation = new BikesAtStationPageViewModel(
|
|
tinkApp.ActiveUser,
|
|
permissions,
|
|
bluetooth,
|
|
Device.Android,
|
|
new TINK.Model.Station.Station("102", new List<string>(), null), // Station 102
|
|
() => tinkApp.GetIsConnected(),
|
|
(isConnected) => tinkApp.GetConnector(isConnected),
|
|
geolocation.Active, // geolocation
|
|
locksService,
|
|
tinkApp.Polling,
|
|
(url) => { },
|
|
(d, obj) => d(obj),
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService);
|
|
|
|
await bikesAtStation.OnAppearing();
|
|
|
|
Assert.IsEmpty(bikesAtStation.StatusInfoText);
|
|
|
|
// Verify list of bikes
|
|
Assert.AreEqual(0, bikesAtStation.Count);
|
|
Assert.IsTrue(bikesAtStation.IsIdle);
|
|
Assert.IsFalse(bikesAtStation.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
|
|
|
// Login hint/ no bikes frame
|
|
Assert.IsFalse(bikesAtStation.IsLoginRequiredHintVisible);
|
|
Assert.IsTrue(bikesAtStation.IsNoBikesAtStationVisible);
|
|
Assert.AreEqual("Momentan sind keine Fahrräder an dieser Station verfügbar.", bikesAtStation.NoBikesAtStationText);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstruct_Droid()
|
|
{
|
|
var geolocation = Substitute.For<IServicesContainer<IGeolocation>>();
|
|
var locksService = Substitute.For<ILocksService>();
|
|
var timeOut = Substitute.For<ITimeOutProvider>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var permissions = Substitute.For<IPermissions>();
|
|
var bluetooth = Substitute.For<IBluetoothLE>();
|
|
|
|
// Fake location permissions to be set
|
|
permissions.CheckPermissionStatusAsync<LocationPermission>().Returns(Task.FromResult(PermissionStatus.Granted));
|
|
geolocation.Active.IsGeolcationEnabled.Returns(true); // Fake gps to be on
|
|
bluetooth.State.Returns(BluetoothState.On); // Fake bluetooth to be on
|
|
|
|
// Fake bluetooth answer for locks with id 2200545 and 2200537.
|
|
locksService.GetLocksStateAsync(Arg.Any<IEnumerable<LockInfoAuthTdo>>(), Arg.Any<TimeSpan>()).Returns(
|
|
new List<LockInfoTdo> {
|
|
{ new LockInfoTdo.Builder { Id = 2200545, State = LockitLockingState.Open }.Build() },
|
|
{ new LockInfoTdo.Builder { Id = 2200537, State = LockitLockingState.Closed }.Build() }
|
|
}
|
|
);
|
|
|
|
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: locksService.GetType().FullName,
|
|
activeGeolocationService: typeof(GeolocationMock).FullName),
|
|
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH", new List<string> { "300001", "300029" })),
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.ShareeFr01_Set1, 1, sessionCookie)),
|
|
geolocation, // Instance geolocation mocks both parts
|
|
locksService,
|
|
new DeviceMock(),
|
|
new SpecialFolderMock(),
|
|
null, // Cipher
|
|
permissions,
|
|
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.
|
|
|
|
var bikesAtStation = new BikesAtStationPageViewModel(
|
|
tinkApp.ActiveUser,
|
|
permissions,
|
|
bluetooth,
|
|
Device.Android,
|
|
new TINK.Model.Station.Station("103", new List<string>(), null), // Station 103
|
|
() => tinkApp.GetIsConnected(),
|
|
(isConnected) => tinkApp.GetConnector(isConnected),
|
|
geolocation.Active, // geolocation
|
|
locksService,
|
|
tinkApp.Polling,
|
|
(url) => { },
|
|
(d, obj) => d(obj),
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService);
|
|
|
|
await bikesAtStation.OnAppearing();
|
|
|
|
// Verify behaviour
|
|
Received.InOrder(() =>
|
|
{
|
|
permissions.CheckPermissionStatusAsync<LocationPermission>();
|
|
var glDummy = geolocation.Active.Received().IsGeolcationEnabled;
|
|
var btDummy = bluetooth.Received().State;
|
|
locksService.GetLocksStateAsync(Arg.Any<IEnumerable<LockInfoAuthTdo>>(), Arg.Any<TimeSpan>());
|
|
});
|
|
|
|
Assert.IsEmpty(bikesAtStation.StatusInfoText);
|
|
|
|
// Verify list of bikes
|
|
Assert.AreEqual(4, bikesAtStation.Count);
|
|
Assert.IsTrue(bikesAtStation.IsIdle);
|
|
Assert.IsTrue(bikesAtStation.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
|
|
|
var bike1545 = bikesAtStation.FirstOrDefault(x => x.Id == "1545") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1537 = bikesAtStation.FirstOrDefault(x => x.Id == "1537") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1315 = bikesAtStation.FirstOrDefault(x => x.Id == "1315") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1543 = bikesAtStation.FirstOrDefault(x => x.Id == "1543") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
|
|
Assert.AreEqual("Rented since 06. November 17:53.", bike1545.StateText);
|
|
Assert.AreEqual("Rented since 12. October 08:38.", bike1537.StateText);
|
|
Assert.AreEqual("Available.", bike1315.StateText);
|
|
Assert.AreEqual("Available.", bike1543.StateText);
|
|
Assert.AreEqual("Close lock", bike1545.LockitButtonText);
|
|
Assert.AreEqual("Open lock & continue renting", bike1537.LockitButtonText);
|
|
Assert.AreEqual("DisposableDisconnected", bike1315.LockitButtonText);
|
|
Assert.AreEqual("DisposableDisconnected", bike1543.LockitButtonText);
|
|
|
|
// Login hint/ no bikes frame
|
|
Assert.IsFalse(bikesAtStation.IsLoginRequiredHintVisible);
|
|
Assert.IsFalse(bikesAtStation.IsNoBikesAtStationVisible);
|
|
Assert.AreEqual(string.Empty, bikesAtStation.NoBikesAtStationText);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstruct_Droid_NoPermissions_OpenSettings()
|
|
{
|
|
var geolocation = Substitute.For<IServicesContainer<IGeolocation>>();
|
|
var locksService = Substitute.For<ILocksService>();
|
|
var timeOut = Substitute.For<ITimeOutProvider>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var permissions = Substitute.For<IPermissions>();
|
|
var bluetooth = Substitute.For<IBluetoothLE>();
|
|
|
|
// Fake location permissions not to be set
|
|
permissions.CheckPermissionStatusAsync<LocationPermission>().Returns(Task.FromResult(PermissionStatus.Denied));
|
|
|
|
// Fake anwser on question whether to open permissions dialog
|
|
viewService.DisplayAlert(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>()).Returns(true);
|
|
|
|
// Fake bluetooth answer for locks with id 2200545 and 2200537.
|
|
locksService.GetLocksStateAsync(Arg.Any<IEnumerable<LockInfoAuthTdo>>(), Arg.Any<TimeSpan>()).Returns(
|
|
new List<LockInfoTdo> {
|
|
{ new LockInfoTdo.Builder { Id = 2200545, State = LockitLockingState.Open }.Build() },
|
|
{ new LockInfoTdo.Builder { Id = 2200537, State = LockitLockingState.Closed }.Build() }
|
|
}
|
|
);
|
|
|
|
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: locksService.GetType().FullName,
|
|
activeGeolocationService: typeof(GeolocationMock).FullName),
|
|
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH", new List<string> { "300001", "300029" })),
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.ShareeFr01_Set1, 1, sessionCookie)),
|
|
geolocation,
|
|
locksService,
|
|
new DeviceMock(),
|
|
new SpecialFolderMock(),
|
|
null, // Cipher
|
|
permissions,
|
|
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.
|
|
|
|
var bikesAtStation = new BikesAtStationPageViewModel(
|
|
tinkApp.ActiveUser,
|
|
permissions,
|
|
bluetooth,
|
|
Device.Android,
|
|
new TINK.Model.Station.Station("103", new List<string>(), null), // Station 103
|
|
() => tinkApp.GetIsConnected(),
|
|
(isConnected) => tinkApp.GetConnector(isConnected),
|
|
geolocation.Active, // geolocation
|
|
locksService,
|
|
tinkApp.Polling,
|
|
(url) => { },
|
|
(d, obj) => d(obj),
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService);
|
|
|
|
await bikesAtStation.OnAppearing();
|
|
|
|
// Verify behaviour
|
|
Received.InOrder(() =>
|
|
{
|
|
permissions.CheckPermissionStatusAsync<LocationPermission>();
|
|
var glDummy = geolocation.Active.Received().IsGeolcationEnabled;
|
|
permissions.RequestPermissionAsync<LocationPermission>(); // Ask user from permissions.
|
|
viewService.DisplayAlert(
|
|
"Hint",
|
|
"Please allow location sharing so that bike lock/locks can be managed.\r\nOpen sharing dialog?",
|
|
"Yes",
|
|
"No");
|
|
permissions.OpenAppSettings();
|
|
});
|
|
|
|
Assert.IsEmpty(bikesAtStation.StatusInfoText);
|
|
|
|
// Verify list of bikes
|
|
Assert.AreEqual(4, bikesAtStation.Count);
|
|
Assert.IsTrue(bikesAtStation.IsIdle);
|
|
Assert.IsTrue(bikesAtStation.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
|
|
|
var bike1545 = bikesAtStation.FirstOrDefault(x => x.Id == "1545") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1537 = bikesAtStation.FirstOrDefault(x => x.Id == "1537") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1315 = bikesAtStation.FirstOrDefault(x => x.Id == "1315") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1543 = bikesAtStation.FirstOrDefault(x => x.Id == "1543") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
|
|
Assert.AreEqual("Rented since 06. November 17:53.", bike1545.StateText);
|
|
Assert.AreEqual("Rented since 12. October 08:38.", bike1537.StateText);
|
|
Assert.AreEqual("Available.", bike1315.StateText);
|
|
Assert.AreEqual("Available.", bike1543.StateText);
|
|
Assert.AreEqual("Search lock", bike1545.LockitButtonText);
|
|
Assert.AreEqual("Search lock", bike1537.LockitButtonText);
|
|
Assert.AreEqual("DisposableDisconnected", bike1315.LockitButtonText);
|
|
Assert.AreEqual("DisposableDisconnected", bike1543.LockitButtonText);
|
|
|
|
// Login hint/ no bikes frame
|
|
Assert.IsFalse(bikesAtStation.IsLoginRequiredHintVisible);
|
|
Assert.IsFalse(bikesAtStation.IsNoBikesAtStationVisible);
|
|
Assert.AreEqual(string.Empty, bikesAtStation.NoBikesAtStationText);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstruct_Droid_NoPermissions()
|
|
{
|
|
var geolocation = Substitute.For<IServicesContainer<IGeolocation>>();
|
|
var locksService = Substitute.For<ILocksService>();
|
|
var timeOut = Substitute.For<ITimeOutProvider>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var permissions = Substitute.For<IPermissions>();
|
|
var bluetooth = Substitute.For<IBluetoothLE>();
|
|
|
|
// Fake location permissions not to be set
|
|
permissions.CheckPermissionStatusAsync<LocationPermission>().Returns(Task.FromResult(PermissionStatus.Denied));
|
|
permissions.OpenAppSettings().Throws<Exception>(); // Ensures that method is not called and fixture succeeds.
|
|
|
|
// Fake anwser on question whether to open permissions dialog
|
|
viewService.DisplayAlert(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>()).Returns(false);
|
|
|
|
// Fake bluetooth answer for locks with id 2200545 and 2200537.
|
|
locksService.GetLocksStateAsync(Arg.Any<IEnumerable<LockInfoAuthTdo>>(), Arg.Any<TimeSpan>()).Returns(
|
|
new List<LockInfoTdo> {
|
|
{ new LockInfoTdo.Builder { Id = 2200545, State = LockitLockingState.Open }.Build() },
|
|
{ new LockInfoTdo.Builder { Id = 2200537, State = LockitLockingState.Closed }.Build() }
|
|
}
|
|
);
|
|
|
|
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: locksService.GetType().FullName,
|
|
activeGeolocationService: typeof(GeolocationMock).FullName),
|
|
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH", new List<string> { "300001", "300029" })),
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.ShareeFr01_Set1, 1, sessionCookie)),
|
|
geolocation,
|
|
locksService,
|
|
new DeviceMock(),
|
|
new SpecialFolderMock(),
|
|
null, // Cipher
|
|
permissions,
|
|
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.
|
|
|
|
var bikesAtStation = new BikesAtStationPageViewModel(
|
|
tinkApp.ActiveUser,
|
|
permissions,
|
|
bluetooth,
|
|
Device.Android,
|
|
new TINK.Model.Station.Station("103", new List<string>(), null), // Station 103
|
|
() => tinkApp.GetIsConnected(),
|
|
(isConnected) => tinkApp.GetConnector(isConnected),
|
|
geolocation.Active, // geolocation
|
|
locksService,
|
|
tinkApp.Polling,
|
|
(url) => { },
|
|
(d, obj) => d(obj),
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService);
|
|
|
|
await bikesAtStation.OnAppearing();
|
|
|
|
// Verify behaviour
|
|
Received.InOrder(() =>
|
|
{
|
|
permissions.CheckPermissionStatusAsync<LocationPermission>();
|
|
var glDummy = geolocation.Active.Received().IsGeolcationEnabled;
|
|
permissions.RequestPermissionAsync<LocationPermission>(); // Ask user from permissions.
|
|
viewService.DisplayAlert(
|
|
"Hint",
|
|
"Please allow location sharing so that bike lock/locks can be managed.\r\nOpen sharing dialog?",
|
|
"Yes",
|
|
"No");
|
|
});
|
|
|
|
Assert.IsEmpty(bikesAtStation.StatusInfoText);
|
|
|
|
// Verify list of bikes
|
|
Assert.AreEqual(4, bikesAtStation.Count);
|
|
Assert.IsTrue(bikesAtStation.IsIdle);
|
|
Assert.IsTrue(bikesAtStation.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
|
|
|
var bike1545 = bikesAtStation.FirstOrDefault(x => x.Id == "1545") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1537 = bikesAtStation.FirstOrDefault(x => x.Id == "1537") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1315 = bikesAtStation.FirstOrDefault(x => x.Id == "1315") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1543 = bikesAtStation.FirstOrDefault(x => x.Id == "1543") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
|
|
Assert.AreEqual("Rented since 06. November 17:53.", bike1545.StateText);
|
|
Assert.AreEqual("Rented since 12. October 08:38.", bike1537.StateText);
|
|
Assert.AreEqual("Available.", bike1315.StateText);
|
|
Assert.AreEqual("Available.", bike1543.StateText);
|
|
Assert.AreEqual("Search lock", bike1545.LockitButtonText);
|
|
Assert.AreEqual("Search lock", bike1537.LockitButtonText);
|
|
Assert.AreEqual("DisposableDisconnected", bike1315.LockitButtonText);
|
|
Assert.AreEqual("DisposableDisconnected", bike1543.LockitButtonText);
|
|
|
|
// Login hint/ no bikes frame
|
|
Assert.IsFalse(bikesAtStation.IsLoginRequiredHintVisible);
|
|
Assert.IsFalse(bikesAtStation.IsNoBikesAtStationVisible);
|
|
Assert.AreEqual(string.Empty, bikesAtStation.NoBikesAtStationText);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstruct_Droid_GeolocationOff()
|
|
{
|
|
var geolocation = Substitute.For<IServicesContainer<IGeolocation>>();
|
|
var locksService = Substitute.For<ILocksService>();
|
|
var timeOut = Substitute.For<ITimeOutProvider>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var permissions = Substitute.For<IPermissions>();
|
|
var bluetooth = Substitute.For<IBluetoothLE>();
|
|
|
|
// Fake location permissions to be set
|
|
permissions.CheckPermissionStatusAsync<LocationPermission>().Returns(Task.FromResult(PermissionStatus.Granted));
|
|
geolocation.Active.IsGeolcationEnabled.Returns(false); // Fake gps to be off
|
|
bluetooth.State.Returns(BluetoothState.On); // Fake bluetooth to be on
|
|
|
|
// Fake bluetooth answer for locks with id 2200545 and 2200537.
|
|
locksService.GetLocksStateAsync(Arg.Any<IEnumerable<LockInfoAuthTdo>>(), Arg.Any<TimeSpan>()).Returns(
|
|
new List<LockInfoTdo> {
|
|
{ new LockInfoTdo.Builder { Id = 2200545, State = LockitLockingState.Open }.Build() },
|
|
{ new LockInfoTdo.Builder { Id = 2200537, State = LockitLockingState.Closed }.Build() }
|
|
}
|
|
);
|
|
|
|
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: locksService.GetType().FullName,
|
|
activeGeolocationService: typeof(GeolocationMock).FullName),
|
|
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH", new List<string> { "300001", "300029" })),
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.ShareeFr01_Set1, 1, sessionCookie)),
|
|
geolocation,
|
|
locksService,
|
|
new DeviceMock(),
|
|
new SpecialFolderMock(),
|
|
null, // Cipher
|
|
permissions,
|
|
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.
|
|
|
|
var bikesAtStation = new BikesAtStationPageViewModel(
|
|
tinkApp.ActiveUser,
|
|
permissions,
|
|
bluetooth,
|
|
Device.Android,
|
|
new TINK.Model.Station.Station("103", new List<string>(), null), // Station 103
|
|
() => tinkApp.GetIsConnected(),
|
|
(isConnected) => tinkApp.GetConnector(isConnected),
|
|
geolocation.Active, // geolocation
|
|
locksService,
|
|
tinkApp.Polling,
|
|
(url) => { },
|
|
(d, obj) => d(obj),
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService);
|
|
|
|
await bikesAtStation.OnAppearing();
|
|
|
|
// Verify behaviour
|
|
Received.InOrder(() =>
|
|
{
|
|
permissions.CheckPermissionStatusAsync<LocationPermission>();
|
|
var glDummy = geolocation.Active.Received().IsGeolcationEnabled;
|
|
viewService.DisplayAlert(
|
|
"Hint",
|
|
"Please activate location so that bike lock can be found!",
|
|
"OK");
|
|
});
|
|
|
|
Assert.IsEmpty(bikesAtStation.StatusInfoText);
|
|
|
|
// Verify list of bikes
|
|
Assert.AreEqual(4, bikesAtStation.Count);
|
|
Assert.IsTrue(bikesAtStation.IsIdle);
|
|
Assert.IsTrue(bikesAtStation.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
|
|
|
var bike1545 = bikesAtStation.FirstOrDefault(x => x.Id == "1545") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1537 = bikesAtStation.FirstOrDefault(x => x.Id == "1537") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1315 = bikesAtStation.FirstOrDefault(x => x.Id == "1315") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1543 = bikesAtStation.FirstOrDefault(x => x.Id == "1543") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
|
|
Assert.AreEqual("Rented since 06. November 17:53.", bike1545.StateText);
|
|
Assert.AreEqual("Rented since 12. October 08:38.", bike1537.StateText);
|
|
Assert.AreEqual("Available.", bike1315.StateText);
|
|
Assert.AreEqual("Available.", bike1543.StateText);
|
|
Assert.AreEqual("Search lock", bike1545.LockitButtonText);
|
|
Assert.AreEqual("Search lock", bike1537.LockitButtonText);
|
|
Assert.AreEqual("DisposableDisconnected", bike1315.LockitButtonText);
|
|
Assert.AreEqual("DisposableDisconnected", bike1543.LockitButtonText);
|
|
|
|
// Login hint/ no bikes frame
|
|
Assert.IsFalse(bikesAtStation.IsLoginRequiredHintVisible);
|
|
Assert.IsFalse(bikesAtStation.IsNoBikesAtStationVisible);
|
|
Assert.AreEqual(string.Empty, bikesAtStation.NoBikesAtStationText);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstruct_Droid_BluetoothOff()
|
|
{
|
|
var geolocation = Substitute.For<IServicesContainer<IGeolocation>>();
|
|
var locksService = Substitute.For<ILocksService>();
|
|
var timeOut = Substitute.For<ITimeOutProvider>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var permissions = Substitute.For<IPermissions>();
|
|
var bluetooth = Substitute.For<IBluetoothLE>();
|
|
|
|
// Fake location permissions to be set
|
|
permissions.CheckPermissionStatusAsync<LocationPermission>().Returns(Task.FromResult(PermissionStatus.Granted));
|
|
geolocation.Active.IsGeolcationEnabled.Returns(true); // Fake gps to be on
|
|
bluetooth.State.Returns(BluetoothState.Off); // // Fake bluetooth to be off
|
|
|
|
// Fake bluetooth answer for locks with id 2200545 and 2200537.
|
|
locksService.GetLocksStateAsync(Arg.Any<IEnumerable<LockInfoAuthTdo>>(), Arg.Any<TimeSpan>()).Returns(
|
|
new List<LockInfoTdo> {
|
|
{ new LockInfoTdo.Builder { Id = 2200545, State = LockitLockingState.Open }.Build() },
|
|
{ new LockInfoTdo.Builder { Id = 2200537, State = LockitLockingState.Closed }.Build() }
|
|
}
|
|
);
|
|
|
|
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: locksService.GetType().FullName,
|
|
activeGeolocationService: typeof(GeolocationMock).FullName),
|
|
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH", new List<string> { "300001", "300029" })),
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.ShareeFr01_Set1, 1, sessionCookie)),
|
|
geolocation,
|
|
locksService,
|
|
new DeviceMock(),
|
|
new SpecialFolderMock(),
|
|
null, // Cipher
|
|
permissions,
|
|
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.
|
|
|
|
var bikesAtStation = new BikesAtStationPageViewModel(
|
|
tinkApp.ActiveUser,
|
|
permissions,
|
|
bluetooth,
|
|
Device.Android,
|
|
new TINK.Model.Station.Station("103", new List<string>(), null), // Station 103
|
|
() => tinkApp.GetIsConnected(),
|
|
(isConnected) => tinkApp.GetConnector(isConnected),
|
|
geolocation.Active, // geolocation
|
|
locksService,
|
|
tinkApp.Polling,
|
|
(url) => { },
|
|
(d, obj) => d(obj),
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService);
|
|
|
|
await bikesAtStation.OnAppearing();
|
|
|
|
// Verify behaviour
|
|
Received.InOrder(() =>
|
|
{
|
|
permissions.CheckPermissionStatusAsync<LocationPermission>();
|
|
var glDummy = geolocation.Active.Received().IsGeolcationEnabled;
|
|
var btDummy = bluetooth.Received().State;
|
|
viewService.DisplayAlert(
|
|
"Hint",
|
|
"Please enable Bluetooth to manage bike lock/locks.",
|
|
"OK");
|
|
});
|
|
|
|
Assert.IsEmpty(bikesAtStation.StatusInfoText);
|
|
|
|
// Verify list of bikes
|
|
Assert.AreEqual(4, bikesAtStation.Count);
|
|
Assert.IsTrue(bikesAtStation.IsIdle);
|
|
Assert.IsTrue(bikesAtStation.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
|
|
|
var bike1545 = bikesAtStation.FirstOrDefault(x => x.Id == "1545") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1537 = bikesAtStation.FirstOrDefault(x => x.Id == "1537") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1315 = bikesAtStation.FirstOrDefault(x => x.Id == "1315") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
var bike1543 = bikesAtStation.FirstOrDefault(x => x.Id == "1543") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
|
|
|
Assert.AreEqual("Rented since 06. November 17:53.", bike1545.StateText);
|
|
Assert.AreEqual("Rented since 12. October 08:38.", bike1537.StateText);
|
|
Assert.AreEqual("Available.", bike1315.StateText);
|
|
Assert.AreEqual("Available.", bike1543.StateText);
|
|
Assert.AreEqual("Search lock", bike1545.LockitButtonText);
|
|
Assert.AreEqual("Search lock", bike1537.LockitButtonText);
|
|
Assert.AreEqual("DisposableDisconnected", bike1315.LockitButtonText);
|
|
Assert.AreEqual("DisposableDisconnected", bike1543.LockitButtonText);
|
|
|
|
// Login hint/ no bikes frame
|
|
Assert.IsFalse(bikesAtStation.IsLoginRequiredHintVisible);
|
|
Assert.IsFalse(bikesAtStation.IsNoBikesAtStationVisible);
|
|
Assert.AreEqual(string.Empty, bikesAtStation.NoBikesAtStationText);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstructKonrad()
|
|
{
|
|
var locksService = Substitute.For<ILocksService>();
|
|
var timeOut = Substitute.For<ITimeOutProvider>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var permissions = Substitute.For<IPermissions>();
|
|
var bluetooth = Substitute.For<IBluetoothLE>();
|
|
|
|
bluetooth.State.Returns(BluetoothState.On);
|
|
|
|
locksService.TimeOut.Returns(timeOut);
|
|
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
|
|
|
var tinkApp = new TinkApp(
|
|
new TINK.Model.Settings.Settings(
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.Off }, { "Konrad", 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: locksService.GetType().FullName,
|
|
activeGeolocationService: typeof(GeolocationMock).FullName),
|
|
new StoreMock(),
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)),
|
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
locksService,
|
|
new DeviceMock(),
|
|
new SpecialFolderMock(),
|
|
null, // Cipher
|
|
new PermissionsMock(),
|
|
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.
|
|
|
|
var bikesAtStation = new BikesAtStationPageViewModel(
|
|
tinkApp.ActiveUser,
|
|
permissions,
|
|
bluetooth,
|
|
Device.iOS,
|
|
new TINK.Model.Station.Station("31", new List<string>(), null),
|
|
() => tinkApp.GetIsConnected(),
|
|
(isConnected) => tinkApp.GetConnector(isConnected),
|
|
new GeolocationMock(),
|
|
locksService,
|
|
tinkApp.Polling,
|
|
(url) => { },
|
|
(d, obj) => d(obj),
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService);
|
|
|
|
await bikesAtStation.OnAppearing();
|
|
|
|
Assert.IsTrue(new List<string> { "Updating...", string.Empty }.Contains(bikesAtStation.StatusInfoText));
|
|
|
|
// Verify list of bikes
|
|
Assert.AreEqual(1, bikesAtStation.Count);
|
|
Assert.IsTrue(bikesAtStation.IsIdle);
|
|
Assert.IsTrue(bikesAtStation.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
|
|
|
Assert.AreEqual("Available.", bikesAtStation.FirstOrDefault(x => x.Id == "52").StateText);
|
|
|
|
// Login hint/ no bikes frame
|
|
Assert.IsTrue(bikesAtStation.IsLoginRequiredHintVisible);
|
|
Assert.IsFalse(bikesAtStation.IsNoBikesAtStationVisible);
|
|
Assert.AreEqual(string.Empty, bikesAtStation.NoBikesAtStationText);
|
|
}
|
|
|
|
|
|
[Test]
|
|
public async Task TestConstructKonrad_NoBikes()
|
|
{
|
|
var locksService = Substitute.For<ILocksService>();
|
|
var timeOut = Substitute.For<ITimeOutProvider>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var permissions = Substitute.For<IPermissions>();
|
|
var bluetooth = Substitute.For<IBluetoothLE>();
|
|
|
|
bluetooth.State.Returns(BluetoothState.On);
|
|
|
|
locksService.TimeOut.Returns(timeOut);
|
|
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
|
|
|
var tinkApp = new TinkApp(
|
|
new TINK.Model.Settings.Settings(
|
|
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.Off }, { "Konrad", 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: locksService.GetType().FullName,
|
|
activeGeolocationService: typeof(GeolocationMock).FullName),
|
|
new StoreMock(),
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)),
|
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
locksService,
|
|
new DeviceMock(),
|
|
new SpecialFolderMock(),
|
|
null, // Cipher
|
|
new PermissionsMock(),
|
|
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.
|
|
|
|
var bikesAtStation = new BikesAtStationPageViewModel(
|
|
tinkApp.ActiveUser,
|
|
permissions,
|
|
bluetooth,
|
|
Device.iOS,
|
|
new TINK.Model.Station.Station("4", new List<string>(), null),
|
|
() => tinkApp.GetIsConnected(),
|
|
(isConnected) => tinkApp.GetConnector(isConnected),
|
|
new GeolocationMock(),
|
|
locksService,
|
|
tinkApp.Polling,
|
|
(url) => { },
|
|
(d, obj) => d(obj),
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService);
|
|
|
|
await bikesAtStation.OnAppearing();
|
|
|
|
Assert.IsTrue(new List<string> { "Updating...", string.Empty }.Contains(bikesAtStation.StatusInfoText));
|
|
|
|
// Verify list of bikes
|
|
Assert.AreEqual(0, bikesAtStation.Count);
|
|
Assert.IsTrue(bikesAtStation.IsIdle);
|
|
Assert.IsFalse(bikesAtStation.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
|
|
|
// Login hint/ no bikes frame
|
|
Assert.IsFalse(bikesAtStation.IsLoginRequiredHintVisible);
|
|
Assert.IsTrue(bikesAtStation.IsNoBikesAtStationVisible);
|
|
Assert.AreEqual("Momentan sind keine Fahrräder an dieser Station verfügbar.", bikesAtStation.NoBikesAtStationText);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstruct_LoggedIn()
|
|
{
|
|
var locksService = Substitute.For<ILocksService>();
|
|
var timeOut = Substitute.For<ITimeOutProvider>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var permissions = Substitute.For<IPermissions>();
|
|
var bluetooth = Substitute.For<IBluetoothLE>();
|
|
|
|
bluetooth.State.Returns(BluetoothState.On);
|
|
|
|
locksService.TimeOut.Returns(timeOut);
|
|
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
|
|
|
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: locksService.GetType().FullName,
|
|
activeGeolocationService: locksService.GetType().FullName),
|
|
new StoreMock(new TINK.Model.User.Account.Account(
|
|
LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
|
LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
|
"4da3044c8657a04ba60e2eaa753bc51a",
|
|
new List<string> { "TINK" })),
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)),
|
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
locksService,
|
|
new DeviceMock(),
|
|
new SpecialFolderMock(),
|
|
null, // Cipher
|
|
new PermissionsMock(),
|
|
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.
|
|
|
|
var bikesAtStation = new BikesAtStationPageViewModel(
|
|
tinkApp.ActiveUser,
|
|
permissions,
|
|
bluetooth,
|
|
Device.iOS,
|
|
new TINK.Model.Station.Station("4", new List<string>(), null),
|
|
() => tinkApp.GetIsConnected(),
|
|
(isConnected) => tinkApp.GetConnector(isConnected),
|
|
new GeolocationMock(),
|
|
locksService,
|
|
tinkApp.Polling,
|
|
(url) => { },
|
|
(d, obj) => d(obj),
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService);
|
|
|
|
await bikesAtStation.OnAppearing();
|
|
|
|
Assert.IsTrue(new List<string> { "Updating...", string.Empty }.Contains(bikesAtStation.StatusInfoText));
|
|
|
|
// Verify list of bikes
|
|
Assert.AreEqual(4, bikesAtStation.Count);
|
|
Assert.IsTrue(bikesAtStation.IsIdle);
|
|
Assert.IsTrue(bikesAtStation.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
|
|
|
Assert.AreEqual("Available.", bikesAtStation.FirstOrDefault(x => x.Id == "5").StateText);
|
|
Assert.AreEqual("Available.", bikesAtStation.FirstOrDefault(x => x.Id == "14").StateText);
|
|
Assert.AreEqual("Available.", bikesAtStation.FirstOrDefault(x => x.Id == "26").StateText);
|
|
Assert.AreEqual("Code 2931, rented since 28. November 13:06.", bikesAtStation.FirstOrDefault(x => x.Id == "7").StateText);
|
|
|
|
// Login hint/ no bikes frame
|
|
Assert.IsFalse(bikesAtStation.IsLoginRequiredHintVisible);
|
|
Assert.IsFalse(bikesAtStation.IsNoBikesAtStationVisible);
|
|
Assert.AreEqual(string.Empty, bikesAtStation.NoBikesAtStationText);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstruct_Offline()
|
|
{
|
|
var locksService = Substitute.For<ILocksService>();
|
|
var timeOut = Substitute.For<ITimeOutProvider>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var permissions = Substitute.For<IPermissions>();
|
|
var bluetooth = Substitute.For<IBluetoothLE>();
|
|
|
|
bluetooth.State.Returns(BluetoothState.On);
|
|
|
|
locksService.TimeOut.Returns(timeOut);
|
|
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
|
|
|
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: locksService.GetType().FullName,
|
|
activeGeolocationService: typeof(GeolocationMock).FullName),
|
|
new StoreMock(),
|
|
(isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)),
|
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
locksService,
|
|
new DeviceMock(),
|
|
new SpecialFolderMock(),
|
|
null, // Cipher
|
|
new PermissionsMock(),
|
|
isConnectedFunc: () => false, // Not connected.
|
|
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 bikesAtStation = new BikesAtStationPageViewModel(
|
|
tinkApp.ActiveUser,
|
|
permissions,
|
|
bluetooth,
|
|
Device.iOS,
|
|
new TINK.Model.Station.Station("4", new List<string>(), null),
|
|
() => tinkApp.GetIsConnected(),
|
|
(isConnected) => tinkApp.GetConnector(isConnected),
|
|
new GeolocationMock(),
|
|
locksService,
|
|
tinkApp.Polling,
|
|
(url) => { },
|
|
(d, obj) => d(obj),
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService);
|
|
|
|
await bikesAtStation.OnAppearing();
|
|
|
|
Assert.AreEqual("Offline.", bikesAtStation.StatusInfoText);
|
|
|
|
// Verify list of bikes
|
|
Assert.AreEqual(3, bikesAtStation.Count);
|
|
Assert.IsTrue(bikesAtStation.IsIdle);
|
|
Assert.IsTrue(bikesAtStation.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
|
|
|
Assert.AreEqual("Available.", bikesAtStation.FirstOrDefault(x => x.Id == "5").StateText);
|
|
Assert.AreEqual("Available.", bikesAtStation.FirstOrDefault(x => x.Id == "14").StateText);
|
|
Assert.AreEqual("Available.", bikesAtStation.FirstOrDefault(x => x.Id == "26").StateText);
|
|
|
|
// Login hint/ no bikes frame
|
|
Assert.IsTrue(bikesAtStation.IsLoginRequiredHintVisible);
|
|
Assert.IsFalse(bikesAtStation.IsNoBikesAtStationVisible);
|
|
Assert.AreEqual(string.Empty, bikesAtStation.NoBikesAtStationText);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestConstruct_WebConnectCommunicationError()
|
|
{
|
|
var locksService = Substitute.For<ILocksService>();
|
|
var timeOut = Substitute.For<ITimeOutProvider>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var permissions = Substitute.For<IPermissions>();
|
|
var bluetooth = Substitute.For<IBluetoothLE>();
|
|
|
|
bluetooth.State.Returns(BluetoothState.On);
|
|
|
|
locksService.TimeOut.Returns(timeOut);
|
|
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
|
|
|
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: locksService.GetType().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,
|
|
cacheServer: new CopriCallsCacheMemory(sessionCookie: sessionCookie),
|
|
httpsServer: new ExceptionServer((msg) => new WebConnectFailureException(msg, new Exception("Source expection."))))),
|
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
locksService,
|
|
new DeviceMock(),
|
|
new SpecialFolderMock(),
|
|
null, // Cipher
|
|
new PermissionsMock(),
|
|
isConnectedFunc: () => false, // Not connected.
|
|
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 bikesAtStation = new BikesAtStationPageViewModel(
|
|
tinkApp.ActiveUser,
|
|
permissions,
|
|
bluetooth,
|
|
Device.iOS,
|
|
new TINK.Model.Station.Station("4", new List<string>(), null),
|
|
() => tinkApp.GetIsConnected(),
|
|
(isConnected) => tinkApp.GetConnector(isConnected),
|
|
new GeolocationMock(),
|
|
locksService,
|
|
tinkApp.Polling,
|
|
(url) => { },
|
|
(d, obj) => d(obj),
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService)
|
|
{
|
|
IsReportLevelVerbose = true
|
|
};
|
|
|
|
await bikesAtStation.OnAppearing();
|
|
|
|
Assert.AreEqual("Connection interrupted, server unreachable.", bikesAtStation.StatusInfoText);
|
|
|
|
// Verify list of bikes
|
|
Assert.AreEqual(3, bikesAtStation.Count);
|
|
Assert.IsTrue(bikesAtStation.IsIdle);
|
|
Assert.IsTrue(bikesAtStation.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
|
|
|
Assert.AreEqual("Available.", bikesAtStation.FirstOrDefault(x => x.Id == "5").StateText);
|
|
Assert.AreEqual("Available.", bikesAtStation.FirstOrDefault(x => x.Id == "14").StateText);
|
|
Assert.AreEqual("Available.", bikesAtStation.FirstOrDefault(x => x.Id == "26").StateText);
|
|
|
|
// Login hint/ no bikes frame
|
|
Assert.IsTrue(bikesAtStation.IsLoginRequiredHintVisible);
|
|
Assert.IsFalse(bikesAtStation.IsNoBikesAtStationVisible);
|
|
Assert.AreEqual(string.Empty, bikesAtStation.NoBikesAtStationText);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestTinkApp_GeneralPurposeError()
|
|
{
|
|
var locksService = Substitute.For<ILocksService>();
|
|
var timeOut = Substitute.For<ITimeOutProvider>();
|
|
var viewService = Substitute.For<IViewService>();
|
|
var permissions = Substitute.For<IPermissions>();
|
|
var bluetooth = Substitute.For<IBluetoothLE>();
|
|
|
|
bluetooth.State.Returns(BluetoothState.On);
|
|
|
|
locksService.TimeOut.Returns(timeOut);
|
|
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
|
|
|
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: locksService.GetType().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,
|
|
cacheServer: new CopriCallsCacheMemory(sessionCookie: sessionCookie),
|
|
httpsServer: new ExceptionServer((msg) => new Exception(msg)))),
|
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|
locksService,
|
|
new DeviceMock(),
|
|
new SpecialFolderMock(),
|
|
null, // Cipher
|
|
new PermissionsMock(),
|
|
isConnectedFunc: () => false, // Not connected.
|
|
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 bikesAtStation = new BikesAtStationPageViewModel(
|
|
tinkApp.ActiveUser,
|
|
permissions,
|
|
bluetooth,
|
|
Device.iOS,
|
|
new TINK.Model.Station.Station("4", new List<string>(), null),
|
|
() => tinkApp.GetIsConnected(),
|
|
(isConnected) => tinkApp.GetConnector(isConnected),
|
|
new GeolocationMock(),
|
|
locksService,
|
|
tinkApp.Polling,
|
|
(url) => { },
|
|
(d, obj) => d(obj),
|
|
Substitute.For<ISmartDevice>(),
|
|
viewService)
|
|
{
|
|
IsReportLevelVerbose = true
|
|
};
|
|
|
|
await bikesAtStation.OnAppearing();
|
|
|
|
Assert.AreEqual("Connection interrupted.", bikesAtStation.StatusInfoText);
|
|
|
|
// Verify list of bikes
|
|
Assert.AreEqual(3, bikesAtStation.Count);
|
|
Assert.IsTrue(bikesAtStation.IsIdle);
|
|
Assert.IsTrue(bikesAtStation.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
|
|
|
Assert.AreEqual("Available.", bikesAtStation.FirstOrDefault(x => x.Id == "5").StateText);
|
|
Assert.AreEqual("Available.", bikesAtStation.FirstOrDefault(x => x.Id == "14").StateText);
|
|
Assert.AreEqual("Available.", bikesAtStation.FirstOrDefault(x => x.Id == "26").StateText);
|
|
|
|
// Login hint/ no bikes frame
|
|
Assert.IsTrue(bikesAtStation.IsLoginRequiredHintVisible);
|
|
Assert.IsFalse(bikesAtStation.IsNoBikesAtStationVisible);
|
|
Assert.AreEqual(string.Empty, bikesAtStation.NoBikesAtStationText);
|
|
}
|
|
}
|
|
}
|