mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-06 02:56:32 +01:00
83 lines
3.3 KiB
C#
83 lines
3.3 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using Plugin.BLE.Abstractions.Contracts;
|
|
using TestFramework.Repository;
|
|
using TINK.Model;
|
|
using TINK.Model.Connector;
|
|
using TINK.Model.Device;
|
|
using TINK.Model.Services.CopriApi.ServerUris;
|
|
using TINK.Model.User.Account;
|
|
using TINK.Repository;
|
|
using TINK.Services;
|
|
using TINK.Services.BluetoothLock;
|
|
using TINK.Services.Geolocation;
|
|
using TINK.Services.Permissions;
|
|
|
|
namespace TestShareeLib.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<ILocationPermission>();
|
|
|
|
// No user logged in is initial state to verify.
|
|
var tinkApp = 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, server: new CopriCallsMemory001())
|
|
: new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory001(sessionCookie)),
|
|
merchantId: "MyMerchId",
|
|
bluetoothService: Substitute.For<IBluetoothLE>(),
|
|
locationPermissionsService: permissions,
|
|
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocationService>>(),
|
|
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 lastVersion*/);
|
|
|
|
// Verifiy initial state.
|
|
Assert.IsFalse(tinkApp.ActiveUser.IsLoggedIn);
|
|
Assert.AreEqual(
|
|
8,
|
|
tinkApp.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,
|
|
tinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count,
|
|
"If no user is logged in no occupied bikes are shown.");
|
|
Assert.IsNull(tinkApp.GetConnector(true).Command.SessionCookie);
|
|
|
|
// Log in user.
|
|
var account = tinkApp.GetConnector(true).Command.DoLogin("javaminister@gmail.com", "*********", "HwId1000000000000").Result;
|
|
await tinkApp.ActiveUser.Login(account);
|
|
|
|
Assert.IsTrue(tinkApp.ActiveUser.IsLoggedIn);
|
|
Assert.AreEqual(
|
|
10,
|
|
tinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count,
|
|
"Sum of bikes is 6 occupied plus 2 occupied.");
|
|
Assert.AreEqual(
|
|
2,
|
|
tinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count,
|
|
"Javaminster occupies 2 bikes.");
|
|
Assert.AreEqual("6103_112e96b36ba33de245943c5ffaf369cd_oiF2kahH", tinkApp.GetConnector(true).Command.SessionCookie);
|
|
}
|
|
}
|
|
}
|