Tests fixed.

This commit is contained in:
Oliver Hauff 2021-11-08 23:11:56 +01:00
parent 4df8aa98aa
commit 8aa3089f32
15 changed files with 779 additions and 82 deletions

View file

@ -13,15 +13,13 @@ namespace TINK.Model.User
/// </summary>
public class User : IUser
{
/// <summary>
/// Holds account data.
/// </summary>
private readonly AccountMutable m_oAccount;
/// <summary> Holds account data. </summary>
private AccountMutable Account { get; }
/// <summary>
/// Provides storing functionality.
/// </summary>
private IStore m_oStore;
private IStore Store { get; }
/// <summary> Holds the id of the device. </summary>
public string DeviceId { get; }
@ -34,10 +32,10 @@ namespace TINK.Model.User
IAccount account,
string deviceId)
{
m_oStore = accountStore
Store = accountStore
?? throw new ArgumentException("Can not instantiate user- object. No store functionality available.");
DeviceId = deviceId;
m_oAccount = new AccountMutable(account);
Account = new AccountMutable(account);
}
/// <summary> Is fired wheneverlogin state changes. </summary>
@ -46,19 +44,14 @@ namespace TINK.Model.User
/// <summary>
/// Holds a value indicating whether user is logged in or not.
/// </summary>
public bool IsLoggedIn {
get
{
return m_oAccount.GetIsLoggedIn();
}
}
public bool IsLoggedIn => Account.GetIsLoggedIn();
/// <summary>
/// Holds the mail address.
/// </summary>
public string Mail
{
get { return m_oAccount.Mail; }
get { return Account.Mail; }
}
/// <summary>
@ -66,24 +59,24 @@ namespace TINK.Model.User
/// </summary>
public string SessionCookie
{
get { return m_oAccount.SessionCookie; }
get { return Account.SessionCookie; }
}
/// <summary>
/// Holds the password.
/// </summary>
public string Password
{
get { return m_oAccount.Pwd; }
get { return Account.Pwd; }
}
/// <summary>Holds the debug level.</summary>
public Permissions DebugLevel
{
get { return m_oAccount.DebugLevel; }
get { return Account.DebugLevel; }
}
/// <summary> Holds the group of the bike (TINK, Konrad, ...).</summary>
public IEnumerable<string> Group { get { return m_oAccount.Group; } }
public IEnumerable<string> Group { get { return Account.Group; } }
/// <summary> Logs in user. </summary>
/// <param name="p_oAccount">Account to use for login.</param>
@ -93,7 +86,7 @@ namespace TINK.Model.User
{
if (IsLoggedIn)
{
throw new Exception($"Can not log in user {mail} because user {m_oAccount} is already logged in.");
throw new Exception($"Can not log in user {mail} because user {Account} is already logged in.");
}
// Check if password might be valid before connecting to copri.
@ -113,10 +106,10 @@ namespace TINK.Model.User
public async Task Login(IAccount account)
{
// Update account instance from copri data.
m_oAccount.Copy(account);
Account.Copy(account);
// Save data to store.
await m_oStore.Save(m_oAccount);
await Store.Save(Account);
// Nothing to do because state did not change.
StateChanged?.Invoke(this, new EventArgs());
@ -128,7 +121,7 @@ namespace TINK.Model.User
{
var l_oPreviousState = IsLoggedIn;
m_oAccount.Copy(m_oStore.Delete(m_oAccount));
Account.Copy(Store.Delete(Account));
if (IsLoggedIn == l_oPreviousState)
{
@ -144,11 +137,11 @@ namespace TINK.Model.User
/// Some user may be "TINK"- user only, some "Konrad" and some may be "TINK" and "Konrad" users.
/// </summary>
/// <param name="p_oAccount">Account to filter with.</param>
/// <param name="p_oSource">Groups to filter..</param>
/// <param name="source">Groups to filter..</param>
/// <returns>Filtered bike groups.</returns>
public IEnumerable<string> DoFilter(IEnumerable<string> p_oSource = null)
public IEnumerable<string> DoFilter(IEnumerable<string> source = null)
{
return m_oAccount.DoFilter(p_oSource);
return Account.DoFilter(source);
}
}
}