sharee.bike-App/TestShareeLib/Model/TestTinkAppLogin.cs

83 lines
3.8 KiB
C#
Raw Normal View History

2021-06-26 20:57:55 +02:00
using NUnit.Framework;
using System;
using TINK.Model;
using TINK.Model.Connector;
using TINK.Model.Services.CopriApi.ServerUris;
using TINK.Services;
using NSubstitute;
2022-04-10 17:38:34 +02:00
using TINK.Services.Geolocation;
2021-06-26 20:57:55 +02:00
using TINK.Services.BluetoothLock;
using TINK.Model.Device;
using TINK.Model.User.Account;
using System.Threading.Tasks;
2021-11-14 23:27:29 +01:00
using TestFramework.Repository;
2022-01-04 18:59:16 +01:00
using TINK.Repository;
2022-04-10 17:38:34 +02:00
using TINK.Services.Permissions;
using Plugin.BLE.Abstractions.Contracts;
2021-06-26 20:57:55 +02:00
2021-11-14 23:27:29 +01:00
namespace TestShareeLib.UseCases.Login
2021-06-26 20:57:55 +02:00
{
[TestFixture]
public class TestTinkApp
{
[Test]
public async Task Login()
{
var accountStore = Substitute.For<IStore>();
var locksService = Substitute.For<ILocksService>();
var device = Substitute.For<ISmartDevice>();
var specialFolder = Substitute.For<ISpecialFolder>();
2022-04-10 17:38:34 +02:00
var permissions = Substitute.For<ILocationPermission>();
2021-06-26 20:57:55 +02:00
// No user logged in is initial state to verify.
2022-01-04 18:59:16 +01:00
var tinkApp = new TinkApp(
2021-06-26 20:57:55 +02:00
new TINK.Model.Settings.Settings(
activeLockService: locksService.GetType().FullName,
activeGeolocationService: "NotRelevantActiveGeoloactionServiceName",
activeUri: new Uri(CopriServerUriList.TINK_DEVEL)),
accountStore,
isConnectedFunc: () => true,
2022-04-10 17:38:34 +02:00
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => string.IsNullOrEmpty(sessionCookie)
? new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), sessionCookie, mail, new CopriCallsMemory001())
: new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), 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,
2021-06-26 20:57:55 +02:00
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 lastVersion*/);
2022-01-04 18:59:16 +01:00
// Verifiy initial state.
Assert.IsFalse(tinkApp.ActiveUser.IsLoggedIn);
2021-11-08 23:11:56 +01:00
Assert.AreEqual(
2021-11-14 23:27:29 +01:00
8,
2022-01-04 18:59:16 +01:00
tinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count,
2021-11-08 23:11:56 +01:00
"Sum of bikes is 6 occupied, no one occupied because no user is logged in");
Assert.AreEqual(
0,
2022-01-04 18:59:16 +01:00
tinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count,
2021-11-08 23:11:56 +01:00
"If no user is logged in no occupied bikes are shown.");
2022-01-04 18:59:16 +01:00
Assert.IsNull(tinkApp.GetConnector(true).Command.SessionCookie);
2021-06-26 20:57:55 +02:00
2022-01-04 18:59:16 +01:00
// Log in user.
var account = tinkApp.GetConnector(true).Command.DoLogin("javaminister@gmail.com", "*********", "HwId1000000000000").Result;
await tinkApp.ActiveUser.Login(account);
2021-06-26 20:57:55 +02:00
2022-01-04 18:59:16 +01:00
Assert.IsTrue(tinkApp.ActiveUser.IsLoggedIn);
2021-11-08 23:11:56 +01:00
Assert.AreEqual(
2021-11-14 23:27:29 +01:00
10,
2022-01-04 18:59:16 +01:00
tinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count,
2021-11-08 23:11:56 +01:00
"Sum of bikes is 6 occupied plus 2 occupied.");
Assert.AreEqual(
2,
2022-01-04 18:59:16 +01:00
tinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count,
2021-11-08 23:11:56 +01:00
"Javaminster occupies 2 bikes.");
2022-01-04 18:59:16 +01:00
Assert.AreEqual("6103_112e96b36ba33de245943c5ffaf369cd_oiF2kahH", tinkApp.GetConnector(true).Command.SessionCookie);
2021-06-26 20:57:55 +02:00
}
}
}