mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-22 21:06:30 +02:00
Version 3.0.362
This commit is contained in:
parent
cba4da9357
commit
4ff3307997
128 changed files with 3954 additions and 3193 deletions
|
@ -1,198 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Response;
|
||||
using TINK.Services.CopriApi;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Query
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCachedQuery
|
||||
{
|
||||
private const string BIKESAVAILABLE = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""bikes"" : {},
|
||||
""response_state"" : ""OK"",
|
||||
""apiserver"" : ""https://app.tink-konstanz.de"",
|
||||
""authcookie"" : """",
|
||||
""response"" : ""bikes_available"",
|
||||
""bikes"" : {
|
||||
""2352"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
||||
""station"" : ""9""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
private const string STATIONSALL = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""stations"" : {
|
||||
""5"" : {
|
||||
""station"" : ""5"",
|
||||
""bike_soll"" : ""0"",
|
||||
""bike_ist"" : ""7"",
|
||||
""station_group"" : [ ""TINK"" ],
|
||||
""gps"" : { ""latitude"": ""47.66756"", ""longitude"": ""9.16477"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : """"
|
||||
},
|
||||
""13"" : {
|
||||
""station"" : ""13"",
|
||||
""bike_soll"" : ""4"",
|
||||
""bike_ist"" : ""1"",
|
||||
""station_group"" : [ ""TINK"" ],
|
||||
""gps"" : { ""latitude"": ""47.657756"", ""longitude"": ""9.176084"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : """"
|
||||
},
|
||||
""30"" : {
|
||||
""station"" : ""30"",
|
||||
""bike_soll"" : ""5"",
|
||||
""bike_ist"" : ""0"",
|
||||
""station_group"" : [ ""TINK"", ""Konrad"" ],
|
||||
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : ""Test für Stadtradstation""
|
||||
}
|
||||
},
|
||||
""user_group"" : [ ""Konrad"", ""TINK"" ],
|
||||
""response_state"" : ""OK"",
|
||||
""authcookie"" : ""6103_f782a208d9399291ba8d086b5dcc2509_12345678"",
|
||||
""debuglevel"" : ""2"",
|
||||
""response"" : ""stations_all"",
|
||||
""user_id"" : ""javaminister@gmail.com"",
|
||||
""apiserver"" : ""https://tinkwwp.copri-bike.de""
|
||||
}";
|
||||
|
||||
private const string STATIONSALLEMPTY = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""stations"" : {
|
||||
},
|
||||
""user_group"" : [ ""Konrad"", ""TINK"" ],
|
||||
""response_state"" : ""OK"",
|
||||
""authcookie"" : ""6103_f782a208d9399291ba8d086b5dcc2509_12345678"",
|
||||
""debuglevel"" : ""2"",
|
||||
""response"" : ""stations_all"",
|
||||
""user_id"" : ""javaminister@gmail.com"",
|
||||
""apiserver"" : ""https://tinkwwp.copri-bike.de""
|
||||
}";
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_StationsFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALL),
|
||||
new GeneralData(),
|
||||
new System.Exception("Bang when getting stations..."))));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new GeneralData())));
|
||||
|
||||
var result = await new CachedQuery(server).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(1, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang when getting stations...", result.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_BikesAvailableFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALLEMPTY),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new GeneralData(),
|
||||
new System.Exception("Bang when getting bikes..."))));
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<StationsAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALL),
|
||||
new GeneralData())));
|
||||
|
||||
var result = await new CachedQuery(server).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(1, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang when getting bikes...", result.Exception.Message);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALL),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.AddToCache(Arg<Result<StationsAvailableResponse>>.Is.Anything));
|
||||
server.Stub(x => x.AddToCache(Arg<Result<BikesAvailableResponse>>.Is.Anything));
|
||||
|
||||
var result = await new CachedQuery(server).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(1, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikes()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable()).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.AddToCache(Arg<Result<BikesAvailableResponse>>.Is.Anything));
|
||||
|
||||
var result = await new CachedQuery(server).GetBikesAsync();
|
||||
|
||||
Assert.AreEqual(1, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
var result = await new CachedQuery(server).GetBikesOccupiedAsync();
|
||||
|
||||
Assert.AreEqual(0, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual(result.Exception.Message, "Abfrage der reservierten/ gebuchten Räder nicht möglich. Kein Benutzer angemeldet.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,363 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Response;
|
||||
using TINK.Services.CopriApi;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Query
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestCachedQueryLoggedIn
|
||||
{
|
||||
private const string BIKESAVAILABLE = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""bikes"" : {},
|
||||
""response_state"" : ""OK"",
|
||||
""apiserver"" : ""https://app.tink-konstanz.de"",
|
||||
""authcookie"" : """",
|
||||
""response"" : ""bikes_available"",
|
||||
""bikes"" : {
|
||||
""2352"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
||||
""station"" : ""9""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
private const string BIKESAVAILABLEEMPTY = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""bikes"" : {},
|
||||
""response_state"" : ""OK"",
|
||||
""apiserver"" : ""https://app.tink-konstanz.de"",
|
||||
""authcookie"" : """",
|
||||
""response"" : ""bikes_available"",
|
||||
""bikes"" : {
|
||||
}
|
||||
}";
|
||||
|
||||
private const string BIKESOCCUPIED = @"{
|
||||
""authcookie"" : ""6103_f782a208d9399291ba8d086b5dcc2509_12345678"",
|
||||
""debuglevel"" : ""2"",
|
||||
""user_group"" : [ ""TINK"" ],
|
||||
""user_id"" : ""javaminister@gmail.com"",
|
||||
""response"" : ""user_bikes_occupied"",
|
||||
""response_state"" : ""OK"",
|
||||
""response_text"" : ""Die Liste der reservierten und gebuchten Fahrräder wurde erfolgreich geladen"",
|
||||
""apiserver"" : ""https://tinkwwp.copri-bike.de"",
|
||||
""bikes_occupied"" : {
|
||||
""89004"" : {
|
||||
""start_time"" : ""2018-01-27 17:33:00.989464+01"",
|
||||
""station"" : ""9"",
|
||||
""unit_price"" : ""2.00"",
|
||||
""tariff_description"": {
|
||||
""free_hours"" : ""0.5"",
|
||||
""name"" : ""TINK Tarif"",
|
||||
""max_eur_per_day"" : ""9.00""
|
||||
},
|
||||
""timeCode"" : ""2061"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""bike"" : ""4"",
|
||||
""total_price"" : ""20.00"",
|
||||
""state"" : ""requested"",
|
||||
""real_hours"" : ""66.05"",
|
||||
""bike_group"" : [ ""TINK"" ],
|
||||
""now_time"" : ""2018-01-30 11:36:45"",
|
||||
""request_time"" : ""2018-01-27 17:33:00.989464+01"",
|
||||
""computed_hours"" : ""10.0""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
private const string STATIONSALL = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""stations"" : {
|
||||
""5"" : {
|
||||
""station"" : ""5"",
|
||||
""bike_soll"" : ""0"",
|
||||
""bike_ist"" : ""7"",
|
||||
""station_group"" : [ ""TINK"" ],
|
||||
""gps"" : { ""latitude"": ""47.66756"", ""longitude"": ""9.16477"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : """"
|
||||
},
|
||||
""13"" : {
|
||||
""station"" : ""13"",
|
||||
""bike_soll"" : ""4"",
|
||||
""bike_ist"" : ""1"",
|
||||
""station_group"" : [ ""TINK"" ],
|
||||
""gps"" : { ""latitude"": ""47.657756"", ""longitude"": ""9.176084"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : """"
|
||||
},
|
||||
""30"" : {
|
||||
""station"" : ""30"",
|
||||
""bike_soll"" : ""5"",
|
||||
""bike_ist"" : ""0"",
|
||||
""station_group"" : [ ""TINK"", ""Konrad"" ],
|
||||
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : ""Test für Stadtradstation""
|
||||
}
|
||||
},
|
||||
""user_group"" : [ ""Konrad"", ""TINK"" ],
|
||||
""response_state"" : ""OK"",
|
||||
""authcookie"" : ""6103_f782a208d9399291ba8d086b5dcc2509_12345678"",
|
||||
""debuglevel"" : ""2"",
|
||||
""response"" : ""stations_all"",
|
||||
""user_id"" : ""javaminister@gmail.com"",
|
||||
""apiserver"" : ""https://tinkwwp.copri-bike.de""
|
||||
}";
|
||||
|
||||
private const string STATIONSALLEMPTY = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""stations"" : {
|
||||
},
|
||||
""user_group"" : [ ""Konrad"", ""TINK"" ],
|
||||
""response_state"" : ""OK"",
|
||||
""authcookie"" : ""6103_f782a208d9399291ba8d086b5dcc2509_12345678"",
|
||||
""debuglevel"" : ""2"",
|
||||
""response"" : ""stations_all"",
|
||||
""user_id"" : ""javaminister@gmail.com"",
|
||||
""apiserver"" : ""https://tinkwwp.copri-bike.de""
|
||||
}";
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_StationsFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALL),
|
||||
new GeneralData(),
|
||||
new System.Exception("Bang when getting stations..."))));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED),
|
||||
new GeneralData())));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(2, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang when getting stations...", result.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_BikesAvailableFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALLEMPTY),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new GeneralData(),
|
||||
new System.Exception("Bang when getting bikes..."))));
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<StationsAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALL),
|
||||
new GeneralData())));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(2, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang when getting bikes...", result.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_BikesOccupiedFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALLEMPTY),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLEEMPTY),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED),
|
||||
new GeneralData(),
|
||||
new System.Exception("Bang when getting bikes occupied..."))));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<StationsAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALL),
|
||||
new GeneralData())));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(2, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang when getting bikes occupied...", result.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALL),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.AddToCache(Arg<Result<StationsAvailableResponse>>.Is.Anything));
|
||||
server.Stub(x => x.AddToCache(Arg<Result<BikesAvailableResponse>>.Is.Anything));
|
||||
server.Stub(x => x.AddToCache(Arg<Result<BikesReservedOccupiedResponse>>.Is.Anything));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(2, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikes_BikesAvailableFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable()).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new GeneralData(),
|
||||
new System.Exception("Bang, bikes avail..."))));
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED),
|
||||
new GeneralData())));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAsync();
|
||||
|
||||
Assert.AreEqual(2, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang, bikes avail...", result.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikes_BikesOccupiedFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLEEMPTY),
|
||||
new GeneralData())));
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED),
|
||||
new GeneralData(),
|
||||
new System.Exception("Bang, error bikes occupied"))));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new GeneralData())));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAsync();
|
||||
|
||||
Assert.AreEqual(2, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang, error bikes occupied", result.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikes()
|
||||
{
|
||||
var server = Substitute.For<ICachedCopriServer>();
|
||||
|
||||
server.GetBikesAvailable().Returns(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new GeneralData())));
|
||||
|
||||
server.GetBikesOccupied().Returns(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED),
|
||||
new GeneralData())));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAsync();
|
||||
|
||||
Assert.AreEqual(2, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied()
|
||||
{
|
||||
var server = Substitute.For<ICachedCopriServer>();
|
||||
|
||||
server.GetBikesAvailable().Returns(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>("{}"),
|
||||
new GeneralData())));
|
||||
|
||||
server.GetBikesOccupied().Returns(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED),
|
||||
new GeneralData())));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesOccupiedAsync();
|
||||
|
||||
Assert.AreEqual(1, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Query
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestQuery
|
||||
{
|
||||
private const string BIKESAVAILABLE = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""bikes"" : {},
|
||||
""response_state"" : ""OK"",
|
||||
""apiserver"" : ""https://app.tink-konstanz.de"",
|
||||
""authcookie"" : """",
|
||||
""response"" : ""bikes_available"",
|
||||
""bikes"" : {
|
||||
""2352"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
||||
""station"" : ""9""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
private const string STATIONSALL = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""stations"" : {
|
||||
""5"" : {
|
||||
""station"" : ""5"",
|
||||
""bike_soll"" : ""0"",
|
||||
""bike_ist"" : ""7"",
|
||||
""station_group"" : [ ""TINK"" ],
|
||||
""gps"" : { ""latitude"": ""47.66756"", ""longitude"": ""9.16477"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : """"
|
||||
},
|
||||
""13"" : {
|
||||
""station"" : ""13"",
|
||||
""bike_soll"" : ""4"",
|
||||
""bike_ist"" : ""1"",
|
||||
""station_group"" : [ ""TINK"" ],
|
||||
""gps"" : { ""latitude"": ""47.657756"", ""longitude"": ""9.176084"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : """"
|
||||
},
|
||||
""30"" : {
|
||||
""station"" : ""30"",
|
||||
""bike_soll"" : ""5"",
|
||||
""bike_ist"" : ""0"",
|
||||
""station_group"" : [ ""TINK"", ""Konrad"" ],
|
||||
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : ""Test für Stadtradstation""
|
||||
}
|
||||
},
|
||||
""user_group"" : [ ""Konrad"", ""TINK"" ],
|
||||
""response_state"" : ""OK"",
|
||||
""authcookie"" : ""6103_f782a208d9399291ba8d086b5dcc2509_12345678"",
|
||||
""debuglevel"" : ""2"",
|
||||
""response"" : ""stations_all"",
|
||||
""user_id"" : ""javaminister@gmail.com"",
|
||||
""apiserver"" : ""https://tinkwwp.copri-bike.de""
|
||||
}";
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStationsAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALL)));
|
||||
server.Stub(x => x.GetBikesAvailableAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
|
||||
var result = await new TINK.Model.Connector.Query(server).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(1, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikes()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICopriServer>();
|
||||
|
||||
server.Stub(x => x.GetBikesAvailableAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
|
||||
var result = await new TINK.Model.Connector.Query(server).GetBikesAsync();
|
||||
|
||||
Assert.AreEqual(1, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICopriServer>();
|
||||
|
||||
var result = await new TINK.Model.Connector.Query(server).GetBikesOccupiedAsync();
|
||||
|
||||
Assert.AreEqual(0, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual(result.Exception.Message, "Abfrage der reservierten/ gebuchten Räder fehlgeschlagen. Kein Benutzer angemeldet.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,156 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestQueryLoggedIn
|
||||
{
|
||||
private const string BIKESAVAILABLE = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""bikes"" : {},
|
||||
""response_state"" : ""OK"",
|
||||
""apiserver"" : ""https://app.tink-konstanz.de"",
|
||||
""authcookie"" : """",
|
||||
""response"" : ""bikes_available"",
|
||||
""bikes"" : {
|
||||
""2352"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
||||
""station"" : ""9""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
private const string BIKESOCCUPIED = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""authcookie"" : ""6103_f782a208d9399291ba8d086b5dcc2509_12345678"",
|
||||
""debuglevel"" : ""2"",
|
||||
""user_group"" : [ ""TINK"" ],
|
||||
""user_id"" : ""javaminister@gmail.com"",
|
||||
""response"" : ""user_bikes_occupied"",
|
||||
""response_state"" : ""OK"",
|
||||
""response_text"" : ""Die Liste der reservierten und gebuchten Fahrräder wurde erfolgreich geladen"",
|
||||
""apiserver"" : ""https://tinkwwp.copri-bike.de"",
|
||||
""bikes_occupied"" : {
|
||||
""89004"" : {
|
||||
""start_time"" : ""2018-01-27 17:33:00.989464+01"",
|
||||
""station"" : ""9"",
|
||||
""unit_price"" : ""2.00"",
|
||||
""tariff_description"": {
|
||||
""free_hours"" : ""0.5"",
|
||||
""name"" : ""TINK Tarif"",
|
||||
""max_eur_per_day"" : ""9.00""
|
||||
},
|
||||
""timeCode"" : ""2061"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""bike"" : ""4"",
|
||||
""total_price"" : ""20.00"",
|
||||
""state"" : ""requested"",
|
||||
""real_hours"" : ""66.05"",
|
||||
""bike_group"" : [ ""TINK"" ],
|
||||
""now_time"" : ""2018-01-30 11:36:45"",
|
||||
""request_time"" : ""2018-01-27 17:33:00.989464+01"",
|
||||
""computed_hours"" : ""10.0""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
private const string STATIONSALL = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""stations"" : {
|
||||
""5"" : {
|
||||
""station"" : ""5"",
|
||||
""bike_soll"" : ""0"",
|
||||
""bike_ist"" : ""7"",
|
||||
""station_group"" : [ ""TINK"" ],
|
||||
""gps"" : { ""latitude"": ""47.66756"", ""longitude"": ""9.16477"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : """"
|
||||
},
|
||||
""13"" : {
|
||||
""station"" : ""13"",
|
||||
""bike_soll"" : ""4"",
|
||||
""bike_ist"" : ""1"",
|
||||
""station_group"" : [ ""TINK"" ],
|
||||
""gps"" : { ""latitude"": ""47.657756"", ""longitude"": ""9.176084"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : """"
|
||||
},
|
||||
""30"" : {
|
||||
""station"" : ""30"",
|
||||
""bike_soll"" : ""5"",
|
||||
""bike_ist"" : ""0"",
|
||||
""station_group"" : [ ""TINK"", ""Konrad"" ],
|
||||
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : ""Test für Stadtradstation""
|
||||
}
|
||||
},
|
||||
""user_group"" : [ ""Konrad"", ""TINK"" ],
|
||||
""response_state"" : ""OK"",
|
||||
""authcookie"" : ""6103_f782a208d9399291ba8d086b5dcc2509_12345678"",
|
||||
""debuglevel"" : ""2"",
|
||||
""response"" : ""stations_all"",
|
||||
""user_id"" : ""javaminister@gmail.com"",
|
||||
""apiserver"" : ""https://tinkwwp.copri-bike.de""
|
||||
}";
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStationsAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALL)));
|
||||
server.Stub(x => x.GetBikesAvailableAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
server.Stub(x => x.GetBikesOccupiedAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
|
||||
var result = await new QueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(2, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikes()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICopriServer>();
|
||||
|
||||
server.Stub(x => x.GetBikesAvailableAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
server.Stub(x => x.GetBikesOccupiedAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
|
||||
var result = await new QueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAsync();
|
||||
|
||||
Assert.AreEqual(2, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied()
|
||||
{
|
||||
var server = Substitute.For<ICopriServer>();
|
||||
|
||||
server.GetBikesAvailableAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>("{}")));
|
||||
|
||||
server.GetBikesOccupiedAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
|
||||
var result = await new QueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesOccupiedAsync();
|
||||
|
||||
Assert.AreEqual(1, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCommandLoggedIn
|
||||
{
|
||||
/// <summary> Verifies, that logout leads to expected call on copri server. </summary>
|
||||
[Test]
|
||||
public void TestDoLogout()
|
||||
{
|
||||
var l_oServer = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
l_oServer.Stub(x => x.DoAuthoutAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<AuthorizationoutResponse>("{ \"response_state\" : \"OK\", \"authcookie\" : \"1\"}")));
|
||||
|
||||
var l_oCmd = new CommandLoggedIn(l_oServer, "MeinKeks", "EMehl", () => DateTime.Now);
|
||||
|
||||
LoginStateChangedEventArgs l_oEventArgs = null;
|
||||
l_oCmd.LoginStateChanged += (sender, eventargs) => l_oEventArgs = eventargs;
|
||||
|
||||
l_oCmd.DoLogout().Wait();
|
||||
|
||||
l_oServer.AssertWasCalled(x => x.DoAuthoutAsync());
|
||||
Assert.IsNotNull(l_oEventArgs);
|
||||
}
|
||||
|
||||
/// <summary> Verifies, that logout leads to expected call on copri server. </summary>
|
||||
[Test]
|
||||
public void TestDoLogout_AuthcookieNotDefined()
|
||||
{
|
||||
var l_oServer = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
l_oServer.Stub(x => x.DoAuthoutAsync()).Throw(new AuthcookieNotDefinedException("Testing action", JsonConvert.DeserializeObject<ResponseBase>(@"{ ""response_state"" : ""Some inner error description""}")));
|
||||
|
||||
var l_oCmd = new CommandLoggedIn(l_oServer, "MeinKeks", "EMehl", () => DateTime.Now);
|
||||
|
||||
LoginStateChangedEventArgs l_oEventArgs = null;
|
||||
l_oCmd.LoginStateChanged += (sender, eventargs) => l_oEventArgs = eventargs;
|
||||
|
||||
l_oCmd.DoLogout().Wait();
|
||||
|
||||
l_oServer.AssertWasCalled(x => x.DoAuthoutAsync());
|
||||
Assert.IsNotNull(l_oEventArgs);
|
||||
}
|
||||
|
||||
/// <summary> Verifies, that logout leads to expected call on copri server. </summary>
|
||||
[Test]
|
||||
public void TestDoLogout_Exception()
|
||||
{
|
||||
var l_oServer = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
l_oServer.Stub(x => x.DoAuthoutAsync()).Throw(new System.Exception("Sometheing went wrong."));
|
||||
|
||||
var l_oCmd = new CommandLoggedIn(l_oServer, "MeinKeks", "EMehl", () => DateTime.Now);
|
||||
|
||||
LoginStateChangedEventArgs l_oEventArgs = null;
|
||||
l_oCmd.LoginStateChanged += (sender, eventargs) => l_oEventArgs = eventargs;
|
||||
|
||||
Assert.Throws<AggregateException>(() => l_oCmd.DoLogout().Wait());
|
||||
|
||||
l_oServer.AssertWasCalled(x => x.DoAuthoutAsync());
|
||||
Assert.IsNull(l_oEventArgs);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Repository;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestConnector
|
||||
{
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCommandFactory()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICachedCopriServer>();
|
||||
|
||||
// Construct not logged in version of connector.
|
||||
var l_oCommand = new TINK.Model.Connector.Connector(
|
||||
new System.Uri("http://1.2.3.4"),
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
"", // Not logged in
|
||||
"",
|
||||
server: l_oCopri).Command;
|
||||
|
||||
Assert.AreEqual(typeof(Command), l_oCommand.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCommandFactory_LoggedIn()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICachedCopriServer>();
|
||||
|
||||
var l_oCommand = new TINK.Model.Connector.Connector(
|
||||
new System.Uri("http://1.2.3.4"),
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
"123", // Logged in
|
||||
"a@b",
|
||||
server: l_oCopri).Command;
|
||||
|
||||
Assert.AreEqual(typeof(CommandLoggedIn), l_oCommand.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestQueryFactory_CachedServer()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICachedCopriServer>();
|
||||
|
||||
var l_oQuery = new TINK.Model.Connector.Connector(
|
||||
new Uri("http://1.2.3.4"),
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
"",
|
||||
"",
|
||||
server: l_oCopri).Query;
|
||||
|
||||
Assert.AreEqual(typeof(CachedQuery), l_oQuery.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestQueryFactory_LoggedIn()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICachedCopriServer>();
|
||||
|
||||
var l_oQuery = new TINK.Model.Connector.Connector(
|
||||
new System.Uri("http://1.2.3.4"),
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
"123",
|
||||
"a@b",
|
||||
server: l_oCopri).Query;
|
||||
|
||||
Assert.AreEqual(typeof(CachedQueryLoggedIn), l_oQuery.GetType());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Repository;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestConnectorCache
|
||||
{
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCommandFactory()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
// Construct not logged in version of connector.
|
||||
var l_oCommand = new ConnectorCache(
|
||||
new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)),
|
||||
null /*UI language */,
|
||||
"", // Not logged in
|
||||
"",
|
||||
server: l_oCopri).Command;
|
||||
|
||||
Assert.AreEqual(typeof(Command), l_oCommand.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCommandFactory_LoggedIn()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
var l_oCommand = new ConnectorCache(
|
||||
new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)),
|
||||
null /*UI language */,
|
||||
"123", // Logged in
|
||||
"a@b",
|
||||
server: l_oCopri).Command;
|
||||
|
||||
Assert.AreEqual(typeof(CommandLoggedIn), l_oCommand.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestQueryFactory_CachedServer()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
var l_oQuery = new ConnectorCache(
|
||||
new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)),
|
||||
null /*UI language */,
|
||||
"",
|
||||
"",
|
||||
server: l_oCopri).Query;
|
||||
|
||||
Assert.AreEqual(typeof(TINK.Model.Connector.Query), l_oQuery.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestQueryFactory_LoggedIn()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
var l_oQuery = new ConnectorCache(
|
||||
new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)),
|
||||
null /*UI language */,
|
||||
"123",
|
||||
"a@b",
|
||||
server: l_oCopri).Query;
|
||||
|
||||
Assert.AreEqual(typeof(QueryLoggedIn), l_oQuery.GetType());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,163 +0,0 @@
|
|||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Request
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCopriCallsStatic
|
||||
{
|
||||
[Test]
|
||||
public void TestDeserializeObjectBikesAvailableValidResponse()
|
||||
{
|
||||
const string VALID_RESPONSE = @"
|
||||
{
|
||||
""shareejson"": {
|
||||
|
||||
""authcookie"": 0,
|
||||
""apiserver"": ""https://tinkwwp.copri-bike.de"",
|
||||
""response"": ""bikes_available"",
|
||||
""bikes"": {
|
||||
""3399"": {
|
||||
""description"": ""Cargo Trike"",
|
||||
""bike"": ""26"",
|
||||
""state"": ""available"",
|
||||
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" },
|
||||
""station"" : ""4""
|
||||
|
||||
},
|
||||
},
|
||||
""response_state"": ""OK"",
|
||||
""copri_version"" : ""4.1.0.0""
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
// Ensure that answer holds a valid bike.
|
||||
var l_oBike = CopriCallsStatic.DeserializeResponse<BikesAvailableResponse>(VALID_RESPONSE).bikes.FirstOrDefault().Value;
|
||||
Assert.NotNull(l_oBike, "Response must contain at leas one bike.");
|
||||
Assert.Greater(l_oBike.description.Length, 0, "Bike despcription must never be empty.");
|
||||
Assert.AreEqual(l_oBike.bike, "26");
|
||||
Assert.That(
|
||||
l_oBike.station,
|
||||
Is.EqualTo("4"),
|
||||
"Station index must never be negative");
|
||||
Assert.AreEqual("available", l_oBike.state);
|
||||
Assert.That(l_oBike.gps, Is.Not.Null, "Gps position must never be empty.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeserializeObjectBikesAvailableValidResponse_NoDescription()
|
||||
{
|
||||
const string INVALID_RESPONSE = @"
|
||||
{
|
||||
""shareejson"": {
|
||||
|
||||
""authcookie"": 0,
|
||||
""apiserver"": ""https://tinkwwp.copri-bike.de"",
|
||||
""response"": ""bikes_available"",
|
||||
""bikes"": {
|
||||
""3399"": {
|
||||
""bike"": 26,
|
||||
""state"": ""available"",
|
||||
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" },
|
||||
""station"" : 4
|
||||
|
||||
},
|
||||
},
|
||||
""response_state"": ""OK"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
// Ensure that answer holds a valid bike.
|
||||
var l_oBike = CopriCallsStatic.DeserializeResponse<BikesAvailableResponse>(INVALID_RESPONSE).bikes.FirstOrDefault().Value;
|
||||
Assert.NotNull(l_oBike, "Response must contain at leas one bike.");
|
||||
Assert.IsNull(l_oBike.description);
|
||||
Assert.That(l_oBike.bike, Is.Not.Null);
|
||||
Assert.That(l_oBike.station, Is.Not.Null);
|
||||
Assert.AreEqual("available", l_oBike.state);
|
||||
Assert.That(l_oBike.gps, Is.Not.Null, "Gps position must never be empty.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeserializeObjectBikesAvailableValidResponse_NoBikeId()
|
||||
{
|
||||
const string VALID_RESPONSE = @"
|
||||
{
|
||||
""shareejson"": {
|
||||
|
||||
""authcookie"": 0,
|
||||
""apiserver"": ""https://tinkwwp.copri-bike.de"",
|
||||
""response"": ""bikes_available"",
|
||||
""bikes"": {
|
||||
""3399"": {
|
||||
""description"": ""Cargo Trike"",
|
||||
""state"": ""available"",
|
||||
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" },
|
||||
""station"" : ""4""
|
||||
},
|
||||
},
|
||||
""response_state"": ""OK"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
}
|
||||
}";
|
||||
|
||||
// Ensure that answer holds a valid bike.
|
||||
var l_oBike = CopriCallsStatic.DeserializeResponse<BikesAvailableResponse>(VALID_RESPONSE).bikes.FirstOrDefault().Value;
|
||||
Assert.NotNull(l_oBike, "Response must contain at leas one bike.");
|
||||
Assert.Greater(l_oBike.description.Length, 0, "Bike despcription must never be empty.");
|
||||
Assert.That(l_oBike.bike, Is.Null);
|
||||
Assert.That(l_oBike.station, Is.Not.Null);
|
||||
Assert.AreEqual("available", l_oBike.state);
|
||||
Assert.That(l_oBike.gps, Is.Not.Null, "Gps position must never be empty.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeserializeObjectBikesOccupiedValidResponse()
|
||||
{
|
||||
const string VALID_RESPONSE = @"
|
||||
{
|
||||
""shareejson"": {
|
||||
""response_state"": ""OK"",
|
||||
""bikes_occupied"": {
|
||||
""87781"": {
|
||||
""timeCode"": ""3630"",
|
||||
""state"": ""occupied"",
|
||||
""station"" : ""5"",
|
||||
""description"": ""Cargo Long"",
|
||||
""start_time"": ""2017-11-28 11:01:51.637747+01"",
|
||||
""bike"": ""8""
|
||||
},
|
||||
""87782"": {
|
||||
""timeCode"": ""2931"",
|
||||
""state"": ""occupied"",
|
||||
""station"" : ""4"",
|
||||
""description"": ""Cargo Long"",
|
||||
""start_time"": ""2017-11-28 13:06:55.147368+01"",
|
||||
""bike"": ""7""
|
||||
}
|
||||
},
|
||||
""authcookie"": ""b76b97e43a2d76b8499f32e6dd597af8"",
|
||||
""response"": ""user_bikes_occupied"",
|
||||
""apiserver"": ""https://tinkwwp.copri-bike.de"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
}
|
||||
}";
|
||||
|
||||
// Ensure that answer holds a valid bike.
|
||||
var l_oBike = CopriCallsStatic.DeserializeResponse<BikesReservedOccupiedResponse>(VALID_RESPONSE).bikes_occupied.FirstOrDefault().Value;
|
||||
Assert.NotNull(l_oBike, "Response must contain at leas one bike.");
|
||||
Assert.Greater(l_oBike.description.Length, 0, "Bike despcription must never be empty.");
|
||||
Assert.That(l_oBike.bike, Is.Not.Null);
|
||||
Assert.That(l_oBike.station, Is.Not.Null);
|
||||
Assert.Greater(l_oBike.state.Length, 0, "State info must never be null or empty.");
|
||||
// Todo: Requested bikes do not have a gps position. What is about booked bikes?
|
||||
// Assert.Greater(l_oBike.gps.Length, 0, "Gps position must never be empty.");
|
||||
Assert.Greater(l_oBike.start_time.Length, 0, "Time when request/ booking was performed must never be null or empty.");
|
||||
Assert.Greater(l_oBike.timeCode.Length, 0, "Booking code must never be null or empty.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using Plugin.BLE.Abstractions.Contracts;
|
||||
using TINK.Services.BluetoothLock.BLE;
|
||||
using TINK.Services.BluetoothLock.Exception;
|
||||
using TINK.Services.BluetoothLock.Tdo;
|
||||
using DeviceState = Plugin.BLE.Abstractions.DeviceState;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Services.BluetoothLock
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestLockItBaseService
|
||||
{
|
||||
[Test]
|
||||
public void TestConnect_Connected_InvalidArgs()
|
||||
{
|
||||
var device = Rhino.Mocks.MockRepository.GenerateStub<IDevice>();
|
||||
var adapter = Rhino.Mocks.MockRepository.GenerateStub<IAdapter>();
|
||||
var cipher = Rhino.Mocks.MockRepository.GenerateStub<TINK.Model.Device.ICipher>();
|
||||
|
||||
Rhino.Mocks.RhinoMocksExtensions.Stub(device, x => x.State).Return(DeviceState.Disconnected);
|
||||
|
||||
var exception = Assert.Throws<AggregateException>(
|
||||
() => { var lockIt = LockItEventBased.Authenticate(device, null, adapter, cipher).Result; },
|
||||
"If connected no auth is requied.");
|
||||
|
||||
Assert.That(exception.InnerExceptions.Count > 0);
|
||||
Assert.That(exception.InnerExceptions[0], Is.InstanceOf<BluetoothDisconnectedException>());
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConnect_Connected()
|
||||
{
|
||||
var device = Substitute.For<IDevice>();
|
||||
var adapter = Substitute.For<IAdapter>();
|
||||
var cipher = Substitute.For<TINK.Model.Device.ICipher>();
|
||||
var auth = Substitute.For<ICharacteristic>();
|
||||
var lockControl = Substitute.For<IService>();
|
||||
|
||||
var authTdo = new LockInfoAuthTdo.Builder
|
||||
{
|
||||
Id = 12,
|
||||
K_seed = new byte[] { (byte)'i', (byte)'V', (byte)'F', (byte)'m', (byte)'u', (byte)'T', (byte)'n', (byte)'K', (byte)'q', (byte)'E', (byte)'Y', (byte)'h', (byte)'m', (byte)'T', (byte)'l', (byte)'e' },
|
||||
K_u = new byte[16]
|
||||
}.Build();
|
||||
|
||||
device.State.Returns(DeviceState.Connected);
|
||||
device.GetServiceAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(Task.FromResult(lockControl));
|
||||
lockControl.GetCharacteristicAsync(Arg.Any<Guid>()).Returns(Task.FromResult(auth));
|
||||
auth.WriteAsync(Arg.Any<byte[]>()).Returns(Task.FromResult(true)); // Write COPRI seed to lock
|
||||
auth.ReadAsync(Arg.Any<CancellationToken>()).Returns(Task.FromResult(new byte[8])); // Read lock seed
|
||||
cipher.Decrypt(Arg.Any<byte[]>(), Arg.Any<byte[]>()).Returns(new byte[3]);
|
||||
cipher.Encrypt(Arg.Any<byte[]>(), Arg.Any<byte[]>()).Returns(new byte[16]);
|
||||
auth.WriteAsync(Arg.Any<byte[]>()).Returns(Task.FromResult(true)); // Write COPRI seed to lock
|
||||
|
||||
device.Name.Returns("Origin");
|
||||
|
||||
Assert.AreEqual(
|
||||
"Origin",
|
||||
LockItEventBased.Authenticate(device, authTdo, adapter, cipher).Result.Name,
|
||||
"If connected no auth is requied.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAuth()
|
||||
{
|
||||
var authTdo = new LockInfoAuthTdo.Builder
|
||||
{
|
||||
Id = 12,
|
||||
K_seed = new byte[] { (byte)'c', (byte)'b', (byte)'z', (byte)'b', (byte)'y', (byte)'I', (byte)'q', (byte)'j', (byte)'v', (byte)'L', (byte)'V', (byte)'I', (byte)'t', (byte)'C', (byte)'B', (byte)'I' },
|
||||
K_u = new byte[16]
|
||||
}.Build();
|
||||
|
||||
var device = Rhino.Mocks.MockRepository.GenerateStub<IDevice>();
|
||||
var adapter = Rhino.Mocks.MockRepository.GenerateStub<IAdapter>();
|
||||
var cipher = Rhino.Mocks.MockRepository.GenerateStub<TINK.Model.Device.ICipher>();
|
||||
|
||||
Rhino.Mocks.RhinoMocksExtensions.Stub(device, x => x.State).Return(DeviceState.Disconnected);
|
||||
|
||||
// Use factory to create LockIt-object.
|
||||
var exception = Assert.Throws<AggregateException>(
|
||||
() => { var lockIt = LockItEventBased.Authenticate(device, authTdo, adapter, cipher).Result; },
|
||||
"If connected no auth is requied.");
|
||||
|
||||
Assert.That(exception.InnerExceptions.Count > 0);
|
||||
Assert.That(exception.InnerExceptions[0], Is.InstanceOf<BluetoothDisconnectedException>());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using TINK.Services;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestServicesContainerMutable
|
||||
{
|
||||
[Test]
|
||||
public void TestCtor()
|
||||
{
|
||||
var container = new ServicesContainerMutableT<object>(new List<object> { new A(), new B() }, typeof(B).FullName);
|
||||
Assert.That(container.Active.GetType().FullName, Is.EqualTo("TestTINKLib.Fixtures.ObjectTests.Services.TestServicesContainerMutable+B"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCtorExceptionDupes()
|
||||
{
|
||||
Assert.That(() => new ServicesContainerMutableT<object>(new List<object> { new A(), new B(), new A() }, typeof(B).FullName), Throws.InstanceOf<Exception>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCtorExceptionActiveNotFound()
|
||||
{
|
||||
Assert.That(() => new ServicesContainerMutableT<object>(new List<object> { new A(), new B() }, "C"), Throws.InstanceOf<ArgumentException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSetActive()
|
||||
{
|
||||
var container = new ServicesContainerMutableT<object>(new List<object> { new A(), new B() }, typeof(B).FullName);
|
||||
container.SetActive(typeof(A).FullName);
|
||||
Assert.That(container.Active.GetType().FullName, Is.EqualTo("TestTINKLib.Fixtures.ObjectTests.Services.TestServicesContainerMutable+A"));
|
||||
}
|
||||
|
||||
|
||||
private class A
|
||||
{ }
|
||||
|
||||
private class B
|
||||
{ }
|
||||
}
|
||||
}
|
|
@ -1,188 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using TINK.Model.State;
|
||||
|
||||
|
||||
namespace TestTINKLib
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestStateInfo
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var l_oInUseState = new StateInfoMutable(() => new DateTime(2017, 09, 20, 23, 20, 0));
|
||||
|
||||
// Verify initial values of properties.
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oInUseState.Value, "Default state is available");
|
||||
Assert.AreEqual("Disposable", l_oInUseState.ToString());
|
||||
Assert.IsNull(l_oInUseState.RemainingTime);
|
||||
Assert.IsNull(l_oInUseState.From);
|
||||
Assert.IsNull(l_oInUseState.Code);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstructCopy()
|
||||
{
|
||||
// State is available.
|
||||
var l_oSource = MockRepository.GenerateStub<IStateInfo>();
|
||||
l_oSource.Stub(x => x.Value).Return(InUseStateEnum.Disposable);
|
||||
|
||||
var l_oState = new StateInfoMutable(state: l_oSource);
|
||||
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oState.Value);
|
||||
Assert.IsNull(l_oState.RemainingTime);
|
||||
Assert.IsNull(l_oState.From);
|
||||
Assert.IsNull(l_oState.Code);
|
||||
|
||||
// State is requested.
|
||||
l_oSource = MockRepository.GenerateStub<IStateInfo>();
|
||||
l_oSource.Stub(x => x.Value).Return(InUseStateEnum.Reserved);
|
||||
l_oSource.Stub(x => x.From).Return(new DateTime(2018, 1, 4, 17, 26, 0));
|
||||
l_oSource.Stub(x => x.MailAddress).Return("who@the");
|
||||
l_oSource.Stub(x => x.Code).Return("323");
|
||||
|
||||
l_oState = new StateInfoMutable(() => new DateTime(2018, 1, 4, 17, 30, 1), l_oSource);
|
||||
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oState.Value);
|
||||
Assert.AreEqual(new TimeSpan(0, 10, 59), l_oState.RemainingTime);
|
||||
Assert.AreEqual(new DateTime(2018, 1, 4, 17, 26, 0), l_oState.From);
|
||||
Assert.AreEqual("who@the", l_oState.MailAddress);
|
||||
Assert.AreEqual("323", l_oState.Code);
|
||||
|
||||
// State is booked.
|
||||
l_oSource = MockRepository.GenerateStub<IStateInfo>();
|
||||
l_oSource.Stub(x => x.Value).Return(InUseStateEnum.Booked);
|
||||
l_oSource.Stub(x => x.From).Return(new DateTime(2018, 1, 4, 17, 00, 0));
|
||||
l_oSource.Stub(x => x.MailAddress).Return("who@the");
|
||||
l_oSource.Stub(x => x.Code).Return("323");
|
||||
|
||||
l_oState = new StateInfoMutable(() => new DateTime(2018, 1, 4, 17, 30, 1), l_oSource);
|
||||
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oState.Value);
|
||||
Assert.IsNull(l_oState.RemainingTime);
|
||||
Assert.AreEqual(new DateTime(2018, 1, 4, 17, 00, 0), l_oState.From);
|
||||
Assert.AreEqual("who@the", l_oState.MailAddress);
|
||||
Assert.AreEqual("323", l_oState.Code);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoUpdate()
|
||||
{
|
||||
var l_oReservedAt = new DateTime(2017, 09, 20, 22, 01, 00);
|
||||
var l_oDateTimeMock = new DateTimeMocker(new List<DateTime> {
|
||||
l_oReservedAt, // Booking time
|
||||
l_oReservedAt.Add(new TimeSpan(0, 4, 0)), // Reserved for 4 mns
|
||||
l_oReservedAt.Add(new TimeSpan(0, 16, 0)) // Time elapsed since booking 16 mns
|
||||
});
|
||||
|
||||
var l_oStateInfo = new StateInfoMutable(l_oDateTimeMock.GetDateTime);
|
||||
|
||||
// Update state from Copri.
|
||||
l_oStateInfo.Load(
|
||||
InUseStateEnum.Reserved, // Copri acknowledges state reserved.
|
||||
l_oDateTimeMock.GetDateTime(),
|
||||
"heiz@mustermann"); // Owner from Copri.
|
||||
|
||||
// Invoke first update (after simulated 4mns)
|
||||
l_oStateInfo.UpdateOnTimeElapsed();
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oStateInfo.Value);
|
||||
Assert.AreEqual(11, l_oStateInfo.RemainingTime.Value.Minutes);
|
||||
Assert.AreEqual(new DateTime(2017, 09, 20, 22, 01, 00), l_oStateInfo.From.Value);
|
||||
Assert.AreEqual("heiz@mustermann", l_oStateInfo.MailAddress);
|
||||
Assert.IsNull(l_oStateInfo.Code);
|
||||
|
||||
// Invoke second update (after simulated 16 mns)
|
||||
l_oStateInfo.UpdateOnTimeElapsed();
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oStateInfo.Value);
|
||||
Assert.IsNull(l_oStateInfo.RemainingTime);
|
||||
Assert.IsNull(l_oStateInfo.From);
|
||||
Assert.IsNull(l_oStateInfo.MailAddress);
|
||||
Assert.IsNull(l_oStateInfo.Code);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUpdateFromWebserver()
|
||||
{
|
||||
Func<DateTime> l_oNowMock = () => new DateTime(2017, 09, 21, 23, 40, 0);
|
||||
var l_oStateInfo = new StateInfoMutable(l_oNowMock);
|
||||
|
||||
l_oStateInfo.Load(InUseStateEnum.Booked, new DateTime(2017, 09, 21, 23, 30, 0), "heiz@mustermann", "21");
|
||||
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oStateInfo.Value);
|
||||
Assert.AreEqual("Booked", l_oStateInfo.ToString());
|
||||
Assert.IsNull(l_oStateInfo.RemainingTime);
|
||||
Assert.AreEqual(new DateTime(2017, 09, 21, 23, 30, 0), l_oStateInfo.From.Value);
|
||||
Assert.AreEqual("heiz@mustermann", l_oStateInfo.MailAddress);
|
||||
Assert.AreEqual("21", l_oStateInfo.Code);
|
||||
|
||||
DateTime FROM = new DateTime(2017, 09, 21, 23, 35, 0);
|
||||
l_oStateInfo.Load(InUseStateEnum.Reserved, FROM, "heiz@mustermann", "22");
|
||||
|
||||
// Verify initial values of properties.
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oStateInfo.Value);
|
||||
Assert.AreEqual("Reserved", l_oStateInfo.ToString());
|
||||
Assert.AreEqual(new TimeSpan(0, 15, 0).Subtract(l_oNowMock().Subtract(FROM)).Minutes, l_oStateInfo.RemainingTime.Value.Minutes);
|
||||
Assert.AreEqual(FROM, l_oStateInfo.From);
|
||||
Assert.AreEqual("heiz@mustermann", l_oStateInfo.MailAddress);
|
||||
Assert.AreEqual("22", l_oStateInfo.Code);
|
||||
|
||||
l_oStateInfo.Load(InUseStateEnum.Disposable, new DateTime(1970, 1, 1, 0, 0, 0), "heiz@mustermann", "unused");
|
||||
|
||||
// Verify initial values of properties.
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oStateInfo.Value);
|
||||
Assert.AreEqual("Disposable", l_oStateInfo.ToString());
|
||||
Assert.IsNull(l_oStateInfo.RemainingTime);
|
||||
Assert.IsNull(l_oStateInfo.From);
|
||||
Assert.IsNull(l_oStateInfo.MailAddress);
|
||||
Assert.IsNull(l_oStateInfo.Code);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLoad()
|
||||
{
|
||||
var l_oState = new StateInfoMutable(
|
||||
() => new DateTime(2018, 01, 03, 21, 14, 0)); // Now
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oState.Value);
|
||||
Assert.IsNull(l_oState.From);
|
||||
Assert.IsNull(l_oState.RemainingTime);
|
||||
Assert.IsNull(l_oState.MailAddress);
|
||||
Assert.IsNull(l_oState.Code);
|
||||
|
||||
// Construct requested state object.
|
||||
var l_oSource = new StateInfo(
|
||||
() => new DateTime(2018, 01, 03, 21, 53, 0),
|
||||
new DateTime(2018, 01, 03, 21, 13, 0), // Requested from
|
||||
"a@b",
|
||||
"123");
|
||||
l_oState.Load(l_oSource);
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oState.Value);
|
||||
Assert.AreEqual(new DateTime(2018, 01, 03, 21, 13, 0), l_oState.From);
|
||||
Assert.AreEqual(14, l_oState.RemainingTime.Value.Minutes);
|
||||
Assert.AreEqual("a@b", l_oState.MailAddress);
|
||||
Assert.AreEqual("123", l_oState.Code);
|
||||
|
||||
|
||||
// Construct booked state object.
|
||||
l_oSource = new StateInfo(new DateTime(2018, 01, 03, 21, 37, 0), "a@b", "123");
|
||||
l_oState.Load(l_oSource);
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oState.Value);
|
||||
Assert.AreEqual(new DateTime(2018, 01, 03, 21, 37, 0), l_oState.From);
|
||||
Assert.IsNull(l_oState.RemainingTime);
|
||||
Assert.AreEqual("a@b", l_oState.MailAddress);
|
||||
Assert.AreEqual("123", l_oState.Code);
|
||||
|
||||
// Construct disposable object
|
||||
l_oSource = new StateInfo();
|
||||
l_oState.Load(l_oSource);
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oState.Value);
|
||||
Assert.IsNull(l_oState.From);
|
||||
Assert.IsNull(l_oState.RemainingTime);
|
||||
Assert.IsNull(l_oState.MailAddress);
|
||||
Assert.IsNull(l_oState.Code);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.State;
|
||||
|
||||
|
||||
namespace TestTINKLib
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestStateRequestedInfo
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct_FromApp()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
InUseStateEnum.Reserved,
|
||||
new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), "a@b", null).Value);
|
||||
|
||||
Assert.AreEqual(
|
||||
"a@b",
|
||||
new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), "a@b", null).MailAddress);
|
||||
|
||||
Assert.IsNull(
|
||||
new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), "a@b", null).Code);
|
||||
|
||||
Assert.AreEqual(
|
||||
new DateTime(2017, 09, 20, 12, 0, 0),
|
||||
new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), "a@b", null).From);
|
||||
|
||||
Assert.IsTrue(
|
||||
new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 1, 0), new DateTime(2017, 09, 20, 12, 0, 0), "a@b", null).GetIsStillReserved(out TimeSpan? l_oRemainigTime));
|
||||
|
||||
Assert.AreEqual(
|
||||
14,
|
||||
l_oRemainigTime.Value.Minutes);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_FromWebserver()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
InUseStateEnum.Reserved,
|
||||
new StateRequestedInfo(() => new DateTime(2017, 09, 20), new DateTime(2017, 09, 19), "a@b", "372").Value);
|
||||
|
||||
Assert.AreEqual(
|
||||
"a@b",
|
||||
new StateRequestedInfo(() => new DateTime(2017, 09, 20), new DateTime(2017, 09, 19), "a@b", "372").MailAddress);
|
||||
|
||||
Assert.AreEqual(
|
||||
"372",
|
||||
new StateRequestedInfo(() => new DateTime(2017, 09, 20), new DateTime(2017, 09, 19), "a@b", "372").Code);
|
||||
|
||||
Assert.AreEqual(
|
||||
new DateTime(2017, 09, 19),
|
||||
new StateRequestedInfo(() => new DateTime(2017, 09, 20), new DateTime(2017, 09, 19), "a@b", "372").From);
|
||||
|
||||
Assert.IsTrue(
|
||||
new StateRequestedInfo(() => new DateTime(2017, 09, 20, 12, 12, 0), new DateTime(2017, 09, 20, 12, 0, 0), "a@b", "372").GetIsStillReserved(out TimeSpan? l_oRemainigTime));
|
||||
|
||||
Assert.AreEqual(
|
||||
3,
|
||||
l_oRemainigTime.Value.Minutes);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTryUpdateOnTimeElapsed()
|
||||
{
|
||||
var l_oReservedAt = new DateTime(2017, 09, 20, 22, 01, 00);
|
||||
var l_oDateTimeMock = new DateTimeMocker(new List<DateTime> {
|
||||
l_oReservedAt.Add(new TimeSpan(0, 4, 0)), // Reserved for 4 mns
|
||||
l_oReservedAt.Add(new TimeSpan(0, 16, 0)) // Time elapsed since booking 16 mns
|
||||
});
|
||||
|
||||
var l_oReservedInfo = new StateRequestedInfo(l_oDateTimeMock.GetDateTime, l_oReservedAt, "a@b", null);
|
||||
Assert.AreEqual("a@b", l_oReservedInfo.MailAddress);
|
||||
Assert.AreEqual(new DateTime(2017, 09, 20, 22, 01, 00), l_oReservedInfo.From, "a@b");
|
||||
|
||||
// Invoke first update (after simulated 4mns)
|
||||
Assert.IsTrue(l_oReservedInfo.GetIsStillReserved(out TimeSpan? l_oRemainigTime));
|
||||
Assert.AreEqual(11, l_oRemainigTime.Value.Minutes);
|
||||
Assert.AreEqual(new DateTime(2017, 09, 20, 22, 01, 00), l_oReservedInfo.From, "a@b");
|
||||
|
||||
// Invoke second update (after simulated 16 mns)
|
||||
Assert.IsFalse(l_oReservedInfo.GetIsStillReserved(out l_oRemainigTime));
|
||||
Assert.IsNull(l_oRemainigTime);
|
||||
Assert.AreEqual(new DateTime(2017, 09, 20, 22, 01, 00), l_oReservedInfo.From, "a@b");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using TINK.Model.Connector;
|
||||
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> { $"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.AreEqual(3, l_oResult.ToList().Count);
|
||||
Assert.AreEqual($"HOM_{FilterHelper.CARGOBIKE}", l_oResult.ToList()[0]);
|
||||
Assert.AreEqual($"HOM_{FilterHelper.CITYBIKE}", l_oResult.ToList()[1]);
|
||||
Assert.AreEqual("HOM_117025", 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> { $"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.AreEqual(2, l_oResult.ToList().Count);
|
||||
Assert.AreEqual($"HOM_{FilterHelper.CARGOBIKE}", l_oResult.ToList()[0]);
|
||||
Assert.AreEqual("HOM_117025", l_oResult.ToList()[1]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,266 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using Plugin.BLE.Abstractions.Contracts;
|
||||
using Rhino.Mocks;
|
||||
using TestFramework.Model.Device;
|
||||
using TestFramework.Model.Services.Geolocation;
|
||||
using TestFramework.Model.User.Account;
|
||||
using TestFramework.Repository;
|
||||
using TestFramework.Services.BluetoothLock;
|
||||
using TestFramework.Services.CopriApi.Connector;
|
||||
using TINK.Model;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Model.Settings;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Services;
|
||||
using TINK.Services.Geolocation;
|
||||
using TINK.Services.Permissions;
|
||||
using TINK.View;
|
||||
using TINK.ViewModel.Account;
|
||||
using TINK.ViewModel.Map;
|
||||
using TINK.ViewModel.Settings;
|
||||
using static TINK.Repository.CopriCallsMemory;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Account
|
||||
{
|
||||
public class TestAccountPageViewModel
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct_NotLoggedIn()
|
||||
{
|
||||
const string MERCH_ID = "MyMerchId";
|
||||
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: typeof(LocksServiceMock).FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory(MERCH_ID, SampleSets.Set2, 1, sessionCookie)),
|
||||
merchantId: MERCH_ID,
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var viewService = MockRepository.GenerateStub<IViewService>();
|
||||
|
||||
var settingsPageViewModel = new AccountPageViewModel(
|
||||
tinkApp,
|
||||
(uri) => { },
|
||||
viewService);
|
||||
|
||||
|
||||
Assert.AreEqual("No user logged in.", settingsPageViewModel.LoggedInInfo);
|
||||
Assert.IsFalse(settingsPageViewModel.IsBookingStateInfoVisible, "No user logged in.");
|
||||
Assert.AreEqual(string.Empty, settingsPageViewModel.BookingStateInfo);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct()
|
||||
{
|
||||
const string MERCH_ID = "MyMerchId";
|
||||
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: typeof(LocksServiceMock).FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "UnknownCookie", new List<string> { "TINK" })),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory(MERCH_ID, SampleSets.Set2, 1, sessionCookie)),
|
||||
merchantId: MERCH_ID,
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var viewService = MockRepository.GenerateStub<IViewService>();
|
||||
|
||||
var settingsPageViewModel = new AccountPageViewModel(
|
||||
tinkApp,
|
||||
(uri) => { },
|
||||
viewService);
|
||||
|
||||
await settingsPageViewModel.OnAppearing();
|
||||
|
||||
Assert.AreEqual("Logged in as a@b.", settingsPageViewModel.LoggedInInfo);
|
||||
Assert.IsFalse(settingsPageViewModel.IsBookingStateInfoVisible, "A user is logged but no bikes requested/ booked.");
|
||||
Assert.AreEqual(string.Empty, settingsPageViewModel.BookingStateInfo);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_TwoBikes()
|
||||
{
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: typeof(LocksServiceMock).FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "6103_112e96b36ba33de245943c5ffaf369cd_", new List<string> { "TINK" })),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory001(sessionCookie)),
|
||||
merchantId: "MyMerchId",
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var viewService = MockRepository.GenerateStub<IViewService>();
|
||||
var settingsPageViewModel = new AccountPageViewModel(
|
||||
tinkApp,
|
||||
(uri) => { },
|
||||
viewService);
|
||||
|
||||
await settingsPageViewModel.OnAppearing();
|
||||
|
||||
Assert.AreEqual("Logged in as a@b.", settingsPageViewModel.LoggedInInfo);
|
||||
Assert.IsTrue(settingsPageViewModel.IsBookingStateInfoVisible, "A user is logged but no bikes requested/ booked.");
|
||||
Assert.AreEqual("Aktuell 2 Fahrräder reserviert/ gebucht.", settingsPageViewModel.BookingStateInfo);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_TwoBikes_Offline()
|
||||
{
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: typeof(LocksServiceMock).FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "6103_112e96b36ba33de245943c5ffaf369cd_", new List<string> { "TINK" })),
|
||||
isConnectedFunc: () => false,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory001(sessionCookie)),
|
||||
merchantId: "MyMerchId",
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null, // Offline
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var viewService = MockRepository.GenerateStub<IViewService>();
|
||||
var settingsPageViewModel = new AccountPageViewModel(
|
||||
tinkApp,
|
||||
(uri) => { },
|
||||
viewService);
|
||||
|
||||
await settingsPageViewModel.OnAppearing();
|
||||
|
||||
Assert.AreEqual("Logged in as a@b.", settingsPageViewModel.LoggedInInfo);
|
||||
Assert.IsTrue(settingsPageViewModel.IsBookingStateInfoVisible, "A user is logged but no bikes requested/ booked.");
|
||||
Assert.AreEqual("Aktuell 2 Fahrräder reserviert/ gebucht. Verbindungsstatus: Offline.", settingsPageViewModel.BookingStateInfo);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_TwoBikes_WebConnectCommunicationError()
|
||||
{
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: typeof(LocksServiceMock).FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "6103_112e96b36ba33de245943c5ffaf369cd_", new List<string> { "TINK" })),
|
||||
isConnectedFunc: () => false,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new TINK.Model.Connector.Connector(
|
||||
uri,
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
sessionCookie,
|
||||
mail,
|
||||
server: new CopriProviderHttps(
|
||||
uri,
|
||||
TinkApp.MerchantId,
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
sessionCookie: sessionCookie,
|
||||
cacheServer: new CopriCallsCacheMemory001(sessionCookie: sessionCookie),
|
||||
httpsServer: new ExceptionServer((msg) => new WebConnectFailureException(msg, new Exception("Source expection."))))),
|
||||
merchantId: "MyMerchId",
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null, // Offline
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var viewService = MockRepository.GenerateStub<IViewService>();
|
||||
var settingsPageViewModel = new AccountPageViewModel(
|
||||
tinkApp,
|
||||
(uri) => { },
|
||||
viewService);
|
||||
|
||||
await settingsPageViewModel.OnAppearing();
|
||||
|
||||
Assert.AreEqual("Logged in as a@b.", settingsPageViewModel.LoggedInInfo); // CopriCallsCacheMemory(SampleSets.Set2,
|
||||
Assert.IsTrue(settingsPageViewModel.IsBookingStateInfoVisible, "A user is logged but no bikes requested/ booked.");
|
||||
Assert.AreEqual("Aktuell 2 Fahrräder reserviert/ gebucht. Verbindungsstatus: Offline.", settingsPageViewModel.BookingStateInfo);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,161 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model;
|
||||
using TINK.ViewModel.Map;
|
||||
namespace UITest.Fixtures.ObjectTests.ViewModel.Map
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestMapPageViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Verifies that if Konrad is turned off in settings map page filter does no more contain Konrad option.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestGetFilterDictinaryMapPage_NoKonrad_TinkOnKonradOff()
|
||||
{
|
||||
var l_oDict = GroupFilterMapPageHelper.CreateUpdated(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }), // Last map page filter (Konrad was still available but off)
|
||||
new List<string> { "TINK" }); // Filters from settings page.
|
||||
|
||||
Assert.AreEqual(1, l_oDict.Count);
|
||||
Assert.IsTrue(l_oDict.ContainsKey("TINK"));
|
||||
Assert.AreEqual(FilterState.On, l_oDict["TINK"]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that if Konrad is turned off in settings map page filter does no more contain Konrad option.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestGetFilterDictinaryMapPage_NoKonrad_TinkOffKonradOn()
|
||||
{
|
||||
var l_oDict = GroupFilterMapPageHelper.CreateUpdated(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.Off }, { "Konrad", FilterState.On } }), // Last map page filter (Konrad was still available but off)
|
||||
new List<string> { "TINK" }); // Filters from settings page.
|
||||
|
||||
Assert.AreEqual(1, l_oDict.Count);
|
||||
Assert.IsTrue(l_oDict.ContainsKey("TINK"));
|
||||
Assert.AreEqual(FilterState.On, l_oDict["TINK"]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that if TINK.* is turned off in settings map page filter does no more contain TINK option.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestGetFilterDictinaryMapPage_NoTink_TinkOnKonradOff()
|
||||
{
|
||||
var l_oDict = GroupFilterMapPageHelper.CreateUpdated(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }), // Last map page filter (Konrad was still available but off)
|
||||
new List<string> { "Konrad" }); // Filters from settings page.
|
||||
|
||||
Assert.AreEqual(1, l_oDict.Count);
|
||||
Assert.IsTrue(l_oDict.ContainsKey("Konrad"));
|
||||
Assert.AreEqual(FilterState.On, l_oDict["Konrad"]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that if Konrad is turned on in settings map page filter is updated with entry Konrad.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestGetFilterDictinaryMapPage_TinkOn()
|
||||
{
|
||||
var l_oDict = GroupFilterMapPageHelper.CreateUpdated(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On } }), // Last map page filter (Konrad was still available but off)
|
||||
new List<string> { "TINK", "Konrad" }); // Filters from settings page.
|
||||
|
||||
Assert.AreEqual(2, l_oDict.Count);
|
||||
Assert.IsTrue(l_oDict.ContainsKey("TINK"));
|
||||
Assert.AreEqual(FilterState.Off, l_oDict["TINK"]);
|
||||
Assert.IsTrue(l_oDict.ContainsKey("Konrad"));
|
||||
Assert.AreEqual(FilterState.On, l_oDict["Konrad"]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that if Konrad is turned on in settings map page filter is updated with entry Konrad.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestGetFilterDictinaryMapPage_TinkOff()
|
||||
{
|
||||
var l_oDict = GroupFilterMapPageHelper.CreateUpdated(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.Off } }), // Last map page filter (Konrad was still available but off)
|
||||
new List<string> { "TINK", "Konrad" }); // Filters from settings page.
|
||||
|
||||
Assert.AreEqual(2, l_oDict.Count);
|
||||
Assert.IsTrue(l_oDict.ContainsKey("TINK"));
|
||||
Assert.AreEqual(FilterState.Off, l_oDict["TINK"]);
|
||||
Assert.IsTrue(l_oDict.ContainsKey("Konrad"));
|
||||
Assert.AreEqual(FilterState.On, l_oDict["Konrad"]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that map page filters are not touched if state is consitend.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestGetFilterDictinaryMapPage_AllOn_KonradActivated()
|
||||
{
|
||||
var l_oDict = GroupFilterMapPageHelper.CreateUpdated(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.Off }, { "Konrad", FilterState.On } }), // Last map page filter (Konrad was still available but off)
|
||||
new List<string> { "TINK", "Konrad" }); // Filters from settings page.
|
||||
|
||||
Assert.AreEqual(2, l_oDict.Count);
|
||||
Assert.IsTrue(l_oDict.ContainsKey("TINK"));
|
||||
Assert.AreEqual(FilterState.Off, l_oDict["TINK"]);
|
||||
Assert.IsTrue(l_oDict.ContainsKey("Konrad"));
|
||||
Assert.AreEqual(FilterState.On, l_oDict["Konrad"]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that map page filters are not touched if state is consitend..
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestGetFilterDictinaryMapPage_AllOn_TinkActivated()
|
||||
{
|
||||
var l_oDict = GroupFilterMapPageHelper.CreateUpdated(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }), // Last map page filter (Konrad was still available but off)
|
||||
new List<string> { "TINK", "Konrad" }); // Filters from settings page.
|
||||
|
||||
Assert.AreEqual(2, l_oDict.Count);
|
||||
Assert.IsTrue(l_oDict.ContainsKey("TINK"));
|
||||
Assert.AreEqual(FilterState.On, l_oDict["TINK"]);
|
||||
Assert.IsTrue(l_oDict.ContainsKey("Konrad"));
|
||||
Assert.AreEqual(FilterState.Off, l_oDict["Konrad"]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that map page filters are not touched if state is consitend.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestGetFilterDictinaryMapPage_NullFilter()
|
||||
{
|
||||
var l_oDict = GroupFilterMapPageHelper.CreateUpdated(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }), // Last map page filter (Konrad was still available but off)
|
||||
null);
|
||||
|
||||
Assert.AreEqual(2, l_oDict.Count, "Do not apply any filter if filter value null is detected.");
|
||||
Assert.IsTrue(l_oDict.ContainsKey("TINK"));
|
||||
Assert.AreEqual(FilterState.On, l_oDict["TINK"]);
|
||||
Assert.IsTrue(l_oDict.ContainsKey("Konrad"));
|
||||
Assert.AreEqual(FilterState.Off, l_oDict["Konrad"]);
|
||||
|
||||
l_oDict = GroupFilterMapPageHelper.CreateUpdated(
|
||||
null,
|
||||
null);
|
||||
|
||||
Assert.IsNull(l_oDict, "Do not apply any filter if filter value null is detected.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoToggle()
|
||||
{
|
||||
var l_oFilter = new TinkKonradToggleViewModel(new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }));
|
||||
|
||||
l_oFilter = new TinkKonradToggleViewModel(l_oFilter.FilterDictionary).DoToggle();
|
||||
|
||||
Assert.AreEqual("Konrad", l_oFilter.CurrentFilter);
|
||||
|
||||
l_oFilter = new TinkKonradToggleViewModel(l_oFilter.FilterDictionary).DoToggle();
|
||||
|
||||
Assert.AreEqual("TINK", l_oFilter.CurrentFilter);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,239 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using TestFramework.Model.User.Account;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
|
||||
using TINK.Model.Device;
|
||||
using TINK.Model.State;
|
||||
using TINK.Model.User;
|
||||
using TINK.Model.User.Account;
|
||||
using TINK.ViewModel;
|
||||
using TINK.ViewModel.Bikes;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace UITest.Fixtures.ViewModel
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestBikeAtStationViewModel
|
||||
{
|
||||
private class BikeInfoMutable : TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
|
||||
{
|
||||
public BikeInfoMutable(
|
||||
string id,
|
||||
LockModel lockModel,
|
||||
bool isDemo = false,
|
||||
IEnumerable<string> group = null,
|
||||
WheelType? wheelType = null,
|
||||
TypeOfBike? typeOfBike = null,
|
||||
string description = null,
|
||||
string stationId = null,
|
||||
string stationName = null,
|
||||
Uri operatorUri = null,
|
||||
Func<DateTime> dateTimeProvider = null,
|
||||
IStateInfo stateInfo = null) : base(
|
||||
new Bike(id, lockModel, wheelType, typeOfBike, description),
|
||||
new Drive(),
|
||||
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
|
||||
isDemo,
|
||||
group,
|
||||
stationId,
|
||||
stationName,
|
||||
operatorUri,
|
||||
null,
|
||||
dateTimeProvider,
|
||||
stateInfo)
|
||||
{
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Tests base class functionaltiy by using child.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestStateText_NotLoggedIn()
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable("2", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Cargo);
|
||||
|
||||
var l_oStoreMock = new StoreMock(); // Account without user name, password and cookie
|
||||
|
||||
var l_oUser = new User(
|
||||
l_oStoreMock,
|
||||
l_oStoreMock.Load().Result,
|
||||
"123456789"); // Device identifier
|
||||
|
||||
// Verify prerequisites
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBike.State.Value);
|
||||
Assert.IsFalse(l_oUser.IsLoggedIn);
|
||||
|
||||
// Verify view model.
|
||||
var l_oViewModel = new TINK.ViewModel.Bikes.Bike.BC.BikeViewModel(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null,
|
||||
l_oBike,
|
||||
l_oUser,
|
||||
new MyBikeInUseStateInfoProvider(),
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
url => { });
|
||||
|
||||
Assert.AreEqual("2", l_oViewModel.Name);
|
||||
Assert.AreEqual("", l_oViewModel.DisplayId);
|
||||
Assert.AreEqual("2", l_oViewModel.Id);
|
||||
Assert.AreEqual("Available.", l_oViewModel.StateText);
|
||||
Assert.AreEqual(Color.Default, l_oViewModel.StateColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests base class functionaltiy by using child.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestStateText_LoggedIn_Reserved()
|
||||
{
|
||||
var l_oViewModel = TestBikeViewModel.TestStateText_LoggedIn_Reserved(
|
||||
(bike, user) => new TINK.ViewModel.Bikes.Bike.BC.BikeViewModel(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null,
|
||||
bike,
|
||||
user,
|
||||
new BikeAtStationInUseStateInfoProvider(),
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
url => { }));
|
||||
|
||||
Assert.AreEqual("Still 15 min. reserved.", l_oViewModel.StateText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests base class functionaltiy by using child.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestStateText_LoggedIn_ReservedWithCopriConnect()
|
||||
{
|
||||
var l_oViewModel = TestBikeViewModel.TestStateText_LoggedIn_ReservedWithCopriConnect(
|
||||
(bike, user) => new TINK.ViewModel.Bikes.Bike.BC.BikeViewModel(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null,
|
||||
bike,
|
||||
user,
|
||||
new BikeAtStationInUseStateInfoProvider(),
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
url => { }));
|
||||
|
||||
Assert.AreEqual("Code 4asdfA, still 7 min. reserved.", l_oViewModel.StateText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests base class functionaltiy by using child.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestStateText_LoggedIn_Booked()
|
||||
{
|
||||
var l_oViewModel = TestBikeViewModel.TestStateText_LoggedIn_Booked(
|
||||
(bike, user) => new TINK.ViewModel.Bikes.Bike.BC.BikeViewModel(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null,
|
||||
bike,
|
||||
user,
|
||||
new BikeAtStationInUseStateInfoProvider(),
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
url => { }));
|
||||
|
||||
Assert.AreEqual(
|
||||
$"Code 4asdfA, rented since {new DateTime(2018, 10, 24, 21, 49, 00).ToString("dd. MMMM HH:mm")}.",
|
||||
l_oViewModel.StateText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests base class functionaltiy by using child.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestStateText_LoggedIn_ReservedBySomeoneElse()
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable("2", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Cargo, "Test description", "3");
|
||||
|
||||
l_oBike.State.Load(
|
||||
InUseStateEnum.Reserved,
|
||||
new DateTime(2017, 10, 24, 21, 49, 3),
|
||||
"ragu@gnu-systems.de",
|
||||
"4asdfA");
|
||||
|
||||
var l_oStoreMock = new StoreMock(new Account("john@long", "123456789" /* password */, false, "987654321" /* session cookie */, new List<string> { "TINK" }));
|
||||
|
||||
var l_oViewModel = new TINK.ViewModel.Bikes.Bike.BC.BikeViewModel(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null,
|
||||
l_oBike,
|
||||
new User(
|
||||
l_oStoreMock,
|
||||
l_oStoreMock.Load().Result,
|
||||
"123456789"), // Device id
|
||||
new BikeAtStationInUseStateInfoProvider(),
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
url => { });
|
||||
|
||||
Assert.AreEqual("Test description", l_oViewModel.Name);
|
||||
Assert.AreEqual("2", l_oViewModel.DisplayId);
|
||||
Assert.AreEqual("2", l_oViewModel.Id);
|
||||
Assert.AreEqual("Fahrrad bereits reserviert durch anderen Nutzer.", l_oViewModel.StateText);
|
||||
Assert.AreEqual(Color.Red, l_oViewModel.StateColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests base class functionaltiy by using child.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestStateText_LoggedIn_BookedBySomeoneElse()
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable("2", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Cargo, "Test description", "3");
|
||||
|
||||
l_oBike.State.Load(
|
||||
InUseStateEnum.Booked,
|
||||
new DateTime(2017, 10, 24, 21, 49, 3),
|
||||
"ragu@gnu-systems.de",
|
||||
"4asdfA");
|
||||
|
||||
var l_oStoreMock = new StoreMock(new Account("john@long", "123456789" /* password */, false, "987654321" /* session cookie */, new List<string> { "TINK" }));
|
||||
|
||||
var l_oViewModel = new TINK.ViewModel.Bikes.Bike.BC.BikeViewModel(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null,
|
||||
l_oBike,
|
||||
new User(
|
||||
l_oStoreMock,
|
||||
l_oStoreMock.Load().Result,
|
||||
"123456789"),
|
||||
new BikeAtStationInUseStateInfoProvider(),
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
url => { });
|
||||
|
||||
Assert.AreEqual("Test description", l_oViewModel.Name);
|
||||
Assert.AreEqual("2", l_oViewModel.DisplayId);
|
||||
Assert.AreEqual("2", l_oViewModel.Id);
|
||||
Assert.AreEqual("Fahrrad bereits gebucht durch anderen Nutzer.", l_oViewModel.StateText);
|
||||
Assert.AreEqual(Color.Red, l_oViewModel.StateColor);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using TestFramework.Model.User.Account;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using TINK.Model.State;
|
||||
using TINK.Model.User;
|
||||
using TINK.Model.User.Account;
|
||||
using TINK.Repository;
|
||||
using TINK.ViewModel.Bikes.Bike;
|
||||
using static TINK.Repository.CopriCallsMemory;
|
||||
|
||||
namespace UITest.Fixtures.ViewModel
|
||||
{
|
||||
public class TestBikeViewModel
|
||||
{
|
||||
private class BikeInfoMutable : TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
|
||||
{
|
||||
public BikeInfoMutable(
|
||||
string id,
|
||||
LockModel lockModel,
|
||||
bool pisDemo = false,
|
||||
IEnumerable<string> group = null,
|
||||
WheelType? wheelType = null,
|
||||
TypeOfBike? typeOfBike = null,
|
||||
string description = null,
|
||||
string stationId = null,
|
||||
string stationName = null,
|
||||
Uri operatorUri = null,
|
||||
Func<DateTime> dateTimeProvider = null,
|
||||
IStateInfo stateInfo = null) : base(
|
||||
new Bike(id, lockModel, wheelType, typeOfBike, description),
|
||||
new TINK.Model.Bikes.BikeInfoNS.DriveNS.Drive(),
|
||||
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
|
||||
pisDemo,
|
||||
group,
|
||||
stationId,
|
||||
stationName,
|
||||
operatorUri,
|
||||
null,
|
||||
dateTimeProvider,
|
||||
stateInfo)
|
||||
{
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Tests base class functionaltiy by using child.
|
||||
/// </summary>
|
||||
public static BikeViewModelBase TestStateText_LoggedIn_Reserved(Func<TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable, User, BikeViewModelBase> p_oFactory)
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable(
|
||||
"2",
|
||||
LockModel.ILockIt,
|
||||
false,
|
||||
new List<string> { "TINK" },
|
||||
WheelType.Trike,
|
||||
TypeOfBike.Cargo,
|
||||
"Test description",
|
||||
"3",
|
||||
"Radstation",
|
||||
null,
|
||||
() => new DateTime(1980, 1, 1)); // Now time stamp
|
||||
|
||||
// Update state from Copri.
|
||||
l_oBike.State.Load(
|
||||
InUseStateEnum.Reserved, // Copri acknowledges state reserved.
|
||||
new DateTime(1980, 1, 1), // Date when bike was booked.
|
||||
"ragu@gnu-systems.de"); // Owner from Copri.
|
||||
|
||||
var l_oStoreMock = new StoreMock(new Account("ragu@gnu-systems.de", "123456789" /* password */, false, "987654321" /* session cookie */, new List<string> { "TINK" }));
|
||||
var l_oUser = new User(
|
||||
l_oStoreMock,
|
||||
l_oStoreMock.Load().Result,
|
||||
"123456789");
|
||||
|
||||
// Verify prerequisites
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oBike.State.Value);
|
||||
Assert.IsTrue(l_oUser.IsLoggedIn);
|
||||
Assert.AreEqual(l_oBike.State.MailAddress, l_oUser.Mail);
|
||||
|
||||
// Do not update from Copri
|
||||
var l_oViewModel = p_oFactory(l_oBike, l_oUser);
|
||||
|
||||
return l_oViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests base class functionaltiy by using child.
|
||||
/// </summary>
|
||||
public static BikeViewModelBase TestStateText_LoggedIn_ReservedWithCopriConnect(Func<TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable, User, BikeViewModelBase> p_oFactory)
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable(
|
||||
"2",
|
||||
LockModel.ILockIt,
|
||||
false,
|
||||
new List<string> { "TINK" },
|
||||
WheelType.Trike,
|
||||
TypeOfBike.Cargo,
|
||||
"Test description",
|
||||
"3",
|
||||
"Radstation",
|
||||
null,
|
||||
() => (new DateTime(1980, 1, 1)).Add(new TimeSpan(0, 8, 0)));
|
||||
|
||||
// Update state from Copri.
|
||||
l_oBike.State.Load(
|
||||
InUseStateEnum.Reserved, // Copri acknowledges state reserved.
|
||||
new DateTime(1980, 1, 1),
|
||||
"ragu@gnu-systems.de", // Owner from Copri.
|
||||
"4asdfA"); // Reservation code from Copri
|
||||
|
||||
var l_oStoreMock = new StoreMock(new Account("ragu@gnu-systems.de", "123456789" /* password */, false, "987654321" /* session cookie */, new List<string> { "TINK" }));
|
||||
var l_oUser = new User(
|
||||
l_oStoreMock, // Mocks account store functionality.
|
||||
l_oStoreMock.Load().Result,
|
||||
"123456789");
|
||||
|
||||
// Verify prerequisites
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oBike.State.Value);
|
||||
Assert.IsTrue(l_oUser.IsLoggedIn);
|
||||
Assert.AreEqual(l_oBike.State.MailAddress, l_oUser.Mail);
|
||||
|
||||
var l_oViewModel = p_oFactory(l_oBike, l_oUser); // Bikes collection mock.
|
||||
|
||||
return l_oViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests base class functionaltiy by using child.
|
||||
/// </summary>
|
||||
public static BikeViewModelBase TestStateText_LoggedIn_Booked(Func<TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable, User, BikeViewModelBase> p_oFactory)
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable("2", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Cargo, "Test description", "3");
|
||||
|
||||
// Update from Copri.
|
||||
l_oBike.State.Load(
|
||||
InUseStateEnum.Booked,
|
||||
new DateTime(2017, 10, 24, 21, 49, 3),
|
||||
"ragu@gnu-systems.de",
|
||||
"4asdfA");
|
||||
|
||||
var l_oCopriServer = new CopriCallsMemory("MyMerchId", SampleSets.Set1, 1);
|
||||
|
||||
var l_oStoreMock = new StoreMock(new Account("ragu@gnu-systems.de", "123456789" /* password */, false, "987654321" /* session cookie */, new List<string> { "TINK" }));
|
||||
var l_oUser = new User(
|
||||
l_oStoreMock,
|
||||
l_oStoreMock.Load().Result,
|
||||
"123456789"); // Device id
|
||||
|
||||
// Verify prerequisites
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oBike.State.Value);
|
||||
Assert.IsTrue(l_oUser.IsLoggedIn);
|
||||
Assert.AreEqual(l_oBike.State.MailAddress, l_oUser.Mail);
|
||||
|
||||
var l_oViewModel = p_oFactory(l_oBike, l_oUser);
|
||||
|
||||
return l_oViewModel;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using TINK.Model.Device;
|
||||
using TINK.ViewModel;
|
||||
using TINK.ViewModel.Bikes;
|
||||
|
||||
namespace UITest.Fixtures.ViewModel
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestMyBikesPageViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests base class functionaltiy by using child.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestStateText_LoggedIn_Reserved()
|
||||
{
|
||||
var l_oViewModel = TestBikeViewModel.TestStateText_LoggedIn_Reserved(
|
||||
(bike, user) => new TINK.ViewModel.Bikes.Bike.BC.BikeViewModel(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null,
|
||||
bike,
|
||||
user,
|
||||
new MyBikeInUseStateInfoProvider(),
|
||||
MockRepository.GenerateStub<IBikesViewModel>(),
|
||||
url => { }));
|
||||
|
||||
|
||||
Assert.AreEqual("Location Station 3, still 15 min. reserved.", l_oViewModel.StateText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests base class functionaltiy by using child.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestStateText_LoggedIn_ReservedWithCopriConnect()
|
||||
{
|
||||
var l_oViewModel = TestBikeViewModel.TestStateText_LoggedIn_ReservedWithCopriConnect(
|
||||
(bike, user) => new TINK.ViewModel.Bikes.Bike.BC.BikeViewModel(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null,
|
||||
bike,
|
||||
user,
|
||||
new MyBikeInUseStateInfoProvider(),
|
||||
MockRepository.GenerateStub<IBikesViewModel>(),
|
||||
url => { }));
|
||||
|
||||
Assert.AreEqual("Code 4asdfA, location Station 3, still 7 min. reserved.", l_oViewModel.StateText);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Tests base class functionaltiy by using child.
|
||||
/// </summary>
|
||||
///
|
||||
[Test]
|
||||
public void TestStateText_LoggedIn_Booked()
|
||||
{
|
||||
var l_oViewModel = TestBikeViewModel.TestStateText_LoggedIn_Booked(
|
||||
(bike, user) => new TINK.ViewModel.Bikes.Bike.BC.BikeViewModel(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null,
|
||||
bike,
|
||||
user,
|
||||
new MyBikeInUseStateInfoProvider(),
|
||||
MockRepository.GenerateStub<IBikesViewModel>(),
|
||||
url => { }));
|
||||
|
||||
Assert.AreEqual(
|
||||
$"Code 4asdfA, location Station 3, rented since {new DateTime(2018, 10, 24, 21, 49, 00).ToString("dd. MMMM HH:mm")}.",
|
||||
l_oViewModel.StateText);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,853 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using NSubstitute.ExceptionExtensions;
|
||||
using NUnit.Framework;
|
||||
using Plugin.BLE.Abstractions.Contracts;
|
||||
using TestFramework.Model.Device;
|
||||
using TestFramework.Model.Services.Geolocation;
|
||||
using TestFramework.Model.User.Account;
|
||||
using TestFramework.Repository;
|
||||
using TestTINKLib.Mocks.Connector;
|
||||
using TINK.Model;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Device;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Model.Settings;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Services;
|
||||
using TINK.Services.BluetoothLock;
|
||||
using TINK.Services.BluetoothLock.Tdo;
|
||||
using TINK.Services.Geolocation;
|
||||
using TINK.Services.Permissions;
|
||||
using TINK.View;
|
||||
using TINK.ViewModel.Map;
|
||||
using TINK.ViewModel.MyBikes;
|
||||
using TINK.ViewModel.Settings;
|
||||
using Xamarin.Forms;
|
||||
using static TINK.Repository.CopriCallsMemory;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.ViewModel
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestMyBikesPageViewModel
|
||||
{
|
||||
[Test]
|
||||
public async Task TestConstruct_Droid()
|
||||
{
|
||||
var geolocation = Substitute.For<IServicesContainer<IGeolocation>>();
|
||||
var locksService = Substitute.For<ILocksService>();
|
||||
var timeOut = Substitute.For<ITimeOutProvider>();
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var permissions = Substitute.For<ILocationPermission>();
|
||||
var bluetooth = Substitute.For<IBluetoothLE>();
|
||||
|
||||
locksService.TimeOut.Returns(timeOut);
|
||||
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
||||
|
||||
// Fake location permissions to be set
|
||||
permissions.CheckStatusAsync().Returns(Task.FromResult(Status.Granted));
|
||||
geolocation.Active.IsGeolcationEnabled.Returns(true); // Fake gps to be on
|
||||
bluetooth.State.Returns(BluetoothState.On); // Fake bluetooth to be on
|
||||
|
||||
// Fake bluetooth answer for locks with id 2200545 and 2200537.
|
||||
locksService.GetLocksStateAsync(Arg.Any<IEnumerable<LockInfoAuthTdo>>(), Arg.Any<TimeSpan>()).Returns(
|
||||
new List<LockInfoTdo> {
|
||||
{ new LockInfoTdo.Builder { Id = 2200545, State = LockitLockingState.Open }.Build() },
|
||||
{ new LockInfoTdo.Builder { Id = 2200537, State = LockitLockingState.Closed }.Build() }
|
||||
}
|
||||
);
|
||||
const string MERCH_ID = "MyMerchId";
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: locksService.GetType().FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH", new List<string> { "300001", "300029" })),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory(MERCH_ID, SampleSets.ShareeFr01_Set1, 1, sessionCookie)),
|
||||
merchantId: MERCH_ID,
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: null,
|
||||
locationServicesContainer: geolocation,
|
||||
locksService: locksService, // Cipher
|
||||
device: new DeviceMock(), // Permissions,
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var myBikes = new MyBikesPageViewModel(
|
||||
tinkApp.ActiveUser,
|
||||
permissions, /* permissions */
|
||||
bluetooth, /* bluetooth */
|
||||
Device.Android,
|
||||
() => tinkApp.GetIsConnected(),
|
||||
(isConnected) => tinkApp.GetConnector(isConnected),
|
||||
geolocation.Active, // geolocation
|
||||
locksService,
|
||||
tinkApp.Stations,
|
||||
tinkApp.Polling,
|
||||
(d, obj) => d(obj),
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
url => { });
|
||||
|
||||
await myBikes.OnAppearingOrRefresh();
|
||||
|
||||
// Verify behaviour
|
||||
Received.InOrder(() =>
|
||||
{
|
||||
permissions.CheckStatusAsync();
|
||||
var glDummy = geolocation.Active.Received().IsGeolcationEnabled;
|
||||
var btDummy = bluetooth.Received().State;
|
||||
locksService.GetLocksStateAsync(Arg.Any<IEnumerable<LockInfoAuthTdo>>(), Arg.Any<TimeSpan>());
|
||||
});
|
||||
|
||||
Assert.IsEmpty(myBikes.StatusInfoText);
|
||||
|
||||
Assert.AreEqual(2, myBikes.Count);
|
||||
Assert.IsTrue(myBikes.IsIdle);
|
||||
Assert.IsTrue(myBikes.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
||||
|
||||
var bike1545 = myBikes.FirstOrDefault(x => x.Id == "1545") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
||||
var bike1537 = myBikes.FirstOrDefault(x => x.Id == "1537") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
||||
Assert.AreEqual($"Rented since {DateTime.Parse("2020-11-06 17:53:22.784681+01"):dd. MMMM HH:mm}.", bike1545.StateText);
|
||||
Assert.AreEqual($"Rented since {DateTime.Parse("2020-10-12 08:38:12.374231+02"):dd. MMMM HH:mm}.", bike1537.StateText);
|
||||
Assert.AreEqual("Close lock", bike1545.LockitButtonText);
|
||||
Assert.AreEqual("Open lock", bike1537.LockitButtonText);
|
||||
|
||||
Assert.IsFalse(myBikes.IsNoBikesOccupiedVisible);
|
||||
Assert.IsEmpty(myBikes.NoBikesOccupiedText);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_Droid_NoPermissions_OpenSettings()
|
||||
{
|
||||
var geolocation = Substitute.For<IServicesContainer<IGeolocation>>();
|
||||
var locksService = Substitute.For<ILocksService>();
|
||||
var timeOut = Substitute.For<ITimeOutProvider>();
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var permissions = Substitute.For<ILocationPermission>();
|
||||
var bluetooth = Substitute.For<IBluetoothLE>();
|
||||
|
||||
locksService.TimeOut.Returns(timeOut);
|
||||
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
||||
|
||||
// Fake location permissions not to be set
|
||||
permissions.CheckStatusAsync().Returns(Task.FromResult(Status.Denied));
|
||||
|
||||
// Fake anwser on question whether to open permissions dialog
|
||||
viewService.DisplayAlert(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>()).Returns(true);
|
||||
|
||||
locksService.GetLocksStateAsync(Arg.Any<IEnumerable<LockInfoAuthTdo>>(), Arg.Any<TimeSpan>()).Returns(
|
||||
new List<LockInfoTdo> {
|
||||
{ new LockInfoTdo.Builder { Id = 2200545, State = LockitLockingState.Open }.Build() },
|
||||
{ new LockInfoTdo.Builder { Id = 2200537, State = LockitLockingState.Closed }.Build() }
|
||||
}
|
||||
);
|
||||
const string MERCH_ID = "MyMerchId";
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: locksService.GetType().FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH", new List<string> { "300001", "300029" })),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory(MERCH_ID, SampleSets.ShareeFr01_Set1, 1, sessionCookie)),
|
||||
merchantId: MERCH_ID,
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: null,
|
||||
locationServicesContainer: geolocation,
|
||||
locksService: locksService, // Cipher
|
||||
device: new DeviceMock(), // Permissions,
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var myBikes = new MyBikesPageViewModel(
|
||||
tinkApp.ActiveUser,
|
||||
permissions, /* permissions */
|
||||
bluetooth, /* bluetooth */
|
||||
Device.Android,
|
||||
() => tinkApp.GetIsConnected(),
|
||||
(isConnected) => tinkApp.GetConnector(isConnected),
|
||||
geolocation.Active, // geolocation
|
||||
locksService,
|
||||
tinkApp.Stations,
|
||||
tinkApp.Polling,
|
||||
(d, obj) => d(obj),
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
url => { });
|
||||
|
||||
await myBikes.OnAppearingOrRefresh();
|
||||
|
||||
// Verify behaviour
|
||||
Received.InOrder(() =>
|
||||
{
|
||||
permissions.CheckStatusAsync();
|
||||
var glDummy = geolocation.Active.Received().IsGeolcationEnabled;
|
||||
permissions.RequestAsync(); // Ask user from permissions.
|
||||
viewService.DisplayAlert(
|
||||
"Hint",
|
||||
"Please allow location sharing so that bike lock/locks can be managed.\r\nOpen sharing dialog?",
|
||||
"Yes",
|
||||
"No");
|
||||
permissions.OpenAppSettings();
|
||||
});
|
||||
|
||||
Assert.IsEmpty(myBikes.StatusInfoText, "Unexpected status info text detected.");
|
||||
|
||||
Assert.AreEqual(2, myBikes.Count);
|
||||
Assert.IsTrue(myBikes.IsIdle);
|
||||
Assert.IsTrue(myBikes.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
||||
|
||||
var bike1545 = myBikes.FirstOrDefault(x => x.Id == "1545") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
||||
var bike1537 = myBikes.FirstOrDefault(x => x.Id == "1537") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
||||
Assert.AreEqual($"Rented since {DateTime.Parse("2020-11-06 17:53:22.784681+01"):dd. MMMM HH:mm}.", bike1545.StateText);
|
||||
Assert.AreEqual($"Rented since {DateTime.Parse("2020-10-12 08:38:12.374231+02"):dd. MMMM HH:mm}.", bike1537.StateText);
|
||||
Assert.AreEqual("Search lock", bike1545.LockitButtonText);
|
||||
Assert.AreEqual("Search lock", bike1537.LockitButtonText);
|
||||
|
||||
Assert.IsFalse(myBikes.IsNoBikesOccupiedVisible);
|
||||
Assert.IsEmpty(myBikes.NoBikesOccupiedText, "There must not be any bikes occupied.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_Droid_NoPermissions()
|
||||
{
|
||||
var geolocation = Substitute.For<IServicesContainer<IGeolocation>>();
|
||||
var locksService = Substitute.For<ILocksService>();
|
||||
var timeOut = Substitute.For<ITimeOutProvider>();
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var permissions = Substitute.For<ILocationPermission>();
|
||||
var bluetooth = Substitute.For<IBluetoothLE>();
|
||||
|
||||
locksService.TimeOut.Returns(timeOut);
|
||||
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
||||
|
||||
// Fake location permissions not to be set
|
||||
permissions.CheckStatusAsync().Returns(Task.FromResult(Status.Denied));
|
||||
|
||||
permissions.OpenAppSettings().Throws<Exception>(); // Ensures that method is not called and fixture succeeds.
|
||||
|
||||
// Fake anwser on question whether to open permissions dialog
|
||||
viewService.DisplayAlert(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>()).Returns(false);
|
||||
|
||||
// Fake bluetooth answer for locks with id 2200545 and 2200537.
|
||||
var lockInfoTdo = new List<LockInfoTdo> {
|
||||
{ new LockInfoTdo.Builder { Id = 2200545, State = LockitLockingState.Open }.Build() },
|
||||
{ new LockInfoTdo.Builder { Id = 2200537, State = LockitLockingState.Closed }.Build() }
|
||||
};
|
||||
|
||||
locksService.GetLocksStateAsync(Arg.Any<IEnumerable<LockInfoAuthTdo>>(), Arg.Any<TimeSpan>()).Returns(lockInfoTdo);
|
||||
const string MERCH_ID = "MyMerchId";
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: locksService.GetType().FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH", new List<string> { "300001", "300029" })),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory(MERCH_ID, SampleSets.ShareeFr01_Set1, 1, sessionCookie)),
|
||||
merchantId: MERCH_ID,
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: null,
|
||||
locationServicesContainer: geolocation,
|
||||
locksService: locksService, // Cipher
|
||||
device: new DeviceMock(), // Permissions,
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var myBikes = new MyBikesPageViewModel(
|
||||
tinkApp.ActiveUser,
|
||||
permissions, /* permissions */
|
||||
bluetooth, /* bluetooth */
|
||||
Device.Android,
|
||||
() => tinkApp.GetIsConnected(),
|
||||
(isConnected) => tinkApp.GetConnector(isConnected),
|
||||
geolocation.Active, // geolocation
|
||||
locksService,
|
||||
tinkApp.Stations,
|
||||
tinkApp.Polling,
|
||||
(d, obj) => d(obj),
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
url => { });
|
||||
|
||||
await myBikes.OnAppearingOrRefresh();
|
||||
|
||||
// Verify behaviour
|
||||
Received.InOrder(() =>
|
||||
{
|
||||
permissions.CheckStatusAsync();
|
||||
var glDummy = geolocation.Active.Received().IsGeolcationEnabled;
|
||||
permissions.RequestAsync(); // Ask user from permissions.
|
||||
viewService.DisplayAlert(
|
||||
"Hint",
|
||||
"Please allow location sharing so that bike lock/locks can be managed.\r\nOpen sharing dialog?",
|
||||
"Yes",
|
||||
"No");
|
||||
});
|
||||
|
||||
Assert.IsEmpty(myBikes.StatusInfoText, "Unexpected status info text detected.");
|
||||
|
||||
Assert.AreEqual(2, myBikes.Count);
|
||||
Assert.IsTrue(myBikes.IsIdle);
|
||||
Assert.IsTrue(myBikes.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
||||
|
||||
var bike1545 = myBikes.FirstOrDefault(x => x.Id == "1545") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
||||
var bike1537 = myBikes.FirstOrDefault(x => x.Id == "1537") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
||||
Assert.AreEqual($"Rented since {DateTime.Parse("2020-11-06 17:53:22.784681+01"):dd. MMMM HH:mm}.", bike1545.StateText);
|
||||
Assert.AreEqual($"Rented since {DateTime.Parse("2020-10-12 08:38:12.374231+02"):dd. MMMM HH:mm}.", bike1537.StateText);
|
||||
Assert.AreEqual("Search lock", bike1545.LockitButtonText);
|
||||
Assert.AreEqual("Search lock", bike1537.LockitButtonText);
|
||||
|
||||
Assert.IsFalse(myBikes.IsNoBikesOccupiedVisible);
|
||||
Assert.IsEmpty(myBikes.NoBikesOccupiedText, "There must not be any bikes occupied.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_Droid_GeolocationOff()
|
||||
{
|
||||
var geolocation = Substitute.For<IServicesContainer<IGeolocation>>();
|
||||
var locksService = Substitute.For<ILocksService>();
|
||||
var timeOut = Substitute.For<ITimeOutProvider>();
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var permissions = Substitute.For<ILocationPermission>();
|
||||
var bluetooth = Substitute.For<IBluetoothLE>();
|
||||
|
||||
locksService.TimeOut.Returns(timeOut);
|
||||
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
||||
|
||||
// Fake location permissions to be set
|
||||
permissions.CheckStatusAsync().Returns(Task.FromResult(Status.Granted));
|
||||
geolocation.Active.IsGeolcationEnabled.Returns(false); // Fake gps to be off
|
||||
|
||||
// Fake bluetooth answer for locks with id 2200545 and 2200537.
|
||||
locksService.GetLocksStateAsync(Arg.Any<IEnumerable<LockInfoAuthTdo>>(), Arg.Any<TimeSpan>()).Returns(
|
||||
new List<LockInfoTdo> {
|
||||
{ new LockInfoTdo.Builder { Id = 2200545, State = LockitLockingState.Open }.Build() },
|
||||
{ new LockInfoTdo.Builder { Id = 2200537, State = LockitLockingState.Closed }.Build() }
|
||||
}
|
||||
);
|
||||
const string MERCH_ID = "MyMerchId";
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: locksService.GetType().FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH", new List<string> { "300001", "300029" })),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory(MERCH_ID, SampleSets.ShareeFr01_Set1, 1, sessionCookie)),
|
||||
merchantId: MERCH_ID,
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: null,
|
||||
locationServicesContainer: geolocation,
|
||||
locksService: locksService, // Cipher
|
||||
device: new DeviceMock(), // Permissions,
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var myBikes = new MyBikesPageViewModel(
|
||||
tinkApp.ActiveUser,
|
||||
permissions, /* permissions */
|
||||
bluetooth, /* bluetooth */
|
||||
Device.Android,
|
||||
() => tinkApp.GetIsConnected(),
|
||||
(isConnected) => tinkApp.GetConnector(isConnected),
|
||||
geolocation.Active, // geolocation
|
||||
locksService,
|
||||
tinkApp.Stations,
|
||||
tinkApp.Polling,
|
||||
(d, obj) => d(obj),
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
url => { });
|
||||
|
||||
await myBikes.OnAppearingOrRefresh();
|
||||
|
||||
// Verify behaviour
|
||||
Received.InOrder(() =>
|
||||
{
|
||||
permissions.CheckStatusAsync();
|
||||
var glDummy = geolocation.Active.Received().IsGeolcationEnabled;
|
||||
viewService.DisplayAlert(
|
||||
"Hint",
|
||||
"Please activate location so that bike lock can be found!",
|
||||
"OK");
|
||||
});
|
||||
|
||||
Assert.IsEmpty(myBikes.StatusInfoText);
|
||||
|
||||
Assert.AreEqual(2, myBikes.Count);
|
||||
Assert.IsTrue(myBikes.IsIdle);
|
||||
Assert.IsTrue(myBikes.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
||||
|
||||
var bike1545 = myBikes.FirstOrDefault(x => x.Id == "1545") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
||||
var bike1537 = myBikes.FirstOrDefault(x => x.Id == "1537") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
||||
Assert.AreEqual($"Rented since {DateTime.Parse("2020-11-06 17:53:22.784681+01"):dd. MMMM HH:mm}.", bike1545.StateText);
|
||||
Assert.AreEqual($"Rented since {DateTime.Parse("2020-10-12 08:38:12.374231+02"):dd. MMMM HH:mm}.", bike1537.StateText);
|
||||
Assert.AreEqual("Search lock", bike1545.LockitButtonText);
|
||||
Assert.AreEqual("Search lock", bike1537.LockitButtonText);
|
||||
|
||||
Assert.IsFalse(myBikes.IsNoBikesOccupiedVisible);
|
||||
Assert.IsEmpty(myBikes.NoBikesOccupiedText);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_Droid_BluetoothOff()
|
||||
{
|
||||
var geolocation = Substitute.For<IServicesContainer<IGeolocation>>();
|
||||
var locksService = Substitute.For<ILocksService>();
|
||||
var timeOut = Substitute.For<ITimeOutProvider>();
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var permissions = Substitute.For<ILocationPermission>();
|
||||
var bluetooth = Substitute.For<IBluetoothLE>();
|
||||
|
||||
locksService.TimeOut.Returns(timeOut);
|
||||
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
||||
|
||||
// Fake location permissions to be set
|
||||
permissions.CheckStatusAsync().Returns(Task.FromResult(Status.Granted));
|
||||
geolocation.Active.IsGeolcationEnabled.Returns(true); // Fake gps to be on
|
||||
bluetooth.State.Returns(BluetoothState.Off); // Fake bluetooth to be off
|
||||
|
||||
var lockInfoTdo = new List<LockInfoTdo> {
|
||||
{ new LockInfoTdo.Builder { Id = 2200545, State = LockitLockingState.Open }.Build() },
|
||||
{ new LockInfoTdo.Builder { Id = 2200537, State = LockitLockingState.Closed }.Build() }
|
||||
};
|
||||
|
||||
locksService.GetLocksStateAsync(Arg.Any<IEnumerable<LockInfoAuthTdo>>(), Arg.Any<TimeSpan>()).Returns(lockInfoTdo);
|
||||
const string MERCH_ID = "MyMerchId";
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: locksService.GetType().FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "5781_d47fc786e740ef77d85a24bcb6f0ff97_oiF2kahH", new List<string> { "300001", "300029" })),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory(MERCH_ID, SampleSets.ShareeFr01_Set1, 1, sessionCookie)),
|
||||
merchantId: MERCH_ID,
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: null,
|
||||
locationServicesContainer: geolocation,
|
||||
locksService: locksService, // Cipher
|
||||
device: new DeviceMock(), // Permissions,
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var myBikes = new MyBikesPageViewModel(
|
||||
tinkApp.ActiveUser,
|
||||
permissions, /* permissions */
|
||||
bluetooth, /* bluetooth */
|
||||
Device.Android,
|
||||
() => tinkApp.GetIsConnected(),
|
||||
(isConnected) => tinkApp.GetConnector(isConnected),
|
||||
geolocation.Active, // geolocation
|
||||
locksService,
|
||||
tinkApp.Stations,
|
||||
tinkApp.Polling,
|
||||
(d, obj) => d(obj),
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
url => { });
|
||||
|
||||
await myBikes.OnAppearingOrRefresh();
|
||||
|
||||
// Verify behaviour
|
||||
Received.InOrder(() =>
|
||||
{
|
||||
permissions.CheckStatusAsync();
|
||||
var glDummy = geolocation.Active.Received().IsGeolcationEnabled;
|
||||
var btDummy = bluetooth.Received().State;
|
||||
viewService.DisplayAlert(
|
||||
"Hint",
|
||||
"Please enable Bluetooth to manage bike lock/locks.",
|
||||
"OK");
|
||||
});
|
||||
|
||||
Assert.That(
|
||||
myBikes.StatusInfoText,
|
||||
Is.Empty,
|
||||
"Status info text must be empty.");
|
||||
|
||||
Assert.AreEqual(2, myBikes.Count);
|
||||
Assert.IsTrue(myBikes.IsIdle);
|
||||
Assert.IsTrue(myBikes.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
||||
|
||||
var bike1545 = myBikes.FirstOrDefault(x => x.Id == "1545") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
||||
var bike1537 = myBikes.FirstOrDefault(x => x.Id == "1537") as TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel;
|
||||
Assert.AreEqual($"Rented since {DateTime.Parse("2020-11-06 17:53:22.784681+01"):dd. MMMM HH:mm}.", bike1545.StateText);
|
||||
Assert.AreEqual($"Rented since {DateTime.Parse("2020-10-12 08:38:12.374231+02"):dd. MMMM HH:mm}.", bike1537.StateText);
|
||||
Assert.AreEqual("Search lock", bike1545.LockitButtonText);
|
||||
Assert.AreEqual("Search lock", bike1537.LockitButtonText);
|
||||
|
||||
Assert.IsFalse(myBikes.IsNoBikesOccupiedVisible);
|
||||
Assert.That(
|
||||
myBikes.NoBikesOccupiedText,
|
||||
Is.Empty,
|
||||
"Label which informs that no bikes are reserved/ rented must be empty.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_NoBikesOccupied()
|
||||
{
|
||||
var locksService = Substitute.For<ILocksService>();
|
||||
var timeOut = Substitute.For<ITimeOutProvider>();
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var permissions = Substitute.For<ILocationPermission>();
|
||||
var bluetooth = Substitute.For<IBluetoothLE>();
|
||||
|
||||
locksService.TimeOut.Returns(timeOut);
|
||||
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
||||
const string MERCH_ID = "MyMerchId";
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: locksService.GetType().FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "Invalid_SessionCookie", new List<string> { "TINK" })),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory(MERCH_ID, SampleSets.Set2, 1, sessionCookie)),
|
||||
merchantId: MERCH_ID,
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: locksService, // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var myBikes = new MyBikesPageViewModel(
|
||||
tinkApp.ActiveUser,
|
||||
permissions, // Permissions,
|
||||
bluetooth,
|
||||
Device.iOS,
|
||||
() => tinkApp.GetIsConnected(),
|
||||
(isConnected) => tinkApp.GetConnector(isConnected),
|
||||
new GeolocationMock(),
|
||||
locksService,
|
||||
tinkApp.Stations,
|
||||
tinkApp.Polling,
|
||||
(d, obj) => d(obj),
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
url => { });
|
||||
|
||||
await myBikes.OnAppearingOrRefresh();
|
||||
|
||||
Assert.IsTrue(new List<string> { "Updating...", string.Empty }.Contains(myBikes.StatusInfoText));
|
||||
|
||||
Assert.AreEqual(0, myBikes.Count);
|
||||
Assert.IsTrue(myBikes.IsIdle);
|
||||
Assert.IsFalse(myBikes.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
||||
|
||||
Assert.IsTrue(myBikes.IsNoBikesOccupiedVisible);
|
||||
Assert.AreEqual("There are currently no bicycles reserved/booked on user a@b.", myBikes.NoBikesOccupiedText);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_Offline()
|
||||
{
|
||||
var locksService = Substitute.For<ILocksService>();
|
||||
var timeOut = Substitute.For<ITimeOutProvider>();
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var permissions = Substitute.For<ILocationPermission>();
|
||||
var bluetooth = Substitute.For<IBluetoothLE>();
|
||||
|
||||
locksService.TimeOut.Returns(timeOut);
|
||||
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
||||
const string MERCH_ID = "MyMerchId";
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: locksService.GetType().FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "4da3044c8657a04ba60e2eaa753bc51a", new List<string> { "TINK" })),
|
||||
isConnectedFunc: () => false,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory(MERCH_ID, SampleSets.Set2, 1, sessionCookie)),
|
||||
merchantId: MERCH_ID,
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: null,
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: locksService, // Cipher
|
||||
device: new DeviceMock(), // Permissions
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null, // Offline
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var myBikes = new MyBikesPageViewModel(
|
||||
tinkApp.ActiveUser,
|
||||
permissions, // Permissions,
|
||||
bluetooth,
|
||||
Device.iOS,
|
||||
() => tinkApp.GetIsConnected(),
|
||||
(isConnected) => tinkApp.GetConnector(isConnected),
|
||||
new GeolocationMock(),
|
||||
locksService,
|
||||
tinkApp.Stations,
|
||||
tinkApp.Polling,
|
||||
(d, obj) => d(obj),
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
url => { });
|
||||
|
||||
await myBikes.OnAppearingOrRefresh();
|
||||
|
||||
Assert.AreEqual("Offline.", myBikes.StatusInfoText);
|
||||
|
||||
Assert.AreEqual(2, myBikes.Count);
|
||||
Assert.IsTrue(myBikes.IsIdle);
|
||||
Assert.IsTrue(myBikes.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
||||
|
||||
Assert.AreEqual("Rented since 28. November 13:06.", myBikes.FirstOrDefault(x => x.Id == "7").StateText);
|
||||
Assert.AreEqual("Rented since 28. November 11:01.", myBikes.FirstOrDefault(x => x.Id == "8").StateText);
|
||||
|
||||
Assert.IsFalse(myBikes.IsNoBikesOccupiedVisible);
|
||||
Assert.AreEqual(string.Empty, myBikes.NoBikesOccupiedText);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestTinkApp_WebConnectCommunicationError()
|
||||
{
|
||||
var locksService = Substitute.For<ILocksService>();
|
||||
var timeOut = Substitute.For<ITimeOutProvider>();
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var permissions = Substitute.For<ILocationPermission>();
|
||||
var bluetooth = Substitute.For<IBluetoothLE>();
|
||||
|
||||
locksService.TimeOut.Returns(timeOut);
|
||||
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
||||
const string MERCH_ID = "MyMerchId";
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: locksService.GetType().FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "4da3044c8657a04ba60e2eaa753bc51a", new List<string> { "TINK" })),
|
||||
isConnectedFunc: () => false,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new TINK.Model.Connector.Connector(
|
||||
uri,
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
sessionCookie,
|
||||
mail,
|
||||
server: new CopriProviderHttps(
|
||||
uri,
|
||||
TinkApp.MerchantId,
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
sessionCookie: sessionCookie,
|
||||
cacheServer: new CopriCallsCacheMemory(MERCH_ID, sessionCookie: sessionCookie),
|
||||
httpsServer: new ExceptionServer((msg) => new WebConnectFailureException(msg, new Exception("Source expection."))))),
|
||||
merchantId: MERCH_ID,
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: locksService, // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null, // Offline
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var myBikes = new MyBikesPageViewModel(
|
||||
tinkApp.ActiveUser,
|
||||
permissions, // Permissions,
|
||||
bluetooth,
|
||||
Device.iOS,
|
||||
() => tinkApp.GetIsConnected(),
|
||||
(isConnected) => tinkApp.GetConnector(isConnected),
|
||||
new GeolocationMock(),
|
||||
locksService,
|
||||
tinkApp.Stations,
|
||||
tinkApp.Polling,
|
||||
(d, obj) => d(obj),
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
url => { })
|
||||
{
|
||||
IsReportLevelVerbose = true
|
||||
};
|
||||
|
||||
await myBikes.OnAppearingOrRefresh();
|
||||
|
||||
Assert.AreEqual("Connection interrupted, server unreachable.", myBikes.StatusInfoText);
|
||||
|
||||
Assert.AreEqual(2, myBikes.Count);
|
||||
Assert.IsTrue(myBikes.IsIdle);
|
||||
Assert.IsTrue(myBikes.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
||||
|
||||
Assert.AreEqual("Rented since 28. November 13:06.", myBikes.FirstOrDefault(x => x.Id == "7").StateText);
|
||||
Assert.AreEqual("Rented since 28. November 11:01.", myBikes.FirstOrDefault(x => x.Id == "8").StateText);
|
||||
|
||||
Assert.IsFalse(myBikes.IsNoBikesOccupiedVisible);
|
||||
Assert.AreEqual(string.Empty, myBikes.NoBikesOccupiedText);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestTinkApp_GeneralPurposeError()
|
||||
{
|
||||
var locksService = Substitute.For<ILocksService>();
|
||||
var timeOut = Substitute.For<ITimeOutProvider>();
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var permissions = Substitute.For<ILocationPermission>();
|
||||
var bluetooth = Substitute.For<IBluetoothLE>();
|
||||
|
||||
locksService.TimeOut.Returns(timeOut);
|
||||
timeOut.MultiConnect.Returns(new TimeSpan(0));
|
||||
const string MERCH_ID = "MyMerchId";
|
||||
var tinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: locksService.GetType().FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(new TINK.Model.User.Account.Account("a@b", "123456789", false, "4da3044c8657a04ba60e2eaa753bc51a", new List<string> { "TINK" })),
|
||||
isConnectedFunc: () => false,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new TINK.Model.Connector.Connector(
|
||||
uri,
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
sessionCookie,
|
||||
mail,
|
||||
server: new CopriProviderHttps(
|
||||
uri,
|
||||
TinkApp.MerchantId,
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
sessionCookie: sessionCookie,
|
||||
cacheServer: new CopriCallsCacheMemory(MERCH_ID, sessionCookie: sessionCookie),
|
||||
httpsServer: new ExceptionServer((msg) => new Exception(msg)))),
|
||||
merchantId: MERCH_ID,
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: null,
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: locksService, // Cipher
|
||||
device: new DeviceMock(), // Permissions.
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null, // Offline
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var myBikes = new MyBikesPageViewModel(
|
||||
tinkApp.ActiveUser,
|
||||
permissions, // Permissions,
|
||||
bluetooth,
|
||||
Device.iOS,
|
||||
() => tinkApp.GetIsConnected(),
|
||||
(isConnected) => tinkApp.GetConnector(isConnected),
|
||||
new GeolocationMock(),
|
||||
locksService,
|
||||
tinkApp.Stations,
|
||||
tinkApp.Polling,
|
||||
(d, obj) => d(obj),
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
url => { })
|
||||
{
|
||||
IsReportLevelVerbose = true
|
||||
};
|
||||
|
||||
await myBikes.OnAppearingOrRefresh();
|
||||
|
||||
Assert.AreEqual("Connection interrupted.", myBikes.StatusInfoText);
|
||||
|
||||
Assert.AreEqual(2, myBikes.Count);
|
||||
Assert.IsTrue(myBikes.IsIdle);
|
||||
Assert.IsTrue(myBikes.IsBikesListVisible, "If there are any bikes, list must be visible.");
|
||||
|
||||
Assert.AreEqual("Rented since 28. November 13:06.", myBikes.FirstOrDefault(x => x.Id == "7").StateText);
|
||||
Assert.AreEqual("Rented since 28. November 11:01.", myBikes.FirstOrDefault(x => x.Id == "8").StateText);
|
||||
|
||||
Assert.IsFalse(myBikes.IsNoBikesOccupiedVisible);
|
||||
Assert.AreEqual(string.Empty, myBikes.NoBikesOccupiedText);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,7 +35,7 @@ namespace TestTINKLib.Fixtures.UseCases.ConnectedOffline
|
|||
merchantId: MERCH_ID,
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocationService>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using Plugin.BLE.Abstractions.Contracts;
|
||||
using TestFramework.Model.Device;
|
||||
using TestFramework.Model.Services.Geolocation;
|
||||
using TestFramework.Model.User.Account;
|
||||
using TestFramework.Services.BluetoothLock;
|
||||
using TINK.Model;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Settings;
|
||||
using TINK.Repository;
|
||||
using TINK.Services;
|
||||
using TINK.Services.Geolocation;
|
||||
using TINK.Services.Permissions;
|
||||
using TINK.ViewModel.Settings;
|
||||
using static TINK.Repository.CopriCallsMemory;
|
||||
|
||||
namespace TestTINKLib.Fixtures.UseCases.SelectStation
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestTinkApp
|
||||
{
|
||||
[Test]
|
||||
public void TestBikesAtStation_AccountStoreMock_NoUser_CopriMock_Set2()
|
||||
{
|
||||
const string MERCH_ID = "MyMerchId";
|
||||
|
||||
var l_oConnector = new ConnectorCache(
|
||||
new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)),
|
||||
null /*UI language */,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
server: new CopriCallsMemory(MERCH_ID, SampleSets.Set2, 1));
|
||||
|
||||
var l_oTinkApp = new TinkApp(
|
||||
new Settings(
|
||||
new TINK.ViewModel.Map.GroupFilterMapPage(new Dictionary<string, FilterState> { { "TINK", FilterState.On } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { "TINK", FilterState.On }, { "Konrad", FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://shareeapp-primary.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: typeof(LocksServiceMock).FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo(MERCH_ID, "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory(MERCH_ID, SampleSets.Set2, 1)),
|
||||
merchantId: MERCH_ID,
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
currentVersion: new Version(3, 2, 0, 115),
|
||||
lastVersion: new Version(3, 0, 173)); // Current app version. Must be larger or equal 3.0.173 to
|
||||
|
||||
Assert.AreEqual(0, TestHelper.GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.Count);
|
||||
|
||||
l_oTinkApp.SelectedStation = new TINK.Model.Station.Station("5", new List<string>(), null);
|
||||
Assert.AreEqual(3, TestHelper.GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.Count);
|
||||
Assert.AreEqual("25", TestHelper.GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.GetById("25").Id);
|
||||
Assert.AreEqual("11", TestHelper.GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.GetById("11").Id);
|
||||
Assert.AreEqual("2", TestHelper.GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.GetById("2").Id);
|
||||
|
||||
l_oTinkApp.SelectedStation = new TINK.Model.Station.Station("10", new List<string>(), null);
|
||||
|
||||
Assert.AreEqual(
|
||||
1,
|
||||
TestHelper.GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.Count);
|
||||
|
||||
Assert.AreEqual("18", TestHelper.GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.GetById("18").Id);
|
||||
|
||||
l_oTinkApp.SelectedStation = new TINK.Model.Station.Station("91345", new List<string>(), null);
|
||||
|
||||
Assert.AreEqual(0, TestHelper.GetBikesAtStation(l_oTinkApp.ActiveUser, l_oConnector, l_oTinkApp.Stations, l_oTinkApp.SelectedStation.Id).Result.Count);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model;
|
||||
using TINK.Model.Bikes;
|
||||
using TINK.Model.Station;
|
||||
using TINK.Model.User;
|
||||
|
||||
namespace TestTINKLib.Fixtures.UseCases
|
||||
{
|
||||
public class TestHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Get all bikes at a given station from copri.
|
||||
/// </summary>
|
||||
public static async Task<BikeCollectionMutable> GetBikesAtStation(
|
||||
User user,
|
||||
TINK.Model.Connector.IConnector connector,
|
||||
IEnumerable<IStation> stations,
|
||||
string selectedStationId)
|
||||
{
|
||||
var l_oBikesAtStation = new BikeCollectionMutable();
|
||||
|
||||
var l_oBikesAvailable = (await connector.Query.GetBikesAsync()).Response;
|
||||
|
||||
l_oBikesAtStation.Update(l_oBikesAvailable.GetAtStation(selectedStationId), stations);
|
||||
|
||||
return l_oBikesAtStation;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using TINK.Model.Bikes;
|
||||
|
||||
using BikeInfoMutable = TINK.Model.Bikes.BikeInfoNS.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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Device;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Request;
|
||||
using TINK.Repository.Response;
|
||||
using static TINK.Repository.CopriCallsMemory;
|
||||
|
||||
namespace TestTINKLib.Mocks.Connector
|
||||
{
|
||||
/// <summary> Allows use of memory for retrieving defined respones.</summary>
|
||||
public class CopriCallsCacheMemory : ICopriCache
|
||||
{
|
||||
private CopriCallsMemory server;
|
||||
|
||||
public CopriCallsCacheMemory(
|
||||
string merchantId,
|
||||
SampleSets? sampleSet = null,
|
||||
int? index = null,
|
||||
string sessionCookie = null)
|
||||
{
|
||||
server = new CopriCallsMemory(merchantId, 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(StationsAvailableResponse 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<ResponseBase> StartReturningBike(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<ReservationBookingResponse> UpdateLockingStateAsync(
|
||||
string bikeId,
|
||||
lock_state state,
|
||||
Uri operatorUri,
|
||||
LocationDto geolocation,
|
||||
double batteryPercentage,
|
||||
IVersionInfo versionInfo)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<ReservationBookingResponse> DoBookAsync(Uri operatorUri, string bikeId, Guid guid, double batteryPercentage, LockingAction? nextAction = null)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<ReservationBookingResponse> BookAvailableAndStartOpeningAsync(string bikeId, Uri operatorUri)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<ReservationBookingResponse> BookReservedAndStartOpeningAsync(string bikeId, Uri operatorUri)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<DoReturnResponse> DoReturn(string bikeId, LocationDto location, Uri operatorUri)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
/// <summary> Returns a bike and starts closing. </summary>
|
||||
/// <param name="bikeId">Id of the bike to return.</param>
|
||||
/// <param name="smartDevice">Provides info about hard and software.</param>
|
||||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on returning request.</returns>
|
||||
public Task<DoReturnResponse> ReturnAndStartClosingAsync(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> throw new System.Exception("Rückgabe mit mit Schloss schließen Befehl Offlinemodus nicht möglich!");
|
||||
|
||||
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, int? currentChargeBars, string message, bool isBikeBroken, Uri operatorUri)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
/// <summary> Submits mini survey to copri server. </summary>
|
||||
/// <param name="answers">Collection of answers.</param>
|
||||
public Task<ResponseBase> DoSubmitMiniSurvey(IDictionary<string, string> answers)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public Task<BikesAvailableResponse> GetBikesAvailableAsync()
|
||||
{
|
||||
return server.GetBikesAvailableAsync();
|
||||
}
|
||||
|
||||
public Task<BikesReservedOccupiedResponse> GetBikesOccupiedAsync()
|
||||
{
|
||||
return server.GetBikesOccupiedAsync();
|
||||
}
|
||||
|
||||
public Task<StationsAvailableResponse> GetStationsAsync()
|
||||
{
|
||||
return server.GetStationsAsync();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
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];
|
||||
}
|
||||
}
|
|
@ -40,36 +40,12 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Fixtures\ObjectTests\Services\TestServicesContainerMutable.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\ViewModel\Account\TestAccountPageViewModel.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\Connector\CopriCallsHttpReference.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\Connector\Query\TestCachedQuery.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\Connector\Query\TestCachedQueryLoggedIn.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\Connector\TestConnectorCache.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\Connector\TestCopriCallsHttps.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\Connector\TestCopriCallsStatic.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\Connector\TestCommandLoggedIn.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\Connector\TestConnector.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\Connector\TestFilter.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\Connector\Query\TestQuery.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\Connector\Query\TestQueryLoggedIn.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\Services\BluetoothLock\TestLockItBaseService.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\User\Account\TestAccountExtensions.cs" />
|
||||
<None Include="Fixtures\ObjectTests\User\Account\TestStore.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\ViewModel\Map\TestMapPageFilter.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\ViewModel\TestBikeAtStationViewModel.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\ViewModel\TestBikeViewModel.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\ViewModel\TestMyBikePageViewModel.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\ViewModel\TestMyBikesPageViewModel.cs" />
|
||||
<Compile Include="Fixtures\UseCases\ConnectedOffline\TestTinkApp.cs" />
|
||||
<Compile Include="Fixtures\UseCases\TestHelper.cs" />
|
||||
<None Include="Fixtures\ObjectTests\Bike\TestBikeSerializeJSON.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\State\TestStateInfoMutable.cs" />
|
||||
<Compile Include="Fixtures\ObjectTests\State\TestStateRequestedInfo.cs" />
|
||||
<Compile Include="Fixtures\UseCases\SelectStation\TestTinkApp.cs" />
|
||||
<Compile Include="Mocks\Bike\BikeCollectionMock.cs" />
|
||||
<Compile Include="Mocks\Connector\CopriCallsCacheMemory.cs" />
|
||||
<Compile Include="Mocks\DateTimeMocker.cs" />
|
||||
<Compile Include="TestHelper.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -77,7 +53,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json">
|
||||
<Version>13.0.2</Version>
|
||||
<Version>13.0.3</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NSubstitute">
|
||||
<Version>5.0.0</Version>
|
||||
|
@ -86,16 +62,13 @@
|
|||
<Version>3.13.3</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NUnit3TestAdapter">
|
||||
<Version>4.3.1</Version>
|
||||
<Version>4.4.2</Version>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="PCLStorage">
|
||||
<Version>1.0.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="RhinoMocks">
|
||||
<Version>3.6.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Serilog.Sinks.File">
|
||||
<Version>5.0.0</Version>
|
||||
</PackageReference>
|
||||
|
@ -133,15 +106,6 @@
|
|||
<Name>TINKLib</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Fixtures\ObjectTests\Connector\Exception\" />
|
||||
<Folder Include="Fixtures\ObjectTests\Connector\Filter\" />
|
||||
<Folder Include="Fixtures\ObjectTests\Connector\Response\" />
|
||||
<Folder Include="Fixtures\ObjectTests\Connector\Updater\" />
|
||||
<Folder Include="Fixtures\ObjectTests\Services\BluetoothLock\Crypto\" />
|
||||
<Folder Include="Fixtures\ObjectTests\Services\BluetoothLock\Tdo\" />
|
||||
<Folder Include="Fixtures\ObjectTests\Settings\BluetoothLock\" />
|
||||
<Folder Include="Fixtures\UseCases\Startup\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue