sharee.bike-App/SharedBusinessLogic.Tests/Model/User/TestUser.cs

100 lines
2.8 KiB
C#
Raw Normal View History

2023-02-22 14:03:35 +01:00
using System;
2022-08-30 15:42:25 +02:00
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
2024-04-09 12:53:23 +02:00
using SharedBusinessLogic.Tests.Framework.Model.User.Account;
using ShareeBike.Model.Connector;
using ShareeBike.Model.User;
using ShareeBike.Model.User.Account;
using ShareeBike.Repository;
using static ShareeBike.Repository.CopriCallsMemory;
namespace SharedBusinessLogic.Tests
2021-07-12 21:31:46 +02:00
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestUser
{
[Test]
public void TestConstruct_NotLoggedIn_NoUsername()
{
var storeMock = new StoreMock(); // Account without user name, password and cookie
var l_oUser = new User(
storeMock,
storeMock.Load().Result,
"HwId1000000000000");
2024-04-09 12:53:23 +02:00
Assert.That(l_oUser.IsLoggedIn, Is.False);
Assert.That(l_oUser.Mail, Is.Null);
Assert.That(l_oUser.Password, Is.Null);
Assert.That(l_oUser.SessionCookie, Is.Null);
2022-09-06 16:08:19 +02:00
}
[Test]
public void TestConstruct_NotLoggedIn_NoCookie()
{
var storeMock = new StoreMock(new Account("John", "123", true, null, new List<string>())); // Account without session cookie.
var user = new User(
storeMock,
storeMock.Load().Result,
"123456789");
2024-04-09 12:53:23 +02:00
Assert.That(user.IsLoggedIn, Is.False);
Assert.That(user.Mail, Is.EqualTo("John"));
Assert.That(user.Password, Is.EqualTo("123"));
Assert.That(user.SessionCookie, Is.Null);
2022-09-06 16:08:19 +02:00
}
[Test]
public void TestConstruct_LoggedIn()
{
2024-04-09 12:53:23 +02:00
var l_oStoreMock = new StoreMock(new Account("John", "123", false, "9512", new List<string> { "ShareeBike" }));
2022-09-06 16:08:19 +02:00
var l_oUser = new User(
l_oStoreMock,
l_oStoreMock.Load().Result,
"123456789");
2024-04-09 12:53:23 +02:00
Assert.That(l_oUser.IsLoggedIn, Is.True, "If store does not hold cookie user is considered to not be logged in");
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
Assert.That(l_oUser.Mail, Is.EqualTo("John"));
Assert.That(l_oUser.Password, Is.EqualTo("123"));
Assert.That(l_oUser.SessionCookie, Is.EqualTo("9512"));
2022-09-06 16:08:19 +02:00
}
/// <summary>Test logging in. </summary>
[Test]
public async Task TestSetCredentials()
{
var l_oConnector = new ConnectorCache(
new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)),
null /*UI language */,
string.Empty,
string.Empty,
2023-02-22 14:03:35 +01:00
server: new CopriCallsMemory("MyMerchId", SampleSets.Set2, 1));
2022-09-06 16:08:19 +02:00
var l_oStoreMock = new StoreMock(); // Account without user name, password and cookie
var l_oUser = new User(
l_oStoreMock,
l_oStoreMock.Load().Result,
"HwId1000000000000");
2024-04-09 12:53:23 +02:00
Assert.That(l_oUser.IsLoggedIn, Is.False);
Assert.That(l_oUser.Mail, Is.Null);
2022-09-06 16:08:19 +02:00
IAccount l_oAccount = l_oConnector.Command.DoLogin(
LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
l_oUser.DeviceId).Result;
await l_oUser.Login(l_oAccount);
2024-04-09 12:53:23 +02:00
Assert.That(l_oUser.IsLoggedIn, Is.True);
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
Assert.That(l_oUser.Mail, Is.EqualTo(LoginSessionCopriInfo.JavaministerHardwareNr1.Mail));
2022-09-06 16:08:19 +02:00
}
}
2021-07-12 21:31:46 +02:00
}