mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-15 22:56:37 +01:00
68 lines
3.1 KiB
C#
68 lines
3.1 KiB
C#
|
using NUnit.Framework;
|
|||
|
using System;
|
|||
|
using TINK.Model;
|
|||
|
using TINK.Model.Connector;
|
|||
|
using TINK.Repository;
|
|||
|
using TINK.Model.Services.CopriApi.ServerUris;
|
|||
|
using static TINK.Repository.CopriCallsMemory;
|
|||
|
using TINK.Services;
|
|||
|
using NSubstitute;
|
|||
|
using TINK.Model.Services.Geolocation;
|
|||
|
using TINK.Services.BluetoothLock;
|
|||
|
using TINK.Model.Device;
|
|||
|
using TINK.Model.User.Account;
|
|||
|
using Plugin.Permissions.Abstractions;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace TestTINKLib.Fixtures.UseCases.Login
|
|||
|
{
|
|||
|
|
|||
|
[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>();
|
|||
|
var permissions = Substitute.For<IPermissions>();
|
|||
|
|
|||
|
// 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)
|
|||
|
? new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1)) as IConnector
|
|||
|
: new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)),
|
|||
|
Substitute.For<IServicesContainer<IGeolocation>>(),
|
|||
|
locksService,
|
|||
|
device,
|
|||
|
specialFolder,
|
|||
|
null, // Cipher
|
|||
|
permissions,
|
|||
|
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);
|
|||
|
Assert.AreEqual(11, l_oTinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count);
|
|||
|
Assert.AreEqual(0, l_oTinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count);
|
|||
|
Assert.IsNull(l_oTinkApp.GetConnector(true).Command.SessionCookie);
|
|||
|
|
|||
|
// Log user out.
|
|||
|
var l_oAccount = l_oTinkApp.GetConnector(true).Command.DoLogin("javaminister@gmail.com", "javaminister", "HwId1000000000000").Result;
|
|||
|
await l_oTinkApp.ActiveUser.Login(l_oAccount);
|
|||
|
|
|||
|
Assert.IsTrue(l_oTinkApp.ActiveUser.IsLoggedIn);
|
|||
|
Assert.AreEqual(13, l_oTinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count);
|
|||
|
Assert.AreEqual(2, l_oTinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count);
|
|||
|
Assert.AreEqual("4da3044c8657a04ba60e2eaa753bc51a", l_oTinkApp.GetConnector(true).Command.SessionCookie);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|