2022-10-17 18:45:38 +02:00
using System ;
2021-07-12 21:31:46 +02:00
using System.Collections.Generic ;
using System.Linq ;
using System.Threading.Tasks ;
2022-08-30 15:42:25 +02:00
using NSubstitute ;
using NSubstitute.ExceptionExtensions ;
using NUnit.Framework ;
using Plugin.BLE.Abstractions.Contracts ;
2022-01-04 18:59:16 +01:00
using TestFramework.Model.Device ;
using TestFramework.Model.Services.Geolocation ;
using TestFramework.Model.User.Account ;
using TestFramework.Repository ;
using TestFramework.Services.CopriApi.Connector ;
2021-07-12 21:31:46 +02:00
using TINK.Model ;
using TINK.Model.Connector ;
2022-01-04 18:59:16 +01:00
using TINK.Model.Device ;
2021-07-12 21:31:46 +02:00
using TINK.Model.Services.CopriApi ;
2022-10-17 18:45:38 +02:00
using TINK.Model.Settings ;
2021-07-12 21:31:46 +02:00
using TINK.Repository ;
2022-01-04 18:59:16 +01:00
using TINK.Repository.Exception ;
using TINK.Services ;
2021-07-12 21:31:46 +02:00
using TINK.Services.BluetoothLock ;
using TINK.Services.BluetoothLock.Tdo ;
2022-08-30 15:42:25 +02:00
using TINK.Services.Geolocation ;
2021-11-07 19:42:59 +01:00
using TINK.Services.Permissions ;
2022-01-04 18:59:16 +01:00
using TINK.View ;
using TINK.ViewModel.BikesAtStation ;
using TINK.ViewModel.Map ;
using TINK.ViewModel.Settings ;
using Xamarin.Forms ;
using static TINK . Repository . CopriCallsMemory ;
2021-07-12 21:31:46 +02:00
namespace TestTINKLib.Fixtures.ObjectTests.ViewModel
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestBikesAtStationPageViewModel
{
[Test]
public async Task TestConstruct_Droid_NotLoggedIn ( )
{
2023-04-05 15:02:10 +02:00
var geolocation = Substitute . For < IServicesContainer < IGeolocationService > > ( ) ;
2022-09-06 16:08:19 +02:00
var locksService = Substitute . For < ILocksService > ( ) ;
var timeOut = Substitute . For < ITimeOutProvider > ( ) ;
var viewService = Substitute . For < IViewService > ( ) ;
var permissions = Substitute . For < ILocationPermission > ( ) ;
var bluetooth = Substitute . For < IBluetoothLE > ( ) ;
var tinkApp = new TinkApp (
2022-10-17 18:45:38 +02:00
new Settings (
2022-09-06 16:08:19 +02:00
new GroupFilterMapPage ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . Off } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
new GroupFilterSettings ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
2022-10-17 18:45:38 +02:00
new StartupSettings ( ) ,
2022-09-06 16:08:19 +02:00
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 , false , null , new List < string > ( ) ) ) ,
isConnectedFunc : ( ) = > true ,
2023-02-22 14:03:35 +01:00
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > new ConnectorCache ( new AppContextInfo ( "MyMerchId" , "MyApp" , new Version ( 1 , 2 ) ) , null /*UI language */ , sessionCookie , mail , server : new CopriCallsMemory001 ( sessionCookie ) ) ,
2022-09-06 16:08:19 +02:00
merchantId : "MyMerchId" ,
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : null ,
locationServicesContainer : geolocation ,
locksService : locksService , // Cipher
device : new DeviceMock ( ) , // Permissions
specialFolder : new SpecialFolderMock ( ) ,
cipher : null ,
theme : null ,
postAction : ( d , obj ) = > d ( obj ) ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) , // Current app version
lastVersion : new Version ( 3 , 0 , 173 ) , // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion : null ) ; // Whats new page was never shown.
var bikesAtStation = new BikesAtStationPageViewModel (
tinkApp . ActiveUser ,
permissions ,
bluetooth ,
Device . Android ,
new TINK . Model . Station . Station ( "FR103" , new List < string > ( ) , null ) , // Was station id 103 before switching from data provider CopriCallsMemory(SampleSets.ShareeFr01_Set1, 1, ...)
( ) = > tinkApp . GetIsConnected ( ) ,
( isConnected ) = > tinkApp . GetConnector ( isConnected ) ,
geolocation . Active , // geolocation
locksService ,
tinkApp . Polling ,
( url ) = > { } ,
( d , obj ) = > d ( obj ) ,
Substitute . For < ISmartDevice > ( ) ,
viewService ) ;
2023-02-22 14:03:35 +01:00
await bikesAtStation . OnAppearingOrRefresh ( ) ;
2022-09-06 16:08:19 +02:00
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 bikeFR9999 = bikesAtStation . FirstOrDefault ( x = > x . Id = = "FR9999" ) as TINK . ViewModel . Bikes . Bike . BluetoothLock . BikeViewModel ; // Was id 1315
var bikeFR9998 = bikesAtStation . FirstOrDefault ( x = > x . Id = = "FR9998" ) as TINK . ViewModel . Bikes . Bike . BluetoothLock . BikeViewModel ; // Was id 1543
Assert . That (
bikeFR9999 ,
Is . Not . Null ) ;
Assert . That (
bikeFR9998 ,
Is . Not . Null ) ;
Assert . AreEqual ( "Available." , bikeFR9999 . StateText ) ;
Assert . AreEqual ( "Available." , bikeFR9998 . StateText ) ;
Assert . AreEqual ( "NotLoggedIn" , bikeFR9999 . LockitButtonText ) ;
Assert . AreEqual ( "NotLoggedIn" , bikeFR9998 . 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 ( )
{
2023-04-05 15:02:10 +02:00
var geolocation = Substitute . For < IServicesContainer < IGeolocationService > > ( ) ;
2022-09-06 16:08:19 +02:00
var locksService = Substitute . For < ILocksService > ( ) ;
var timeOut = Substitute . For < ITimeOutProvider > ( ) ;
var viewService = Substitute . For < IViewService > ( ) ;
var permissions = Substitute . For < ILocationPermission > ( ) ;
var bluetooth = Substitute . For < IBluetoothLE > ( ) ;
const string MERCH_ID = "MyMerchId" ;
var tinkApp = new TinkApp (
2022-10-17 18:45:38 +02:00
new Settings (
2022-09-06 16:08:19 +02:00
new GroupFilterMapPage ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . Off } } ) ,
new GroupFilterSettings ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
2022-10-17 18:45:38 +02:00
new StartupSettings ( ) ,
2022-09-06 16:08:19 +02:00
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" , false , "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH" , new List < string > { "300001" , "300029" } ) ) ,
isConnectedFunc : ( ) = > true ,
2023-02-22 14:03:35 +01:00
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > new ConnectorCache ( new AppContextInfo ( "MyMerchId" , "MyApp" , new Version ( 1 , 2 ) ) , null /*UI language */ , sessionCookie , mail , server : new CopriCallsMemory ( MERCH_ID , SampleSets . ShareeFr01_Set1 , 1 , sessionCookie ) ) ,
2022-09-06 16:08:19 +02:00
merchantId : "MyMerchId" ,
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : null ,
locationServicesContainer : geolocation ,
locksService : locksService , // Cipher
device : new DeviceMock ( ) , // Permissions,
specialFolder : new SpecialFolderMock ( ) ,
cipher : null ,
theme : null ,
postAction : ( d , obj ) = > d ( obj ) ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) , // Current app version
lastVersion : new Version ( 3 , 0 , 173 ) , // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion : null ) ; // Whats new page was never shown.
var 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 ) ;
2023-02-22 14:03:35 +01:00
await bikesAtStation . OnAppearingOrRefresh ( ) ;
2022-09-06 16:08:19 +02:00
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 ) ;
2023-01-18 14:22:51 +01:00
Assert . AreEqual ( "There are currently no bicycles available at this station." , bikesAtStation . NoBikesAtStationText ) ;
2022-09-06 16:08:19 +02:00
}
[Test]
public async Task TestConstruct_Droid ( )
{
2023-04-05 15:02:10 +02:00
var geolocation = Substitute . For < IServicesContainer < IGeolocationService > > ( ) ;
2022-09-06 16:08:19 +02:00
var locksService = Substitute . For < ILocksService > ( ) ;
var timeOut = Substitute . For < ITimeOutProvider > ( ) ;
var viewService = Substitute . For < IViewService > ( ) ;
var permissions = Substitute . For < ILocationPermission > ( ) ;
var bluetooth = Substitute . For < IBluetoothLE > ( ) ;
// Fake location permissions to be set
permissions . CheckStatusAsync ( ) . Returns ( Task . FromResult ( Status . 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 ( ) }
}
) ;
const string MERCH_ID = "MyMerchId" ;
var tinkApp = new TinkApp (
2022-10-17 18:45:38 +02:00
new Settings (
2022-09-06 16:08:19 +02:00
new GroupFilterMapPage ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . Off } } ) ,
new GroupFilterSettings ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
2022-10-17 18:45:38 +02:00
new StartupSettings ( ) ,
2022-09-06 16:08:19 +02:00
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" , false , "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH" , new List < string > { "300001" , "300029" } ) ) ,
isConnectedFunc : ( ) = > true ,
2023-02-22 14:03:35 +01:00
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > new ConnectorCache ( new AppContextInfo ( MERCH_ID , "MyApp" , new Version ( 1 , 2 ) ) , null /*UI language */ , sessionCookie , mail , server : new CopriCallsMemory ( MERCH_ID , SampleSets . ShareeFr01_Set1 , 1 , sessionCookie ) ) ,
2022-09-06 16:08:19 +02:00
merchantId : MERCH_ID , // Instance geolocation mocks both parts
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : null ,
locationServicesContainer : geolocation ,
locksService : locksService , // Cipher
device : new DeviceMock ( ) , // Permissions,
specialFolder : new SpecialFolderMock ( ) ,
cipher : null ,
theme : null ,
postAction : ( d , obj ) = > d ( obj ) ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) , // Current app version
lastVersion : new Version ( 3 , 0 , 173 ) , // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion : null ) ; // Whats new page was never shown.
var 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 ) ;
2023-02-22 14:03:35 +01:00
await bikesAtStation . OnAppearingOrRefresh ( ) ;
2022-09-06 16:08:19 +02:00
// Verify behaviour
Received . InOrder ( ( ) = >
{
permissions . CheckStatusAsync ( ) ;
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 . That (
bike1545 ,
Is . Not . Null ) ;
Assert . That (
bike1537 ,
Is . Not . Null ) ;
Assert . That (
bike1315 ,
Is . Not . Null ) ;
Assert . That (
bike1543 ,
Is . Not . Null ) ;
Assert . AreEqual ( $"Rented since {DateTime.Parse(" 2020 - 11 - 06 17 : 53 : 22.784681 + 01 "):dd. MMMM HH:mm}." , bike1545 . StateText ) ;
Assert . AreEqual ( $"Rented since {DateTime.Parse(" 2020 - 10 - 12 08 : 38 : 12.374231 + 02 "):dd. MMMM HH:mm}." , bike1537 . StateText ) ;
Assert . AreEqual ( "Available." , bike1315 . StateText ) ;
Assert . AreEqual ( "Available." , bike1543 . StateText ) ;
Assert . AreEqual ( "Close lock" , bike1545 . LockitButtonText ) ;
Assert . AreEqual ( "Open 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_OpenSettings ( )
{
2023-04-05 15:02:10 +02:00
var geolocation = Substitute . For < IServicesContainer < IGeolocationService > > ( ) ;
2022-09-06 16:08:19 +02:00
var locksService = Substitute . For < ILocksService > ( ) ;
var timeOut = Substitute . For < ITimeOutProvider > ( ) ;
var viewService = Substitute . For < IViewService > ( ) ;
var permissions = Substitute . For < ILocationPermission > ( ) ;
var bluetooth = Substitute . For < IBluetoothLE > ( ) ;
// Fake location permissions not to be set
permissions . CheckStatusAsync ( ) . Returns ( Task . FromResult ( Status . 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 ( ) }
}
) ;
bluetooth . State . Returns ( BluetoothState . On ) ;
const string MERCH_ID = "MyMerchId" ;
var tinkApp = new TinkApp (
2022-10-17 18:45:38 +02:00
new Settings (
2022-09-06 16:08:19 +02:00
new GroupFilterMapPage ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . Off } } ) ,
new GroupFilterSettings ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
2022-10-17 18:45:38 +02:00
new StartupSettings ( ) ,
2022-09-06 16:08:19 +02:00
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" , false , "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH" , new List < string > { "300001" , "300029" } ) ) ,
isConnectedFunc : ( ) = > true ,
2023-02-22 14:03:35 +01:00
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > new ConnectorCache ( new AppContextInfo ( MERCH_ID , "MyApp" , new Version ( 1 , 2 ) ) , null /*UI language */ , sessionCookie , mail , server : new CopriCallsMemory ( MERCH_ID , SampleSets . ShareeFr01_Set1 , 1 , sessionCookie ) ) ,
2022-09-06 16:08:19 +02:00
merchantId : MERCH_ID ,
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : null ,
locationServicesContainer : geolocation ,
locksService : locksService , // Cipher
device : new DeviceMock ( ) , // Permissions,
specialFolder : new SpecialFolderMock ( ) ,
cipher : null ,
theme : null ,
postAction : ( d , obj ) = > d ( obj ) ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) , // Current app version
lastVersion : new Version ( 3 , 0 , 173 ) , // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion : null ) ; // Whats new page was never shown.
var 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 ) ;
2023-02-22 14:03:35 +01:00
await bikesAtStation . OnAppearingOrRefresh ( ) ;
2022-09-06 16:08:19 +02:00
// Verify behaviour
Received . InOrder ( ( ) = >
{
permissions . CheckStatusAsync ( ) ;
var glDummy = geolocation . Active . Received ( ) . IsGeolcationEnabled ;
2022-12-07 16:54:52 +01:00
// permissions.RequestAsync(); // Ask user from permissions (disabled, since no secondary request allowed).
2022-09-06 16:08:19 +02:00
viewService . DisplayAlert (
"Hint" ,
"Please allow location sharing so that bike lock/locks can be managed.\r\nOpen sharing dialog?" ,
"Yes" ,
"No" ) ;
permissions . OpenAppSettings ( ) ;
} ) ;
2022-12-07 16:54:52 +01:00
Assert . IsTrue ( new List < string > { "Updating..." , string . Empty } . Contains ( bikesAtStation . StatusInfoText ) ) ;
2022-09-06 16:08:19 +02:00
// 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 . That (
bike1545 ,
Is . Not . Null ) ;
Assert . That (
bike1537 ,
Is . Not . Null ) ;
Assert . That (
bike1315 ,
Is . Not . Null ) ;
Assert . That (
bike1543 ,
Is . Not . Null ) ;
Assert . AreEqual ( $"Rented since {DateTime.Parse(" 2020 - 11 - 06 17 : 53 : 22.784681 + 01 "):dd. MMMM HH:mm}." , bike1545 . StateText ) ;
Assert . AreEqual ( $"Rented since {DateTime.Parse(" 2020 - 10 - 12 08 : 38 : 12.374231 + 02 "):dd. MMMM HH:mm}." , 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 ( )
{
2023-04-05 15:02:10 +02:00
var geolocation = Substitute . For < IServicesContainer < IGeolocationService > > ( ) ;
2022-09-06 16:08:19 +02:00
var locksService = Substitute . For < ILocksService > ( ) ;
var timeOut = Substitute . For < ITimeOutProvider > ( ) ;
var viewService = Substitute . For < IViewService > ( ) ;
var permissions = Substitute . For < ILocationPermission > ( ) ;
var bluetooth = Substitute . For < IBluetoothLE > ( ) ;
// Fake location permissions not to be set
permissions . CheckStatusAsync ( ) . Returns ( Task . FromResult ( Status . 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 ( ) }
}
) ;
const string MERCH_ID = "MyMerchId" ;
var tinkApp = new TinkApp (
2022-10-17 18:45:38 +02:00
new Settings (
2022-09-06 16:08:19 +02:00
new GroupFilterMapPage ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . Off } } ) ,
new GroupFilterSettings ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
2022-10-17 18:45:38 +02:00
new StartupSettings ( ) ,
2022-09-06 16:08:19 +02:00
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" , false , "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH" , new List < string > { "300001" , "300029" } ) ) ,
isConnectedFunc : ( ) = > true ,
2023-02-22 14:03:35 +01:00
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > new ConnectorCache ( new AppContextInfo ( MERCH_ID , "MyApp" , new Version ( 1 , 2 ) ) , null /*UI language */ , sessionCookie , mail , server : new CopriCallsMemory ( MERCH_ID , SampleSets . ShareeFr01_Set1 , 1 , sessionCookie ) ) ,
2022-09-06 16:08:19 +02:00
merchantId : MERCH_ID ,
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : null ,
locationServicesContainer : geolocation ,
locksService : locksService , // Cipher
device : new DeviceMock ( ) , // Permissions,
specialFolder : new SpecialFolderMock ( ) ,
cipher : null ,
theme : null ,
postAction : ( d , obj ) = > d ( obj ) ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) , // Current app version
lastVersion : new Version ( 3 , 0 , 173 ) , // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion : null ) ; // Whats new page was never shown.
var 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 ) ;
2023-02-22 14:03:35 +01:00
await bikesAtStation . OnAppearingOrRefresh ( ) ;
2022-09-06 16:08:19 +02:00
// Verify behaviour
Received . InOrder ( ( ) = >
{
permissions . CheckStatusAsync ( ) ;
var glDummy = geolocation . Active . Received ( ) . IsGeolcationEnabled ;
2022-12-07 16:54:52 +01:00
//permissions.RequestAsync(); // Ask user from permissions (disabled, since no secondary request allowed).
2022-09-06 16:08:19 +02:00
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 . That (
bike1545 ,
Is . Not . Null ) ;
Assert . That (
bike1537 ,
Is . Not . Null ) ;
Assert . That (
bike1315 ,
Is . Not . Null ) ;
Assert . That (
bike1543 ,
Is . Not . Null ) ;
Assert . AreEqual ( $"Rented since {DateTime.Parse(" 2020 - 11 - 06 17 : 53 : 22.784681 + 01 "):dd. MMMM HH:mm}." , bike1545 . StateText ) ;
Assert . AreEqual ( $"Rented since {DateTime.Parse(" 2020 - 10 - 12 08 : 38 : 12.374231 + 02 "):dd. MMMM HH:mm}." , 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 ( )
{
2023-04-05 15:02:10 +02:00
var geolocation = Substitute . For < IServicesContainer < IGeolocationService > > ( ) ;
2022-09-06 16:08:19 +02:00
var locksService = Substitute . For < ILocksService > ( ) ;
var timeOut = Substitute . For < ITimeOutProvider > ( ) ;
var viewService = Substitute . For < IViewService > ( ) ;
var permissions = Substitute . For < ILocationPermission > ( ) ;
var bluetooth = Substitute . For < IBluetoothLE > ( ) ;
// Fake location permissions to be set
permissions . CheckStatusAsync ( ) . Returns ( Task . FromResult ( Status . 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 ( ) }
}
) ;
const string MERCH_ID = "MyMerchId" ;
var tinkApp = new TinkApp (
2022-10-17 18:45:38 +02:00
new Settings (
2022-09-06 16:08:19 +02:00
new GroupFilterMapPage ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . Off } } ) ,
new GroupFilterSettings ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
2022-10-17 18:45:38 +02:00
new StartupSettings ( ) ,
2022-09-06 16:08:19 +02:00
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" , false , "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH" , new List < string > { "300001" , "300029" } ) ) ,
isConnectedFunc : ( ) = > true ,
2023-02-22 14:03:35 +01:00
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > new ConnectorCache ( new AppContextInfo ( MERCH_ID , "MyApp" , new Version ( 1 , 2 ) ) , null /*UI language */ , sessionCookie , mail , server : new CopriCallsMemory ( MERCH_ID , SampleSets . ShareeFr01_Set1 , 1 , sessionCookie ) ) ,
2022-09-06 16:08:19 +02:00
merchantId : MERCH_ID ,
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : null ,
locationServicesContainer : geolocation ,
locksService : locksService , // Cipher
device : new DeviceMock ( ) , // Permissions,
specialFolder : new SpecialFolderMock ( ) ,
cipher : null ,
theme : null ,
postAction : ( d , obj ) = > d ( obj ) ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) , // Current app version
lastVersion : new Version ( 3 , 0 , 173 ) , // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion : null ) ; // Whats new page was never shown.
var 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 ) ;
2023-02-22 14:03:35 +01:00
await bikesAtStation . OnAppearingOrRefresh ( ) ;
2022-09-06 16:08:19 +02:00
// Verify behaviour
Received . InOrder ( ( ) = >
{
permissions . CheckStatusAsync ( ) ;
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 . That (
bike1545 ,
Is . Not . Null ) ;
Assert . That (
bike1537 ,
Is . Not . Null ) ;
Assert . That (
bike1315 ,
Is . Not . Null ) ;
Assert . That (
bike1543 ,
Is . Not . Null ) ;
Assert . AreEqual ( $"Rented since {DateTime.Parse(" 2020 - 11 - 06 17 : 53 : 22.784681 + 01 "):dd. MMMM HH:mm}." , bike1545 . StateText ) ;
Assert . AreEqual ( $"Rented since {DateTime.Parse(" 2020 - 10 - 12 08 : 38 : 12.374231 + 02 "):dd. MMMM HH:mm}." , 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 ( )
{
2023-04-05 15:02:10 +02:00
var geolocation = Substitute . For < IServicesContainer < IGeolocationService > > ( ) ;
2022-09-06 16:08:19 +02:00
var locksService = Substitute . For < ILocksService > ( ) ;
var timeOut = Substitute . For < ITimeOutProvider > ( ) ;
var viewService = Substitute . For < IViewService > ( ) ;
var permissions = Substitute . For < ILocationPermission > ( ) ;
var bluetooth = Substitute . For < IBluetoothLE > ( ) ;
// Fake location permissions to be set
permissions . CheckStatusAsync ( ) . Returns ( Task . FromResult ( Status . 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 ( ) }
}
) ;
const string MERCH_ID = "MyMerchId" ;
var tinkApp = new TinkApp (
2022-10-17 18:45:38 +02:00
new Settings (
2022-09-06 16:08:19 +02:00
new GroupFilterMapPage ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . Off } } ) ,
new GroupFilterSettings ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
2022-10-17 18:45:38 +02:00
new StartupSettings ( ) ,
2022-09-06 16:08:19 +02:00
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" , false , "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH" , new List < string > { "300001" , "300029" } ) ) ,
isConnectedFunc : ( ) = > true ,
2023-02-22 14:03:35 +01:00
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > new ConnectorCache ( new AppContextInfo ( MERCH_ID , "MyApp" , new Version ( 1 , 2 ) ) , null /*UI language */ , sessionCookie , mail , server : new CopriCallsMemory ( MERCH_ID , SampleSets . ShareeFr01_Set1 , 1 , sessionCookie ) ) ,
2022-09-06 16:08:19 +02:00
merchantId : MERCH_ID ,
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : null ,
locationServicesContainer : geolocation ,
locksService : locksService , // Cipher
device : new DeviceMock ( ) , // Permissions,
specialFolder : new SpecialFolderMock ( ) ,
cipher : null ,
theme : null ,
postAction : ( d , obj ) = > d ( obj ) ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) , // Current app version
lastVersion : new Version ( 3 , 0 , 173 ) , // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion : null ) ; // Whats new page was never shown.
var 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 ) ;
2023-02-22 14:03:35 +01:00
await bikesAtStation . OnAppearingOrRefresh ( ) ;
2022-09-06 16:08:19 +02:00
// Verify behaviour
Received . InOrder ( ( ) = >
{
permissions . CheckStatusAsync ( ) ;
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 . That (
bike1545 ,
Is . Not . Null ) ;
Assert . That (
bike1537 ,
Is . Not . Null ) ;
Assert . That (
bike1315 ,
Is . Not . Null ) ;
Assert . That (
bike1543 ,
Is . Not . Null ) ;
Assert . AreEqual ( $"Rented since {DateTime.Parse(" 2020 - 11 - 06 17 : 53 : 22.784681 + 01 "):dd. MMMM HH:mm}." , bike1545 . StateText ) ;
Assert . AreEqual ( $"Rented since {DateTime.Parse(" 2020 - 10 - 12 08 : 38 : 12.374231 + 02 "):dd. MMMM HH:mm}." , 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 < ILocationPermission > ( ) ;
var bluetooth = Substitute . For < IBluetoothLE > ( ) ;
bluetooth . State . Returns ( BluetoothState . On ) ;
locksService . TimeOut . Returns ( timeOut ) ;
timeOut . MultiConnect . Returns ( new TimeSpan ( 0 ) ) ;
const string MERCH_ID = "MyMerchId" ;
var tinkApp = new TinkApp (
2022-10-17 18:45:38 +02:00
new Settings (
2022-09-06 16:08:19 +02:00
new GroupFilterMapPage ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . Off } } ) ,
new GroupFilterSettings ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
2022-10-17 18:45:38 +02:00
new StartupSettings ( ) ,
2022-09-06 16:08:19 +02:00
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 ( ) ,
isConnectedFunc : ( ) = > true ,
2023-02-22 14:03:35 +01:00
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > new ConnectorCache ( new AppContextInfo ( MERCH_ID , "MyApp" , new Version ( 1 , 2 ) ) , null /*UI language */ , sessionCookie , mail , server : new CopriCallsMemory001 ( sessionCookie ) ) ,
2022-09-06 16:08:19 +02:00
merchantId : MERCH_ID ,
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : Substitute . For < ILocationPermission > ( ) ,
2023-04-05 15:02:10 +02:00
locationServicesContainer : Substitute . For < IServicesContainer < IGeolocationService > > ( ) ,
2022-09-06 16:08:19 +02:00
locksService : locksService , // Cipher
device : new DeviceMock ( ) ,
specialFolder : new SpecialFolderMock ( ) ,
cipher : null ,
theme : null ,
postAction : ( d , obj ) = > d ( obj ) ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) , // Current app version
lastVersion : new Version ( 3 , 0 , 173 ) , // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion : null ) ; // Whats new page was never shown.
var bikesAtStation = new BikesAtStationPageViewModel (
tinkApp . ActiveUser ,
permissions ,
bluetooth ,
Device . iOS ,
new TINK . Model . Station . Station ( "FR101" , new List < string > ( ) , null ) , // Was 31 before switching CopriCallsMemory(SampleSets.Set2, 1, ...)
( ) = > tinkApp . GetIsConnected ( ) ,
( isConnected ) = > tinkApp . GetConnector ( isConnected ) ,
new GeolocationMock ( ) ,
locksService ,
tinkApp . Polling ,
( url ) = > { } ,
( d , obj ) = > d ( obj ) ,
Substitute . For < ISmartDevice > ( ) ,
viewService ) ;
2023-02-22 14:03:35 +01:00
await bikesAtStation . OnAppearingOrRefresh ( ) ;
2022-09-06 16:08:19 +02:00
Assert . IsTrue ( new List < string > { "Updating..." , string . Empty } . Contains ( bikesAtStation . StatusInfoText ) ) ;
// Verify list of bikes
Assert . AreEqual ( 3 , bikesAtStation . Count ) ; // Was 1 before switch.
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 = = "FR1003" ) . StateText ) ; // Was 52 before switch.
Assert . AreEqual ( "Available." , bikesAtStation . FirstOrDefault ( x = > x . Id = = "FR1002" ) . StateText ) ;
Assert . AreEqual ( "Available." , bikesAtStation . FirstOrDefault ( x = > x . Id = = "FR1001" ) . 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 < ILocationPermission > ( ) ;
var bluetooth = Substitute . For < IBluetoothLE > ( ) ;
bluetooth . State . Returns ( BluetoothState . On ) ;
locksService . TimeOut . Returns ( timeOut ) ;
timeOut . MultiConnect . Returns ( new TimeSpan ( 0 ) ) ;
const string MERCH_ID = "MyMerchId" ;
var tinkApp = new TinkApp (
2022-10-17 18:45:38 +02:00
new Settings (
2022-09-06 16:08:19 +02:00
new GroupFilterMapPage ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . Off } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
new GroupFilterSettings ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
2022-10-17 18:45:38 +02:00
new StartupSettings ( ) ,
2022-09-06 16:08:19 +02:00
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 ( ) ,
isConnectedFunc : ( ) = > true ,
2023-02-22 14:03:35 +01:00
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > new ConnectorCache ( new AppContextInfo ( "MyMerchId" , "MyApp" , new Version ( 1 , 2 ) ) , null /*UI language */ , sessionCookie , mail , server : new CopriCallsMemory ( MERCH_ID , SampleSets . Set2 , 1 , sessionCookie ) ) ,
2022-09-06 16:08:19 +02:00
merchantId : "MyMerchId" ,
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : Substitute . For < ILocationPermission > ( ) ,
2023-04-05 15:02:10 +02:00
locationServicesContainer : Substitute . For < IServicesContainer < IGeolocationService > > ( ) ,
2022-09-06 16:08:19 +02:00
locksService : locksService , // Cipher
device : new DeviceMock ( ) ,
specialFolder : new SpecialFolderMock ( ) ,
cipher : null ,
theme : null ,
postAction : ( d , obj ) = > d ( obj ) ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) , // Current app version
lastVersion : new Version ( 3 , 0 , 173 ) , // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion : null ) ; // Whats new page was never shown.
var 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 ) ;
2023-02-22 14:03:35 +01:00
await bikesAtStation . OnAppearingOrRefresh ( ) ;
2022-09-06 16:08:19 +02:00
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 ) ;
2023-01-18 14:22:51 +01:00
Assert . AreEqual ( "There are currently no bicycles available at this station." , bikesAtStation . NoBikesAtStationText ) ;
2022-09-06 16:08:19 +02:00
}
[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 < ILocationPermission > ( ) ;
var bluetooth = Substitute . For < IBluetoothLE > ( ) ;
bluetooth . State . Returns ( BluetoothState . On ) ;
locksService . TimeOut . Returns ( timeOut ) ;
timeOut . MultiConnect . Returns ( new TimeSpan ( 0 ) ) ;
var tinkApp = new TinkApp (
2022-10-17 18:45:38 +02:00
new Settings (
2022-09-06 16:08:19 +02:00
new GroupFilterMapPage ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . Off } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
new GroupFilterSettings ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
2022-10-17 18:45:38 +02:00
new StartupSettings ( ) ,
2022-09-06 16:08:19 +02:00
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 ,
false ,
"6103_112e96b36ba33de245943c5ffaf369cd_" , // Was 4da3044c8657a04ba60e2eaa753bc51a before switching from data provider CopriCallsMemory(SampleSets.Set2, 1, ...)
new List < string > { FilterHelper . CARGOBIKE } ) ) ,
isConnectedFunc : ( ) = > true ,
2023-02-22 14:03:35 +01:00
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > new ConnectorCache ( new AppContextInfo ( "MyMerchId" , "MyApp" , new Version ( 1 , 2 ) ) , null /*UI language */ , sessionCookie , mail , server : new CopriCallsMemory001 ( sessionCookie ) ) ,
2022-09-06 16:08:19 +02:00
merchantId : "MyMerchId" ,
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : Substitute . For < ILocationPermission > ( ) ,
2023-04-05 15:02:10 +02:00
locationServicesContainer : Substitute . For < IServicesContainer < IGeolocationService > > ( ) ,
2022-09-06 16:08:19 +02:00
locksService : locksService , // Cipher
device : new DeviceMock ( ) ,
specialFolder : new SpecialFolderMock ( ) ,
cipher : null ,
theme : null ,
postAction : ( d , obj ) = > d ( obj ) ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) , // Current app version
lastVersion : new Version ( 3 , 0 , 173 ) , // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion : null ) ; // Whats new page was never shown.
var bikesAtStation = new BikesAtStationPageViewModel (
tinkApp . ActiveUser ,
permissions ,
bluetooth ,
Device . iOS ,
new TINK . Model . Station . Station ( "FR103" , new List < string > ( ) , null ) , // Was station id 4 before switching from data provider CopriCallsMemory(SampleSets.Set2, 1, ...)
( ) = > tinkApp . GetIsConnected ( ) ,
( isConnected ) = > tinkApp . GetConnector ( isConnected ) ,
new GeolocationMock ( ) ,
locksService ,
tinkApp . Polling ,
( url ) = > { } ,
( d , obj ) = > d ( obj ) ,
Substitute . For < ISmartDevice > ( ) ,
viewService ) ;
2023-02-22 14:03:35 +01:00
await bikesAtStation . OnAppearingOrRefresh ( ) ;
2022-09-06 16:08:19 +02:00
Assert . IsTrue ( new List < string > { "Updating..." , string . Empty } . Contains ( bikesAtStation . StatusInfoText ) ) ;
// Verify list of bikes
Assert . AreEqual ( 4 , bikesAtStation . Count ) ; // Count of bikes was 4 before switching from data provider CopriCallsMemory(SampleSets.Set2, 1, ...)
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 = = "FR9999" ) . StateText ) ;
Assert . AreEqual ( "Available." , bikesAtStation . FirstOrDefault ( x = > x . Id = = "FR9999" ) . StateText ) ;
Assert . AreEqual ( "Max. reservation time of 15 min. expired." , bikesAtStation . FirstOrDefault ( x = > x . Id = = "FR1004" ) . StateText ) ;
Assert . AreEqual ( $"Rented since {DateTime.Parse(" 2021 - 11 - 06 18 : 57 : 25.445447 + 01 "):dd. MMMM HH:mm}." , bikesAtStation . FirstOrDefault ( x = > x . Id = = "FR1544" ) . StateText ) ; // Was 7
// 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 < ILocationPermission > ( ) ;
var bluetooth = Substitute . For < IBluetoothLE > ( ) ;
bluetooth . State . Returns ( BluetoothState . On ) ;
locksService . TimeOut . Returns ( timeOut ) ;
timeOut . MultiConnect . Returns ( new TimeSpan ( 0 ) ) ;
var tinkApp = new TinkApp (
2022-10-17 18:45:38 +02:00
new Settings (
2022-09-06 16:08:19 +02:00
new GroupFilterMapPage ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . Off } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
new GroupFilterSettings ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
2022-10-17 18:45:38 +02:00
new StartupSettings ( ) ,
2022-09-06 16:08:19 +02:00
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 ( ) ,
isConnectedFunc : ( ) = > false ,
2023-02-22 14:03:35 +01:00
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > new ConnectorCache ( new AppContextInfo ( "MyMerchId" , "MyApp" , new Version ( 1 , 2 ) ) , null /*UI language */ , sessionCookie , mail , server : new CopriCallsMemory001 ( sessionCookie ) ) ,
2022-09-06 16:08:19 +02:00
merchantId : "MyMerchId" ,
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : Substitute . For < ILocationPermission > ( ) ,
2023-04-05 15:02:10 +02:00
locationServicesContainer : Substitute . For < IServicesContainer < IGeolocationService > > ( ) ,
2022-09-06 16:08:19 +02:00
locksService : locksService , // Cipher
device : new DeviceMock ( ) ,
specialFolder : new SpecialFolderMock ( ) ,
cipher : null , // Not connected.
theme : null ,
postAction : ( d , obj ) = > d ( obj ) ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) , // Current app version
lastVersion : new Version ( 3 , 0 , 173 ) , // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion : null ) ; // Whats new page was never shown.
var bikesAtStation = new BikesAtStationPageViewModel (
tinkApp . ActiveUser ,
permissions ,
bluetooth ,
Device . iOS ,
new TINK . Model . Station . Station ( "FR103" , new List < string > ( ) , null ) , // Was station id 4 before switching from data provider CopriCallsMemory(SampleSets.Set2, 1
( ) = > tinkApp . GetIsConnected ( ) ,
( isConnected ) = > tinkApp . GetConnector ( isConnected ) ,
new GeolocationMock ( ) ,
locksService ,
tinkApp . Polling ,
( url ) = > { } ,
( d , obj ) = > d ( obj ) ,
Substitute . For < ISmartDevice > ( ) ,
viewService ) ;
2023-02-22 14:03:35 +01:00
await bikesAtStation . OnAppearingOrRefresh ( ) ;
2022-09-06 16:08:19 +02:00
2023-03-08 13:18:54 +01:00
Assert . AreEqual ( "Offline." , bikesAtStation . StatusInfoText ) ;
2022-09-06 16:08:19 +02:00
// Verify list of bikes
Assert . AreEqual ( 2 , bikesAtStation . Count ) ; // Count of bikes was 3. There is no more bike with id 26.
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 = = "FR9999" ) . StateText ) ; // Was id 5
Assert . AreEqual ( "Available." , bikesAtStation . FirstOrDefault ( x = > x . Id = = "FR9998" ) . StateText ) ; // Was is 14
// 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 < ILocationPermission > ( ) ;
var bluetooth = Substitute . For < IBluetoothLE > ( ) ;
bluetooth . State . Returns ( BluetoothState . On ) ;
locksService . TimeOut . Returns ( timeOut ) ;
timeOut . MultiConnect . Returns ( new TimeSpan ( 0 ) ) ;
var tinkApp = new TinkApp (
2022-10-17 18:45:38 +02:00
new Settings (
2022-09-06 16:08:19 +02:00
new GroupFilterMapPage ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . Off } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
new GroupFilterSettings ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
2022-10-17 18:45:38 +02:00
new StartupSettings ( ) ,
2022-09-06 16:08:19 +02:00
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 ( ) ,
isConnectedFunc : ( ) = > false ,
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > new TINK . Model . Connector . Connector (
uri ,
new AppContextInfo ( "oiF2kahH" , "sharee.bike.test" , new Version ( 3 , 0 , 267 ) ) ,
null /*UI language */ ,
sessionCookie ,
mail ,
server : new CopriProviderHttps (
uri ,
TinkApp . MerchantId ,
new AppContextInfo ( "oiF2kahH" , "sharee.bike.test" , new Version ( 3 , 0 , 267 ) ) ,
null /*UI language */ ,
sessionCookie : sessionCookie ,
cacheServer : new CopriCallsCacheMemory001 ( sessionCookie : sessionCookie ) ,
httpsServer : new ExceptionServer ( ( msg ) = > new WebConnectFailureException ( msg , new Exception ( "Source expection." ) ) ) ) ) ,
merchantId : "MyMerchId" ,
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : Substitute . For < ILocationPermission > ( ) ,
2023-04-05 15:02:10 +02:00
locationServicesContainer : Substitute . For < IServicesContainer < IGeolocationService > > ( ) ,
2022-09-06 16:08:19 +02:00
locksService : locksService , // Cipher
device : new DeviceMock ( ) ,
specialFolder : new SpecialFolderMock ( ) ,
cipher : null , // Not connected.
theme : null ,
postAction : ( d , obj ) = > d ( obj ) ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) , // Current app version
lastVersion : new Version ( 3 , 0 , 173 ) , // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion : null ) ; // Whats new page was never shown.
var bikesAtStation = new BikesAtStationPageViewModel (
tinkApp . ActiveUser ,
permissions ,
bluetooth ,
Device . iOS ,
new TINK . Model . Station . Station ( "FR103" , new List < string > ( ) , null ) , // Was station id 4 before switching from data provider CopriCallsCacheMemory()
( ) = > tinkApp . GetIsConnected ( ) ,
( isConnected ) = > tinkApp . GetConnector ( isConnected ) ,
new GeolocationMock ( ) ,
locksService ,
tinkApp . Polling ,
( url ) = > { } ,
( d , obj ) = > d ( obj ) ,
Substitute . For < ISmartDevice > ( ) ,
viewService )
{
IsReportLevelVerbose = true
} ;
2023-02-22 14:03:35 +01:00
await bikesAtStation . OnAppearingOrRefresh ( ) ;
2022-09-06 16:08:19 +02:00
Assert . AreEqual ( "Connection interrupted, server unreachable." , bikesAtStation . StatusInfoText ) ;
// Verify list of bikes
Assert . AreEqual ( 2 , bikesAtStation . Count ) ; // Count of bikes was 3. There is no more bike with id 26.
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 = = "FR9999" ) . StateText ) ; // Was id 5
Assert . AreEqual ( "Available." , bikesAtStation . FirstOrDefault ( x = > x . Id = = "FR9998" ) . StateText ) ; // Was is 14
// 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 < ILocationPermission > ( ) ;
var bluetooth = Substitute . For < IBluetoothLE > ( ) ;
bluetooth . State . Returns ( BluetoothState . On ) ;
locksService . TimeOut . Returns ( timeOut ) ;
timeOut . MultiConnect . Returns ( new TimeSpan ( 0 ) ) ;
var tinkApp = new TinkApp (
2022-10-17 18:45:38 +02:00
new Settings (
2022-09-06 16:08:19 +02:00
new GroupFilterMapPage ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . Off } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
new GroupFilterSettings ( new Dictionary < string , FilterState > { { FilterHelper . CARGOBIKE , FilterState . On } , { FilterHelper . CITYBIKE , FilterState . On } } ) ,
2022-10-17 18:45:38 +02:00
new StartupSettings ( ) ,
2022-09-06 16:08:19 +02:00
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 ( ) ,
isConnectedFunc : ( ) = > false ,
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > new TINK . Model . Connector . Connector (
uri ,
new AppContextInfo ( "oiF2kahH" , "sharee.bike.test" , new Version ( 3 , 0 , 267 ) ) ,
null /*UI language */ ,
sessionCookie ,
mail ,
server : new CopriProviderHttps (
uri ,
TinkApp . MerchantId ,
new AppContextInfo ( "oiF2kahH" , "sharee.bike.test" , new Version ( 3 , 0 , 267 ) ) ,
null /*UI language */ ,
sessionCookie : sessionCookie ,
cacheServer : new CopriCallsCacheMemory001 ( sessionCookie : sessionCookie ) ,
httpsServer : new ExceptionServer ( ( msg ) = > new Exception ( msg ) ) ) ) ,
merchantId : "MyMerchId" ,
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : Substitute . For < ILocationPermission > ( ) ,
2023-04-05 15:02:10 +02:00
locationServicesContainer : Substitute . For < IServicesContainer < IGeolocationService > > ( ) ,
2022-09-06 16:08:19 +02:00
locksService : locksService , // Cipher
device : new DeviceMock ( ) ,
specialFolder : new SpecialFolderMock ( ) ,
cipher : null , // Not connected.
theme : null ,
postAction : ( d , obj ) = > d ( obj ) ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) , // Current app version
lastVersion : new Version ( 3 , 0 , 173 ) , // Current app version. Must be larger or equal 3.0.173 to
whatsNewShownInVersion : null ) ; // Whats new page was never shown.
var bikesAtStation = new BikesAtStationPageViewModel (
tinkApp . ActiveUser ,
permissions ,
bluetooth ,
Device . iOS ,
new TINK . Model . Station . Station ( "FR103" , new List < string > ( ) , null ) , // Was station id 4 before switching from data provider CopriCallsCacheMemory()
( ) = > tinkApp . GetIsConnected ( ) ,
( isConnected ) = > tinkApp . GetConnector ( isConnected ) ,
new GeolocationMock ( ) ,
locksService ,
tinkApp . Polling ,
( url ) = > { } ,
( d , obj ) = > d ( obj ) ,
Substitute . For < ISmartDevice > ( ) ,
viewService )
{
IsReportLevelVerbose = true
} ;
2023-02-22 14:03:35 +01:00
await bikesAtStation . OnAppearingOrRefresh ( ) ;
2022-09-06 16:08:19 +02:00
Assert . AreEqual ( "Connection interrupted." , bikesAtStation . StatusInfoText ) ;
// Verify list of bikes
Assert . AreEqual ( 2 , bikesAtStation . Count ) ; // Count of bikes was 3. There is no more bike with id 26.
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 = = "FR9999" ) . StateText ) ; // Was id 5
Assert . AreEqual ( "Available." , bikesAtStation . FirstOrDefault ( x = > x . Id = = "FR9998" ) . StateText ) ; // Was id 14.
// Login hint/ no bikes frame
Assert . IsTrue ( bikesAtStation . IsLoginRequiredHintVisible ) ;
Assert . IsFalse ( bikesAtStation . IsNoBikesAtStationVisible ) ;
Assert . AreEqual ( string . Empty , bikesAtStation . NoBikesAtStationText ) ;
}
}
2021-07-12 21:31:46 +02:00
}