Legacy testing lib added..

This commit is contained in:
Oliver Hauff 2021-07-12 21:31:46 +02:00
parent 0167fc321f
commit 47ed05837e
118 changed files with 17505 additions and 0 deletions

View file

@ -0,0 +1,42 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
namespace UITest.Fixtures.ObjectTests.User.Account
{
[TestFixture]
public class TestAccount
{
[Test]
public void TestConstruct()
{
var l_oAccount = new TINK.Model.User.Account.Account("a@b", "112", "3330", new List<string> { "Honkey", "Tonkey" }, TINK.Model.User.Account.Permissions.None);
Assert.AreEqual("a@b", l_oAccount.Mail);
Assert.AreEqual("112", l_oAccount.Pwd);
Assert.AreEqual("3330", l_oAccount.SessionCookie);
Assert.AreEqual("Honkey,Tonkey", String.Join(",", l_oAccount.Group));
Assert.AreEqual(TINK.Model.User.Account.Permissions.None, l_oAccount.DebugLevel);
}
[Test]
public void TestConstruct_Copy()
{
var l_oAccount = new TINK.Model.User.Account.Account(new TINK.Model.User.Account.Account("a@b", "112", "3330", new List<string> { "Honkey", "Tonkey" },TINK.Model.User.Account.Permissions.None));
Assert.AreEqual("a@b", l_oAccount.Mail);
Assert.AreEqual("112", l_oAccount.Pwd);
Assert.AreEqual("3330", l_oAccount.SessionCookie);
Assert.AreEqual("Honkey,Tonkey", String.Join(",", l_oAccount.Group));
Assert.AreEqual(TINK.Model.User.Account.Permissions.None, l_oAccount.DebugLevel);
}
[Test]
public void TestConstruct_InvalidGroup()
{
Assert.Throws<ArgumentException>(() => new TINK.Model.User.Account.Account("a@b", "112", "3330", null, TINK.Model.User.Account.Permissions.None));
Assert.Throws<ArgumentException>(() => new TINK.Model.User.Account.Account(null));
}
}
}

View file

@ -0,0 +1,50 @@
using NUnit.Framework;
using Rhino.Mocks;
using System.Collections.Generic;
using System.Linq;
using TINK.Model.User.Account;
namespace TestTINKLib.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 = MockRepository.GenerateMock<IAccount>();
l_oAccount.Stub((x) => x.Mail).Return("a@b");
l_oAccount.Stub((x) => x.SessionCookie).Return(""); // User is not logged in
l_oAccount.Stub((x) => x.Group).Return(new List<string> { "TINK", "FutureType" });
var l_oSource = new List<string> { "TINK", "Konrad", "FutureType" };
var l_oResult = l_oAccount.DoFilter(l_oSource);
Assert.AreEqual(3, l_oResult.ToList().Count);
Assert.AreEqual("TINK", l_oResult.ToList()[0]);
Assert.AreEqual("Konrad", l_oResult.ToList()[1]);
Assert.AreEqual("FutureType", l_oResult.ToList()[2]);
}
/// <summary> </summary>
[Test]
public void TestDoFilter()
{
var l_oAccount = MockRepository.GenerateMock<IAccount>();
l_oAccount.Stub((x) => x.Mail).Return("a@b");
l_oAccount.Stub((x) => x.SessionCookie).Return("123");
l_oAccount.Stub((x) => x.Group).Return(new List<string> { "TINK", "FutureType" });
var l_oSource = new List<string> { "TINK", "Konrad", "FutureType" };
var l_oResult = l_oAccount.DoFilter(l_oSource);
Assert.AreEqual(2, l_oResult.ToList().Count);
Assert.AreEqual("TINK", l_oResult.ToList()[0]);
Assert.AreEqual("FutureType", l_oResult.ToList()[1]);
}
}
}

View file

@ -0,0 +1,24 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using TINK.Model.User.Account;
namespace UITest.Fixtures.ObjectTests.User.Account
{
[TestFixture]
public class TestStore
{
[Test, Explicit("Did never ran, file load exception.")]
public void TestLoadSaveRoundtrip()
{
var l_oStore = new Store("4711");
l_oStore.Save(new TINK.Model.User.Account.Account("a@b", "112", "3330", new List<string> { "Honkey", "Tonkey" }, 17));
var l_oAccount = l_oStore.Load();
Assert.AreEqual("a@b", l_oAccount.Mail);
Assert.AreEqual("112", l_oAccount.Pwd);
Assert.AreEqual("3330", l_oAccount.SessionCookie);
Assert.AreEqual("Honkey,Tonkey", String.Join(",", l_oAccount.Group));
Assert.AreEqual(17, l_oAccount.DebugLevel);
}
}
}

View file

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

View file

@ -0,0 +1,97 @@
using NUnit.Framework;
using TINK.Model.User;
using TINK.Model.Connector;
using TestTINKLib.Model.User.Account;
using TINK.Model.User.Account;
using System.Collections.Generic;
using TINK.Repository;
using static TINK.Repository.CopriCallsMemory;
namespace TestTINKLib
{
[TestFixture]
public class TestUser
{
[Test]
public void TestConstruct_NotLoggedIn_NoUsername()
{
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);
Assert.IsNull(l_oUser.Password);
Assert.IsNull(l_oUser.SessionCookie);
}
[Test]
public void TestConstruct_NotLoggedIn_NoCookie()
{
var l_oStoreMock = new StoreMock(new Account("John", "123", null, new List<string>())); // Account without session cookie.
var l_oUser = new User(
l_oStoreMock,
l_oStoreMock.Load().Result,
"123456789");
Assert.IsFalse(l_oUser.IsLoggedIn);
Assert.AreEqual("John", l_oUser.Mail);
Assert.AreEqual("123", l_oUser.Password);
Assert.IsNull(l_oUser.SessionCookie);
}
[Test]
public void TestConstruct_LoggedIn()
{
var l_oStoreMock = new StoreMock(new Account("John", "123", "9512", new List<string> { "TINK" }));
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]
public void TestSetCredentials()
{
var l_oConnector = new ConnectorCache(
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;
l_oUser.Login(l_oAccount);
Assert.IsTrue(l_oUser.IsLoggedIn);
Assert.AreEqual(LoginSessionCopriInfo.JavaministerHardwareNr1.Mail, l_oUser.Mail);
}
}
}