Version 3.0.381

This commit is contained in:
Anja 2024-04-09 12:53:23 +02:00
parent f963c0a219
commit 3a363acf3a
1525 changed files with 60589 additions and 125098 deletions

View file

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
namespace UITest.Fixtures.ObjectTests.User.Account
{
[TestFixture]
public class TestAccount
{
[Test]
public void TestConstruct()
{
// Act
var account = new ShareeBike.Model.User.Account.Account(
"hans.musterman@hotmail.com", // Mail
"myPasswd", // Pwd
false,
"aktuellerKeks", // Cookie
new List<string> { "Honkey", "Tonkey" }, // Group
ShareeBike.Model.User.Account.Permissions.None);
// Assert
Assert.That(account.Mail, Is.EqualTo("hans.musterman@hotmail.com"));
Assert.That(account.Pwd, Is.EqualTo("myPasswd"));
Assert.That(account.IsAgbAcknowledged, Is.False);
Assert.That(account.SessionCookie, Is.EqualTo("aktuellerKeks"));
Assert.That(String.Join(",", account.Group), Is.EqualTo("Honkey,Tonkey"));
Assert.That(account.DebugLevel, Is.EqualTo(ShareeBike.Model.User.Account.Permissions.None));
}
[Test]
public void TestConstruct_Copy()
{
var account = new ShareeBike.Model.User.Account.Account(new ShareeBike.Model.User.Account.Account(
"a@b",
"112",
true, // Agbs have been acknowledged
"3330",
new List<string> { "Honkey", "Tonkey" },
ShareeBike.Model.User.Account.Permissions.None));
Assert.That(account.Mail, Is.EqualTo("a@b"));
Assert.That(account.Pwd, Is.EqualTo("112"));
Assert.That(account.IsAgbAcknowledged, Is.True);
Assert.That(account.SessionCookie, Is.EqualTo("3330"));
Assert.That(String.Join(",", account.Group), Is.EqualTo("Honkey,Tonkey"));
Assert.That(account.DebugLevel, Is.EqualTo(ShareeBike.Model.User.Account.Permissions.None));
}
[Test]
public void TestConstruct_InvalidGroup()
{
Assert.Throws<ArgumentException>(() => new ShareeBike.Model.User.Account.Account("a@b", "112", false, "3330", null, ShareeBike.Model.User.Account.Permissions.None));
Assert.Throws<ArgumentException>(() => new ShareeBike.Model.User.Account.Account(null));
}
}
}

View file

@ -0,0 +1,51 @@
using System.Collections.Generic;
using System.Linq;
using NSubstitute;
using NUnit.Framework;
using ShareeBike.Model.Connector;
using ShareeBike.Model.User.Account;
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.User.Account
{
[TestFixture]
public class TestAccountExtensions
{
/// <summary> If no user is logged in filter is not applied. </summary>
[Test]
public void TestDoFilter_NoUserLoggedIn()
{
var l_oAccount = Substitute.For<IAccount>();
l_oAccount.Mail.Returns("a@b");
l_oAccount.SessionCookie.Returns(""); // User is not logged in
l_oAccount.Group.Returns(new List<string> { $"HOM_{FilterHelper.CARGOBIKE}", "HOM_117025" });
var l_oSource = new List<string> { $"HOM_{FilterHelper.CARGOBIKE}", $"HOM_{FilterHelper.CITYBIKE}", "HOM_117025" };
var l_oResult = l_oAccount.DoFilter(l_oSource);
Assert.That(l_oResult.ToList().Count, Is.EqualTo(3));
Assert.That(l_oResult.ToList()[0], Is.EqualTo($"HOM_{FilterHelper.CARGOBIKE}"));
Assert.That(l_oResult.ToList()[1], Is.EqualTo($"HOM_{FilterHelper.CITYBIKE}"));
Assert.That(l_oResult.ToList()[2], Is.EqualTo("HOM_117025"));
}
/// <summary> </summary>
[Test]
public void TestDoFilter()
{
var l_oAccount = Substitute.For<IAccount>();
l_oAccount.Mail.Returns("a@b");
l_oAccount.SessionCookie.Returns("123");
l_oAccount.Group.Returns(new List<string> { $"HOM_{FilterHelper.CARGOBIKE}", "HOM_117025" });
var l_oSource = new List<string> { $"HOM_{FilterHelper.CARGOBIKE}", $"HOM_{FilterHelper.CITYBIKE}", "HOM_117025" };
var l_oResult = l_oAccount.DoFilter(l_oSource);
Assert.That(l_oResult.ToList().Count, Is.EqualTo(2));
Assert.That(l_oResult.ToList()[0], Is.EqualTo($"HOM_{FilterHelper.CARGOBIKE}"));
Assert.That(l_oResult.ToList()[1], Is.EqualTo("HOM_117025"));
}
}
}

View file

@ -0,0 +1,30 @@
using NUnit.Framework;
using ShareeBike.Model.User.Account;
namespace SharedBusinessLogic.Tests
{
[TestFixture]
public class TestValidator
{
[Test]
public void TestValidateMailAndPasswordDelegate()
{
Assert.That(Validator.ValidateMailAndPasswordDelegate(null, null).ValidElement, Is.EqualTo(Elements.None));
Assert.That(Validator.ValidateMailAndPasswordDelegate("", null).ValidElement, Is.EqualTo(Elements.None));
Assert.That(Validator.ValidateMailAndPasswordDelegate("a", null).ValidElement, Is.EqualTo(Elements.None));
Assert.That(Validator.ValidateMailAndPasswordDelegate("a@", null).ValidElement, Is.EqualTo(Elements.None));
Assert.That(Validator.ValidateMailAndPasswordDelegate("a@c", "").ValidElement, Is.EqualTo(Elements.Mail));
Assert.That(Validator.ValidateMailAndPasswordDelegate("a@c", "123").ValidElement, Is.EqualTo(Elements.Mail));
Assert.That(Validator.ValidateMailAndPasswordDelegate("a@c", "123456789" /* password */).ValidElement, Is.EqualTo(Elements.Mail | Elements.Password));
}
}
}

View file

@ -0,0 +1,99 @@
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));
}
}
}