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

78 lines
3.4 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;
using TINK.Model.Services.Geolocation;
using TINK.Services.BluetoothLock;
using TINK.Model.Device;
using TINK.Model.User.Account;
2021-12-08 17:58:06 +01:00
using Plugin.Permissions.Abstractions;
2021-06-26 20:57:55 +02:00
using System.Threading.Tasks;
2021-11-14 23:27:29 +01:00
using TestFramework.Repository;
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>();
2021-12-08 17:58:06 +01:00
var permissions = Substitute.For<IPermissions>();
2021-06-26 20:57:55 +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,
(isConnected, uri, sessionCookie, mail, expiresAfter) => string.IsNullOrEmpty(sessionCookie)
2021-11-08 23:11:56 +01:00
? new ConnectorCache(sessionCookie, mail, new CopriCallsMemory001()) as IConnector
: new ConnectorCache(sessionCookie, mail, new CopriCallsMemory001(sessionCookie)),
2021-06-26 20:57:55 +02:00
Substitute.For<IServicesContainer<IGeolocation>>(),
locksService,
device,
specialFolder,
null, // Cipher
2021-12-08 17:58:06 +01:00
permissions,
2021-06-26 20:57:55 +02:00
isConnectedFunc: () => true,
currentVersion: new Version(3, 2, 0, 115),
lastVersion: new Version(3, 0, 173) /* Current app version. Must be larger or equal 3.0.173 to lastVersion*/);
Assert.IsFalse(l_oTinkApp.ActiveUser.IsLoggedIn);
2021-11-08 23:11:56 +01:00
Assert.AreEqual(
2021-11-14 23:27:29 +01:00
8,
2021-11-08 23:11:56 +01:00
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.");
2021-06-26 20:57:55 +02:00
Assert.IsNull(l_oTinkApp.GetConnector(true).Command.SessionCookie);
// Log user out.
2021-11-08 23:11:56 +01:00
var l_oAccount = l_oTinkApp.GetConnector(true).Command.DoLogin("javaminister@gmail.com", "*********", "HwId1000000000000").Result;
2021-06-26 20:57:55 +02:00
await l_oTinkApp.ActiveUser.Login(l_oAccount);
Assert.IsTrue(l_oTinkApp.ActiveUser.IsLoggedIn);
2021-11-08 23:11:56 +01:00
Assert.AreEqual(
2021-11-14 23:27:29 +01:00
10,
2021-11-08 23:11:56 +01:00
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
}
}
}