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; using Plugin.Permissions.Abstractions; using TestShareeLib.Repository; namespace TestTINKLib.Fixtures.UseCases.Logout { [TestFixture] public class TestTinkApp { [Test] public void Logout() { var accountStore = Substitute.For(); var locksService = Substitute.For(); var device = Substitute.For(); var specialFolder = Substitute.For(); var permissions = Substitute.For(); var account = Substitute.For(); 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_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 CopriCallsMemory001()) : new ConnectorCache(sessionCookie, mail, new CopriCallsMemory001(sessionCookie)), Substitute.For>(), 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 Assert.IsTrue(l_oTinkApp.ActiveUser.IsLoggedIn); // There are 6 bikes available and 2, one reserved and one rented by javaminsiter. Assert.AreEqual( 8, 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); // Log user out. l_oTinkApp.GetConnector(true).Command.DoLogout().Wait(); l_oTinkApp.ActiveUser.Logout(); Assert.IsFalse(l_oTinkApp.ActiveUser.IsLoggedIn); Assert.AreEqual( 6, 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."); Assert.IsNull(l_oTinkApp.GetConnector(true).Command.SessionCookie); } } }