mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
83 lines
3.7 KiB
C#
83 lines
3.7 KiB
C#
using System;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using Plugin.BLE.Abstractions.Contracts;
|
|
using SharedBusinessLogic.Tests.Framework.Repository;
|
|
using ShareeBike.Model;
|
|
using ShareeBike.Model.Connector;
|
|
using ShareeBike.Model.Device;
|
|
using ShareeBike.Model.Services.CopriApi.ServerUris;
|
|
using ShareeBike.Model.User.Account;
|
|
using ShareeBike.Repository;
|
|
using ShareeBike.Services;
|
|
using ShareeBike.Services.BluetoothLock;
|
|
using ShareeBike.Services.Geolocation;
|
|
using ShareeBike.Services.Permissions;
|
|
|
|
namespace SharedBusinessLogic.Tests.Fixtures.UseCases.Logout
|
|
{
|
|
[TestFixture]
|
|
public class TestShareeBikeApp
|
|
{
|
|
[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>();
|
|
|
|
accountStore.Load().Returns(account);
|
|
account.Mail.Returns("javaminister@gmail.com");
|
|
account.Pwd.Returns("*********");
|
|
account.SessionCookie.Returns("6103_112e96b36ba33de245943c5ffaf369cd_");
|
|
|
|
// No user logged in is initial state to verify.
|
|
var l_oShareeBikeApp = new ShareeBikeApp(
|
|
new ShareeBike.Model.Settings.Settings(
|
|
activeLockService: locksService.GetType().FullName,
|
|
activeGeolocationService: "NotRelevantActiveGeoloactionServiceName",
|
|
activeUri: new Uri(CopriServerUriList.ShareeBike_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
|
|
|
|
Assert.That(l_oShareeBikeApp.ActiveUser.IsLoggedIn, Is.True);
|
|
// There are 6 bikes available and 2, one reserved and one rented by javaminsiter.
|
|
Assert.That(
|
|
l_oShareeBikeApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count, Is.EqualTo(10),
|
|
"Sum of bikes is 6 occupied plus 2 occupied.");
|
|
Assert.That(l_oShareeBikeApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count, Is.EqualTo(2),
|
|
"Javaminster occupies 2 bikes.");
|
|
Assert.That(l_oShareeBikeApp.GetConnector(true).Command.SessionCookie, Is.EqualTo("6103_112e96b36ba33de245943c5ffaf369cd_"));
|
|
|
|
// Log user out.
|
|
l_oShareeBikeApp.GetConnector(true).Command.DoLogout().Wait();
|
|
l_oShareeBikeApp.ActiveUser.Logout();
|
|
|
|
Assert.That(l_oShareeBikeApp.ActiveUser.IsLoggedIn, Is.False);
|
|
Assert.That(
|
|
l_oShareeBikeApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count, Is.EqualTo(8),
|
|
"Sum of bikes is 6 occupied, no one occupied because no user is logged in");
|
|
Assert.That(
|
|
l_oShareeBikeApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count, Is.EqualTo(0),
|
|
"If no user is logged in no occupied bikes are shown.");
|
|
Assert.That(l_oShareeBikeApp.GetConnector(true).Command.SessionCookie, Is.Null);
|
|
}
|
|
}
|
|
}
|