2022-08-30 15:42:25 +02:00
using System ;
using NSubstitute ;
using NUnit.Framework ;
using Plugin.BLE.Abstractions.Contracts ;
using TestFramework.Repository ;
2021-06-26 20:57:55 +02:00
using TINK.Model ;
using TINK.Model.Connector ;
using TINK.Model.Device ;
2022-08-30 15:42:25 +02:00
using TINK.Model.Services.CopriApi.ServerUris ;
2021-06-26 20:57:55 +02:00
using TINK.Model.User.Account ;
2022-01-04 18:59:16 +01:00
using TINK.Repository ;
2022-08-30 15:42:25 +02:00
using TINK.Services ;
using TINK.Services.BluetoothLock ;
using TINK.Services.Geolocation ;
2022-04-10 17:38:34 +02:00
using TINK.Services.Permissions ;
2021-06-26 20:57:55 +02:00
namespace TestTINKLib.Fixtures.UseCases.Logout
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestTinkApp
{
[Test]
public void Logout ( )
{
var accountStore = Substitute . For < IStore > ( ) ;
var locksService = Substitute . For < ILocksService > ( ) ;
var device = Substitute . For < ISmartDevice > ( ) ;
var specialFolder = Substitute . For < ISpecialFolder > ( ) ;
var permissions = Substitute . For < ILocationPermission > ( ) ;
var account = Substitute . For < IAccount > ( ) ;
2021-06-26 20:57:55 +02:00
2022-09-06 16:08:19 +02:00
accountStore . Load ( ) . Returns ( account ) ;
account . Mail . Returns ( "javaminister@gmail.com" ) ;
account . Pwd . Returns ( "*********" ) ;
account . SessionCookie . Returns ( "6103_112e96b36ba33de245943c5ffaf369cd_" ) ;
2021-06-26 20:57:55 +02:00
2022-09-06 16:08:19 +02:00
// No user logged in is initial state to verify.
var l_oTinkApp = new TinkApp (
new TINK . Model . Settings . Settings (
activeLockService : locksService . GetType ( ) . FullName ,
activeGeolocationService : "NotRelevantActiveGeoloactionServiceName" ,
activeUri : new Uri ( CopriServerUriList . TINK_DEVEL ) ) ,
accountStore ,
isConnectedFunc : ( ) = > true ,
connectorFactory : ( isConnected , uri , sessionCookie , mail , expiresAfter ) = > string . IsNullOrEmpty ( sessionCookie )
? new ConnectorCache ( new AppContextInfo ( "MyMerchId" , "MyApp" , new Version ( 1 , 2 ) ) , null /*UI language */ , sessionCookie , mail , new CopriCallsMemory001 ( ) )
: new ConnectorCache ( new AppContextInfo ( "MyMerchId" , "MyApp" , new Version ( 1 , 2 ) ) , null /*UI language */ , sessionCookie , mail , new CopriCallsMemory001 ( sessionCookie ) ) ,
merchantId : "MyMerchId" ,
bluetoothService : Substitute . For < IBluetoothLE > ( ) ,
locationPermissionsService : permissions ,
locationServicesContainer : Substitute . For < IServicesContainer < IGeolocation > > ( ) ,
locksService : locksService , // Cipher
device : device ,
specialFolder : specialFolder ,
cipher : null ,
theme : null ,
currentVersion : new Version ( 3 , 2 , 0 , 115 ) ,
lastVersion : new Version ( 3 , 0 , 173 ) ) ; // Current app version. Must be larger or equal 3.0.173 to
2021-06-26 20:57:55 +02:00
2022-09-06 16:08:19 +02:00
Assert . IsTrue ( l_oTinkApp . ActiveUser . IsLoggedIn ) ;
// There are 6 bikes available and 2, one reserved and one rented by javaminsiter.
Assert . AreEqual (
10 ,
l_oTinkApp . GetConnector ( true ) . Query . GetBikesAsync ( ) . Result . Response . Count ,
"Sum of bikes is 6 occupied plus 2 occupied." ) ;
Assert . AreEqual ( 2 ,
l_oTinkApp . GetConnector ( true ) . Query . GetBikesOccupiedAsync ( ) . Result . Response . Count ,
"Javaminster occupies 2 bikes." ) ;
Assert . AreEqual ( "6103_112e96b36ba33de245943c5ffaf369cd_" , l_oTinkApp . GetConnector ( true ) . Command . SessionCookie ) ;
2021-06-26 20:57:55 +02:00
2022-09-06 16:08:19 +02:00
// Log user out.
l_oTinkApp . GetConnector ( true ) . Command . DoLogout ( ) . Wait ( ) ;
l_oTinkApp . ActiveUser . Logout ( ) ;
2021-06-26 20:57:55 +02:00
2022-09-06 16:08:19 +02:00
Assert . IsFalse ( l_oTinkApp . ActiveUser . IsLoggedIn ) ;
Assert . AreEqual (
8 ,
l_oTinkApp . GetConnector ( true ) . Query . GetBikesAsync ( ) . Result . Response . Count ,
"Sum of bikes is 6 occupied, no one occupied because no user is logged in" ) ;
Assert . AreEqual (
0 ,
l_oTinkApp . GetConnector ( true ) . Query . GetBikesOccupiedAsync ( ) . Result . Response . Count ,
"If no user is logged in no occupied bikes are shown." ) ;
Assert . IsNull ( l_oTinkApp . GetConnector ( true ) . Command . SessionCookie ) ;
}
}
2021-06-26 20:57:55 +02:00
}