mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-21 21:46:27 +02:00
Legacy testing lib added..
This commit is contained in:
parent
0167fc321f
commit
47ed05837e
118 changed files with 17505 additions and 0 deletions
26
TestTINKLib/Mocks/Bike/BikeCollectionMock.cs
Normal file
26
TestTINKLib/Mocks/Bike/BikeCollectionMock.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using TINK.Model.Bike;
|
||||
|
||||
using BikeInfoMutable = TINK.Model.Bike.BC.BikeInfoMutable;
|
||||
|
||||
namespace TestTINKLib.Mocks.Bike
|
||||
{
|
||||
public class BikeCollectionMock : Collection<BikeInfoMutable>, IBikeDictionaryMutable<BikeInfoMutable>
|
||||
{
|
||||
public BikeInfoMutable GetById(string id)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void RemoveById(string id)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public bool ContainsKey(string id)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
106
TestTINKLib/Mocks/Connector/CopriCallsCacheMemory.cs
Normal file
106
TestTINKLib/Mocks/Connector/CopriCallsCacheMemory.cs
Normal file
|
@ -0,0 +1,106 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Response;
|
||||
using static TINK.Repository.CopriCallsMemory;
|
||||
using TINK.Repository.Request;
|
||||
using TINK.Model.Device;
|
||||
|
||||
namespace TestTINKLib.Mocks.Connector
|
||||
{
|
||||
/// <summary> Allows use of memory for retrieving defined respones.</summary>
|
||||
public class CopriCallsCacheMemory : ICopriCache
|
||||
{
|
||||
private CopriCallsMemory server;
|
||||
|
||||
public CopriCallsCacheMemory(
|
||||
SampleSets? sampleSet = null,
|
||||
int? index = null,
|
||||
string sessionCookie = null)
|
||||
{
|
||||
server = new CopriCallsMemory(sampleSet, index, sessionCookie);
|
||||
}
|
||||
|
||||
public bool IsStationsExpired => true;
|
||||
|
||||
public bool IsBikesAvailableExpired => true;
|
||||
|
||||
public bool IsBikesOccupiedExpired => true;
|
||||
|
||||
public bool IsConnected => server.IsConnected;
|
||||
|
||||
public string SessionCookie => server.SessionCookie;
|
||||
|
||||
public string MerchantId => server.MerchantId;
|
||||
|
||||
public void AddToCache(StationsAllResponse stations)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public void AddToCache(BikesAvailableResponse bikes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public void AddToCache(BikesReservedOccupiedResponse bikes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public Task<AuthorizationResponse> DoAuthorizationAsync(string p_strMailAddress, string p_strPassword, string p_strDeviceId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<AuthorizationoutResponse> DoAuthoutAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ReservationBookingResponse> DoReserveAsync(string bikeId, Uri operatorUri)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ReservationCancelReturnResponse> DoCancelReservationAsync(string p_iBikeId, Uri operatorUri)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ReservationBookingResponse> CalculateAuthKeysAsync(string bikeId, Uri operatorUri)
|
||||
=> throw new NotSupportedException();
|
||||
|
||||
public Task<ReservationBookingResponse> UpdateLockingStateAsync(string bikeId, LocationDto geolocation, lock_state state, double batteryPercentage, Uri operatorUri)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<ReservationBookingResponse> DoBookAsync(string bikeId, Guid guid, double batteryPercentage, Uri operatorUri)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ReservationCancelReturnResponse> DoReturn(string bikeId, LocationDto location, ISmartDevice smartDevice, Uri operatorUri)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, string message, bool isBikeBroken, Uri operatorUri)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<BikesAvailableResponse> GetBikesAvailableAsync()
|
||||
{
|
||||
return server.GetBikesAvailableAsync();
|
||||
}
|
||||
|
||||
public Task<BikesReservedOccupiedResponse> GetBikesOccupiedAsync()
|
||||
{
|
||||
return server.GetBikesOccupiedAsync();
|
||||
}
|
||||
|
||||
public Task<StationsAllResponse> GetStationsAsync()
|
||||
{
|
||||
return server.GetStationsAsync();
|
||||
}
|
||||
}
|
||||
}
|
82
TestTINKLib/Mocks/Connector/ExceptionServer.cs
Normal file
82
TestTINKLib/Mocks/Connector/ExceptionServer.cs
Normal file
|
@ -0,0 +1,82 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Device;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Request;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TestTINKLib.Mocks.Connector
|
||||
{
|
||||
/// <summary> Simulates communication errors when connecting to copri.</summary>
|
||||
public class ExceptionServer : ICopriServer
|
||||
{
|
||||
private Func<string, Exception> ExceptionFactory { get; }
|
||||
|
||||
/// <summary> Constructs object.</summary>
|
||||
/// <param name="exceptionFactory"> Provides exceptions which are thrown whenn querrying information from server.</param>
|
||||
public ExceptionServer(Func<string, Exception> exceptionFactory)
|
||||
{
|
||||
ExceptionFactory = exceptionFactory;
|
||||
}
|
||||
|
||||
public bool IsConnected => true;
|
||||
|
||||
public string SessionCookie => string.Empty;
|
||||
|
||||
public string MerchantId => string.Empty;
|
||||
|
||||
public Task<AuthorizationResponse> DoAuthorizationAsync(string p_strMailAddress, string p_strPassword, string p_strDeviceId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<AuthorizationoutResponse> DoAuthoutAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ReservationBookingResponse> DoReserveAsync(string bikeId, Uri operatorUri)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ReservationCancelReturnResponse> DoCancelReservationAsync(string p_iBikeId, Uri operatorUri)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ReservationBookingResponse> CalculateAuthKeysAsync(string bikeId, Uri operatorUri)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<ReservationBookingResponse> UpdateLockingStateAsync(string bikeId, LocationDto geolocation, lock_state state, double batteryPercentage, Uri operatorUri)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<ReservationBookingResponse> DoBookAsync(string bikeId, Guid guid, double batteryPercentage, Uri operatorUri)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ReservationCancelReturnResponse> DoReturn(string bikeId, LocationDto location, ISmartDevice smartDevice, Uri operatorUri)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, string message, bool isBikeBroken, Uri operatorUri)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<BikesAvailableResponse> GetBikesAvailableAsync()
|
||||
{
|
||||
throw ExceptionFactory($"Simulated error thrown at {nameof(GetBikesAvailableAsync)}.");
|
||||
}
|
||||
|
||||
public Task<BikesReservedOccupiedResponse> GetBikesOccupiedAsync()
|
||||
{
|
||||
throw ExceptionFactory($"Simulated error thrown at {nameof(GetBikesOccupiedAsync)}.");
|
||||
}
|
||||
|
||||
public Task<StationsAllResponse> GetStationsAsync()
|
||||
{
|
||||
throw ExceptionFactory($"Simulated error thrown at {nameof(GetStationsAsync)}.");
|
||||
}
|
||||
}
|
||||
}
|
24
TestTINKLib/Mocks/DateTimeMocker.cs
Normal file
24
TestTINKLib/Mocks/DateTimeMocker.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TestTINKLib
|
||||
{
|
||||
public class DateTimeMocker
|
||||
{
|
||||
private static int m_iIndex;
|
||||
private static IList<DateTime> m_oDateTimeSeries;
|
||||
|
||||
public DateTimeMocker(IList<DateTime> p_oDateTimeSeries)
|
||||
{
|
||||
if (p_oDateTimeSeries.Count < 1)
|
||||
{
|
||||
throw new Exception("Can not initialize mock object. List must contain at least one date time.");
|
||||
}
|
||||
|
||||
m_iIndex = 0;
|
||||
m_oDateTimeSeries = p_oDateTimeSeries;
|
||||
}
|
||||
|
||||
public Func<DateTime> GetDateTime = () => m_oDateTimeSeries[m_iIndex < m_oDateTimeSeries.Count ? m_iIndex++ : m_iIndex = 0];
|
||||
}
|
||||
}
|
46
TestTINKLib/Mocks/Device/DeviceMock.cs
Normal file
46
TestTINKLib/Mocks/Device/DeviceMock.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using TINK.Model.Device;
|
||||
|
||||
namespace TestTINKLib.Mocks.Device
|
||||
{
|
||||
public class DeviceMock : ISmartDevice
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the id of the device.
|
||||
/// </summary>
|
||||
private string m_strDeviceId = "522c6ff6886198fd";
|
||||
|
||||
public string Manufacturer => throw new System.NotImplementedException();
|
||||
|
||||
public string Model => throw new System.NotImplementedException();
|
||||
|
||||
public string PlatformText => throw new System.NotImplementedException();
|
||||
|
||||
public string VersionText => throw new System.NotImplementedException();
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a device mock object setting device id to default value.
|
||||
/// </summary>
|
||||
public DeviceMock()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a device mock object.
|
||||
/// </summary>
|
||||
/// <param name="p_strDeviceId">Mocked Id</param>
|
||||
public DeviceMock(string p_strDeviceId)
|
||||
{
|
||||
m_strDeviceId = p_strDeviceId;
|
||||
}
|
||||
|
||||
/// <summary> Gets the device ID.</summary>
|
||||
/// <returns></returns>
|
||||
public string Identifier
|
||||
=> m_strDeviceId;
|
||||
|
||||
/// <summary> Close the application. </summary>
|
||||
public void CloseApplication()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
23
TestTINKLib/Mocks/Device/SpecialFolderMock.cs
Normal file
23
TestTINKLib/Mocks/Device/SpecialFolderMock.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using TINK.Model.Device;
|
||||
|
||||
namespace TestTINKLib.Mocks.Device
|
||||
{
|
||||
public class SpecialFolderMock : ISpecialFolder
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the folder name of external folder to write to.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetExternalFilesDir()
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary> Gets the folder name of the personal data folder dir on internal storage. </summary>
|
||||
/// <returns>Directory name.</returns>
|
||||
public string GetInternalPersonalDir()
|
||||
{
|
||||
return System.IO.Path.GetTempPath();
|
||||
}
|
||||
}
|
||||
}
|
21
TestTINKLib/Mocks/Services/GeolocationMock.cs
Normal file
21
TestTINKLib/Mocks/Services/GeolocationMock.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Services.Geolocation;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace TestTINKLib.Mocks.Services
|
||||
{
|
||||
public class GeolocationMock : IGeolocation
|
||||
{
|
||||
|
||||
public Task<Location> GetAsync(DateTime? timeStamp = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary> If true location data returned is simulated.</summary>
|
||||
public bool IsSimulation { get => true; }
|
||||
|
||||
public bool IsGeolcationEnabled => true;
|
||||
}
|
||||
}
|
86
TestTINKLib/Mocks/Services/LocksServiceMock.cs
Normal file
86
TestTINKLib/Mocks/Services/LocksServiceMock.cs
Normal file
|
@ -0,0 +1,86 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Bike;
|
||||
using TINK.Model.Bike.BluetoothLock;
|
||||
using TINK.Services.BluetoothLock;
|
||||
using TINK.Services.BluetoothLock.Tdo;
|
||||
|
||||
namespace TestTINKLib.Mocks.Services
|
||||
{
|
||||
public class LocksServiceMock : ILocksService
|
||||
{
|
||||
/// <param name="connectTimeout">Timeout for connect operation of a single lock.</param>
|
||||
public async Task<IEnumerable<LockInfoTdo>> GetLocksStateAsync(IEnumerable<LockInfoAuthTdo> locksInfo, TimeSpan connectTimeout)
|
||||
{
|
||||
return await Task.FromResult(new List<LockInfoTdo>());
|
||||
}
|
||||
|
||||
/// <summary> Holds timeout values for series of connecting attemps to a lock or multiple locks. </summary>
|
||||
public ITimeOutProvider TimeOut { get; set; }
|
||||
|
||||
public void UpdateSimulation(BikeCollection bikes) {}
|
||||
|
||||
/// <summary> Opens lock.</summary>
|
||||
/// <param name="bike">Bike object to update.</param>
|
||||
public async Task<LockitLockingState?> OpenAsync(int lockId, byte[] copriKey) => await Task.FromResult(LockitLockingState.Open);
|
||||
|
||||
/// <summary> Closes lock.</summary>
|
||||
/// <param name="bike">Bike object to update.</param>
|
||||
public async Task<LockitLockingState?> CloseAsync(int lockId, byte[] copriKey) => await Task.FromResult(LockitLockingState.Closed);
|
||||
|
||||
/// <summary> Gets the state of a bike. </summary>
|
||||
/// <param name="lockId">Id of lockId to get state for.</param>
|
||||
/// <returns></returns>
|
||||
public async Task<LockitLockingState?> GetState(string lockId) => await Task.FromResult((LockitLockingState?)null);
|
||||
|
||||
/// <summary> Connects to lock.</summary>
|
||||
/// <param name="authInfo"> Info required to connect to lock.</param>
|
||||
/// <param name="connectTimeout">Timeout for connect operation.</param>
|
||||
public async Task<LockInfoTdo> ConnectAsync(LockInfoAuthTdo authInfo, TimeSpan connectTimeout)
|
||||
{
|
||||
return await Task.FromResult(new LockInfoTdo.Builder { Id = 12, Guid = new System.Guid("00000000-0000-0000-0000-000000000042"), State = null }.Build());
|
||||
}
|
||||
|
||||
/// <summary> Set sound settings.</summary>
|
||||
/// <param name="lockId">Id of lock to set sound settings.</param>
|
||||
public async Task<bool> SetSoundAsync(int lockId, SoundSettings settings)
|
||||
{
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
/// <summary> Gets battery percentage.</summary>
|
||||
/// <param name="lockId">Id of lock to get info for.</param>
|
||||
public Task<double> GetBatteryPercentageAsync(int lockId)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary> Sets whether alarm is on or off.</summary>
|
||||
/// <param name="lockId">Id of lock to get info from.</param>
|
||||
public async Task SetIsAlarmOffAsync(int lockId, bool activated)
|
||||
{
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
/// <summary> Gets whether alarm is on or off.</summary>
|
||||
/// <param name="lockId">Id of lock to get info for.</param>
|
||||
public async Task<bool> GetIsAlarmOffAsync(int lockId)
|
||||
{
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
/// <summary>Gets a lock by bike Id.</summary>
|
||||
/// <param name="bikeId"></param>
|
||||
/// <returns>Lock object</returns>
|
||||
public ILockService this[int bikeId]
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<LockingState> DisconnectAsync(int bikeId, Guid bikeGuid) => throw new NotSupportedException();
|
||||
}
|
||||
}
|
41
TestTINKLib/Mocks/Services/PermissionsMock.cs
Normal file
41
TestTINKLib/Mocks/Services/PermissionsMock.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using Plugin.Permissions;
|
||||
using Plugin.Permissions.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TestTINKLib.Mocks.Services
|
||||
{
|
||||
public class PermissionsMock : IPermissions
|
||||
{
|
||||
public async Task<PermissionStatus> CheckPermissionStatusAsync<T>() where T : BasePermission, new()
|
||||
{
|
||||
return await Task.FromResult(Plugin.Permissions.Abstractions.PermissionStatus.Granted);
|
||||
}
|
||||
|
||||
public Task<PermissionStatus> CheckPermissionStatusAsync(Permission permission)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool OpenAppSettings()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<PermissionStatus> RequestPermissionAsync<T>() where T : BasePermission, new()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<Dictionary<Permission, PermissionStatus>> RequestPermissionsAsync(params Permission[] permissions)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<bool> ShouldShowRequestPermissionRationaleAsync(Permission permission)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
41
TestTINKLib/Mocks/User/Account/StoreMock.cs
Normal file
41
TestTINKLib/Mocks/User/Account/StoreMock.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using System.Threading.Tasks;
|
||||
using TINK.Model.User.Account;
|
||||
|
||||
namespace TestTINKLib.Model.User.Account
|
||||
{
|
||||
public class StoreMock : IStore
|
||||
{
|
||||
IAccount m_oAccount;
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates
|
||||
/// - a dummy account to simulate a logged in user before end of last session
|
||||
/// - an empty account to simulate no user logged in before end of last session
|
||||
/// </summary>
|
||||
/// <param name="p_oAccount">If null no user is logged in.</param>
|
||||
public StoreMock(IAccount p_oAccount = null)
|
||||
{
|
||||
m_oAccount = new TINK.Model.User.Account.Account(p_oAccount ?? new EmptyAccount());
|
||||
}
|
||||
|
||||
public Task<IAccount> Load()
|
||||
{
|
||||
return Task.FromResult<IAccount>(new TINK.Model.User.Account.Account(m_oAccount));
|
||||
}
|
||||
|
||||
public IAccount Delete(IAccount p_oAccount)
|
||||
{
|
||||
// Set member to empty.
|
||||
m_oAccount = new EmptyAccount();
|
||||
|
||||
// Return empty account.
|
||||
return new EmptyAccount();
|
||||
}
|
||||
|
||||
public Task Save(IAccount p_oAccount)
|
||||
{
|
||||
m_oAccount = new TINK.Model.User.Account.Account(p_oAccount);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue