mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-15 22:56:37 +01:00
99 lines
2.8 KiB
C#
99 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
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
|
|
{
|
|
|
|
[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");
|
|
|
|
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);
|
|
}
|
|
|
|
[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");
|
|
|
|
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);
|
|
}
|
|
|
|
[Test]
|
|
public void TestConstruct_LoggedIn()
|
|
{
|
|
var l_oStoreMock = new StoreMock(new Account("John", "123", false, "9512", new List<string> { "ShareeBike" }));
|
|
|
|
var l_oUser = new User(
|
|
l_oStoreMock,
|
|
l_oStoreMock.Load().Result,
|
|
"123456789");
|
|
|
|
Assert.That(l_oUser.IsLoggedIn, Is.True, "If store does not hold cookie user is considered to not be logged in");
|
|
|
|
Assert.That(l_oUser.Mail, Is.EqualTo("John"));
|
|
Assert.That(l_oUser.Password, Is.EqualTo("123"));
|
|
Assert.That(l_oUser.SessionCookie, Is.EqualTo("9512"));
|
|
}
|
|
|
|
/// <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,
|
|
server: new CopriCallsMemory("MyMerchId", 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.That(l_oUser.IsLoggedIn, Is.False);
|
|
Assert.That(l_oUser.Mail, Is.Null);
|
|
|
|
IAccount l_oAccount = l_oConnector.Command.DoLogin(
|
|
LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
|
LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
|
l_oUser.DeviceId).Result;
|
|
|
|
await l_oUser.Login(l_oAccount);
|
|
Assert.That(l_oUser.IsLoggedIn, Is.True);
|
|
|
|
Assert.That(l_oUser.Mail, Is.EqualTo(LoginSessionCopriInfo.JavaministerHardwareNr1.Mail));
|
|
}
|
|
}
|
|
}
|