sharee.bike-App/TestTINKLib/Fixtures/ObjectTests/User/TestUser.cs

101 lines
3.2 KiB
C#
Raw Permalink Normal View History

2021-07-12 21:31:46 +02:00
using NUnit.Framework;
using TINK.Model.User;
using TINK.Model.Connector;
using TINK.Model.User.Account;
using System.Collections.Generic;
using TINK.Repository;
using static TINK.Repository.CopriCallsMemory;
2021-11-14 23:27:29 +01:00
using TestFramework.Model.User.Account;
2022-01-04 18:59:16 +01:00
using System;
using System.Threading.Tasks;
2021-07-12 21:31:46 +02:00
namespace TestTINKLib
{
[TestFixture]
public class TestUser
{
[Test]
public void TestConstruct_NotLoggedIn_NoUsername()
{
2022-01-04 18:59:16 +01:00
var storeMock = new StoreMock(); // Account without user name, password and cookie
2021-07-12 21:31:46 +02:00
var l_oUser = new User(
2022-01-04 18:59:16 +01:00
storeMock,
storeMock.Load().Result,
2021-07-12 21:31:46 +02:00
"HwId1000000000000");
Assert.IsFalse(l_oUser.IsLoggedIn);
Assert.IsNull(l_oUser.Mail);
Assert.IsNull(l_oUser.Password);
Assert.IsNull(l_oUser.SessionCookie);
}
[Test]
public void TestConstruct_NotLoggedIn_NoCookie()
{
2022-01-04 18:59:16 +01:00
var storeMock = new StoreMock(new Account("John", "123", true, null, new List<string>())); // Account without session cookie.
2021-07-12 21:31:46 +02:00
2022-01-04 18:59:16 +01:00
var user = new User(
storeMock,
storeMock.Load().Result,
2021-07-12 21:31:46 +02:00
"123456789");
2022-01-04 18:59:16 +01:00
Assert.IsFalse(user.IsLoggedIn);
Assert.AreEqual("John", user.Mail);
Assert.AreEqual("123", user.Password);
Assert.IsNull(user.SessionCookie);
2021-07-12 21:31:46 +02:00
}
[Test]
public void TestConstruct_LoggedIn()
{
2022-01-04 18:59:16 +01:00
var l_oStoreMock = new StoreMock(new Account("John", "123", false, "9512", new List<string> { "TINK" }));
2021-07-12 21:31:46 +02:00
var l_oUser = new User(
l_oStoreMock,
l_oStoreMock.Load().Result,
"123456789");
Assert.IsTrue(l_oUser.IsLoggedIn, "If store does not hold cookie user is considered to not be logged in");
Assert.AreEqual("John", l_oUser.Mail);
Assert.AreEqual("123", l_oUser.Password);
Assert.AreEqual("9512", l_oUser.SessionCookie);
}
/// <summary>Test logging in. </summary>
[Test]
2022-01-04 18:59:16 +01:00
public async Task TestSetCredentials()
2021-07-12 21:31:46 +02:00
{
var l_oConnector = new ConnectorCache(
2022-01-04 18:59:16 +01:00
new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)),
2021-07-12 21:31:46 +02:00
string.Empty,
string.Empty,
new CopriCallsMemory(SampleSets.Set2, 1));
var l_oStoreMock = new StoreMock(); // Account without user name, password and cookie
var l_oUser = new User(
l_oStoreMock,
l_oStoreMock.Load().Result,
"HwId1000000000000");
Assert.IsFalse(l_oUser.IsLoggedIn);
Assert.IsNull(l_oUser.Mail);
IAccount l_oAccount = l_oConnector.Command.DoLogin(
LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
l_oUser.DeviceId).Result;
2022-01-04 18:59:16 +01:00
await l_oUser.Login(l_oAccount);
2021-07-12 21:31:46 +02:00
Assert.IsTrue(l_oUser.IsLoggedIn);
Assert.AreEqual(LoginSessionCopriInfo.JavaministerHardwareNr1.Mail, l_oUser.Mail);
}
}
}