mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-22 04:46:30 +02:00
Tests fixed.
This commit is contained in:
parent
4df8aa98aa
commit
8aa3089f32
15 changed files with 779 additions and 82 deletions
|
@ -36,36 +36,36 @@ namespace TINK.Model.Connector
|
|||
/// If communication fails an exception is thrown.
|
||||
/// </summary>
|
||||
public async Task<IAccount> DoLogin(
|
||||
string p_strMail,
|
||||
string p_strPassword,
|
||||
string p_strDeviceId)
|
||||
string mail,
|
||||
string password,
|
||||
string deviceId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(p_strMail))
|
||||
if (string.IsNullOrEmpty(mail))
|
||||
{
|
||||
throw new ArgumentNullException("Can not loging user. Mail address must not be null or empty.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(p_strPassword))
|
||||
if (string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new ArgumentNullException("Can not loging user. Password must not be null or empty.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(p_strDeviceId))
|
||||
if (string.IsNullOrEmpty(deviceId))
|
||||
{
|
||||
throw new ArgumentNullException("Can not loging user. Device not be null or empty.");
|
||||
}
|
||||
|
||||
AuthorizationResponse l_oResponse;
|
||||
AuthorizationResponse response;
|
||||
try
|
||||
{
|
||||
l_oResponse = (await CopriServer.DoAuthorizationAsync(p_strMail, p_strPassword, p_strDeviceId)).GetIsResponseOk(p_strMail);
|
||||
response = (await CopriServer.DoAuthorizationAsync(mail, password, deviceId)).GetIsResponseOk(mail);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
var l_oAccount = l_oResponse.GetAccount(MerchantId, p_strMail, p_strPassword);
|
||||
var l_oAccount = response.GetAccount(MerchantId, mail, password);
|
||||
|
||||
// Log in state changes. Notify parent object to update.
|
||||
LoginStateChanged?.Invoke(this, new LoginStateChangedEventArgs(l_oAccount.SessionCookie, l_oAccount.Mail));
|
||||
|
@ -83,9 +83,9 @@ namespace TINK.Model.Connector
|
|||
/// <summary>
|
||||
/// Request to reserve a bike.
|
||||
/// </summary>
|
||||
/// <param name="p_oBike">Bike to book.</param>
|
||||
/// <param name="bike">Bike to book.</param>
|
||||
public async Task DoReserve(
|
||||
Bikes.Bike.BC.IBikeInfoMutable p_oBike)
|
||||
Bikes.Bike.BC.IBikeInfoMutable bike)
|
||||
{
|
||||
Log.ForContext<Command>().Error("Unexpected booking request detected. No user logged in.");
|
||||
await Task.CompletedTask;
|
||||
|
|
|
@ -5,12 +5,13 @@ namespace TINK.Model.Connector
|
|||
public static class FilteredConnectorFactory
|
||||
{
|
||||
/// <summary> Creates a filter object. </summary>
|
||||
/// <param name="group"></param>
|
||||
/// <param name="group">Filter to apply on stations and bikes.</param>
|
||||
/// <param name="connector">Connector to connect to COPRI.</param>
|
||||
public static IFilteredConnector Create(IEnumerable<string> group, IConnector connector)
|
||||
{
|
||||
return group != null
|
||||
? (IFilteredConnector) new FilteredConnector(group, connector)
|
||||
: new NullFilterConnector(connector);
|
||||
: new NullFilterConnector(connector); // Do not apply filtering.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ namespace TINK.Model.Connector
|
|||
{
|
||||
if (loginResponse == null)
|
||||
{
|
||||
throw new ArgumentNullException("p_oLoginResponse");
|
||||
throw new ArgumentNullException(nameof(loginResponse));
|
||||
}
|
||||
|
||||
return new Account(
|
||||
|
@ -165,13 +165,13 @@ namespace TINK.Model.Connector
|
|||
}
|
||||
|
||||
/// <summary> Gets bikes available from copri server response.</summary>
|
||||
/// <param name="p_oBikesAvailableResponse">Response to create collection from.</param>
|
||||
/// <param name="bikesAvailableResponse">Response to create collection from.</param>
|
||||
/// <returns>New collection of available bikes.</returns>
|
||||
public static BikeCollection GetBikesAvailable(
|
||||
this BikesAvailableResponse p_oBikesAvailableResponse)
|
||||
this BikesAvailableResponse bikesAvailableResponse)
|
||||
{
|
||||
return GetBikesAll(
|
||||
p_oBikesAvailableResponse,
|
||||
bikesAvailableResponse,
|
||||
new BikesReservedOccupiedResponse(), // There are no occupied bikes.
|
||||
string.Empty,
|
||||
() => DateTime.Now);
|
||||
|
@ -198,8 +198,8 @@ namespace TINK.Model.Connector
|
|||
public static BikeCollection GetBikesAll(
|
||||
BikesAvailableResponse bikesAvailableResponse,
|
||||
BikesReservedOccupiedResponse bikesOccupiedResponse,
|
||||
string p_strMail,
|
||||
Func<DateTime> p_oDateTimeProvider)
|
||||
string mail,
|
||||
Func<DateTime> dateTimeProvider)
|
||||
{
|
||||
var bikesDictionary = new Dictionary<string, BikeInfo>();
|
||||
var duplicates = new Dictionary<string, BikeInfo>();
|
||||
|
@ -242,8 +242,8 @@ namespace TINK.Model.Connector
|
|||
{
|
||||
BikeInfo bikeInfo = BikeInfoFactory.Create(
|
||||
bikeInfoResponse,
|
||||
p_strMail,
|
||||
p_oDateTimeProvider);
|
||||
mail,
|
||||
dateTimeProvider);
|
||||
|
||||
if (bikeInfo == null)
|
||||
{
|
||||
|
|
|
@ -147,7 +147,7 @@ namespace TINK.Model
|
|||
public TinkApp(
|
||||
Settings.Settings settings,
|
||||
IStore accountStore,
|
||||
Func<bool, Uri, string, string, TimeSpan, IConnector> connectorFactory,
|
||||
Func<bool, Uri, string /* session cookie*/, string /* mail address*/, TimeSpan, IConnector> connectorFactory,
|
||||
IServicesContainer<IGeolocation> geolocationServicesContainer,
|
||||
ILocksService locksService,
|
||||
ISmartDevice device,
|
||||
|
|
|
@ -6,12 +6,12 @@ namespace TINK.Model.User.Account
|
|||
public static class AccountExtensions
|
||||
{
|
||||
/// <summary> Gets information whether user is logged in or not from account object. </summary>
|
||||
/// <param name="p_oAccount">Object to get information from.</param>
|
||||
/// <param name="account">Object to get information from.</param>
|
||||
/// <returns>True if user is logged in, false if not.</returns>
|
||||
public static bool GetIsLoggedIn(this IAccount p_oAccount)
|
||||
public static bool GetIsLoggedIn(this IAccount account)
|
||||
{
|
||||
return !string.IsNullOrEmpty(p_oAccount.Mail)
|
||||
&& !string.IsNullOrEmpty(p_oAccount.SessionCookie);
|
||||
return !string.IsNullOrEmpty(account.Mail)
|
||||
&& !string.IsNullOrEmpty(account.SessionCookie);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -12,10 +12,6 @@ namespace TINK.Model.User.Account
|
|||
/// </summary>
|
||||
private Account m_oAccount;
|
||||
|
||||
/// <summary> Prevents an invalid instance to be created. </summary>
|
||||
private AccountMutable()
|
||||
{
|
||||
}
|
||||
|
||||
public AccountMutable(IAccount p_oSource)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1264,7 +1264,7 @@ namespace TINK.Repository
|
|||
}
|
||||
}";
|
||||
|
||||
private const SampleSets DEFAULT_SAMPLE_SET = SampleSets.Set2;
|
||||
private const SampleSets DEFAULT_SAMPLE_SET = SampleSets.Set2;
|
||||
|
||||
private const int DEFAULT_STAGE_INDEX = 1;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue