mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-21 21:46:27 +02:00
Code updated to 3.0.238
This commit is contained in:
parent
3302d80678
commit
9c6a1fa92b
257 changed files with 7763 additions and 2861 deletions
|
@ -13,13 +13,13 @@ namespace TestTINKLib
|
|||
private class BikeInfoMutable : TINK.Model.Bike.BC.BikeInfoMutable
|
||||
{
|
||||
public BikeInfoMutable(
|
||||
int id,
|
||||
string id,
|
||||
bool isDemo = false,
|
||||
IEnumerable<string> group = null,
|
||||
WheelType? wheelType = null,
|
||||
TypeOfBike? typeOfBike = null,
|
||||
string description = null,
|
||||
int? currentStationId = null,
|
||||
string currentStationId = null,
|
||||
Uri operatorUri = null,
|
||||
TariffDescription tariffDescription = null,
|
||||
Func<DateTime> dateTimeProvider = null,
|
||||
|
@ -32,13 +32,13 @@ namespace TestTINKLib
|
|||
public void TestConstruct()
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable(
|
||||
42,
|
||||
"42",
|
||||
false,
|
||||
new List<string> { "TINK" },
|
||||
WheelType.Two,
|
||||
TypeOfBike.Cargo);
|
||||
|
||||
Assert.AreEqual(42, l_oBike.Id);
|
||||
Assert.AreEqual("42", l_oBike.Id);
|
||||
Assert.IsFalse(l_oBike.IsDemo);
|
||||
Assert.AreEqual(WheelType.Two, l_oBike.WheelType);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, l_oBike.TypeOfBike);
|
||||
|
@ -46,32 +46,32 @@ namespace TestTINKLib
|
|||
Assert.IsNull(l_oBike.CurrentStation);
|
||||
|
||||
l_oBike = new BikeInfoMutable(
|
||||
17,
|
||||
"17",
|
||||
true,
|
||||
new List<string> { "TINK" },
|
||||
WheelType.Mono,
|
||||
TypeOfBike.Allround,
|
||||
"Test description",
|
||||
1);
|
||||
"1");
|
||||
|
||||
Assert.AreEqual(17, l_oBike.Id);
|
||||
Assert.AreEqual("17", l_oBike.Id);
|
||||
Assert.IsTrue(l_oBike.IsDemo);
|
||||
Assert.AreEqual(WheelType.Mono, l_oBike.WheelType);
|
||||
Assert.AreEqual(TypeOfBike.Allround, l_oBike.TypeOfBike);
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBike.State.Value);
|
||||
Assert.AreEqual(1, l_oBike.CurrentStation);
|
||||
Assert.AreEqual("1", l_oBike.CurrentStation);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestToString()
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable(3, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Cargo, dateTimeProvider: () => new DateTime(1970, 1, 1));
|
||||
var l_oBike = new BikeInfoMutable("3", false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Cargo, dateTimeProvider: () => new DateTime(1970, 1, 1));
|
||||
|
||||
Assert.AreEqual(
|
||||
"Id=3, wheel(s)=Two, type=Cargo, demo=False, state=Disposable, location=On the road.",
|
||||
l_oBike.ToString());
|
||||
|
||||
l_oBike = new BikeInfoMutable(3, true, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", 5, dateTimeProvider: () => new DateTime(1970, 1, 1));
|
||||
l_oBike = new BikeInfoMutable("3", true, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "5", dateTimeProvider: () => new DateTime(1970, 1, 1));
|
||||
Assert.AreEqual(
|
||||
"Id=3, wheel(s)=Trike, type=Allround, demo=True, state=Disposable, location=Station 5.",
|
||||
l_oBike.ToString());
|
||||
|
|
|
@ -16,32 +16,32 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
|
|||
"Verify that no unspecific reference not set to... exception is thrown");
|
||||
|
||||
Assert.Throws<System.ArgumentException>(
|
||||
() => new BikeInfo(new TINK.Model.Bike.BC.BikeInfo(12,1), null),
|
||||
() => new BikeInfo(new TINK.Model.Bike.BC.BikeInfo("12", "1"), null),
|
||||
"Verify that no unspecific reference not set to... exception is thrown");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCtorAvailable()
|
||||
{
|
||||
Assert.AreEqual (12,new BikeInfo(12, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), 13).Id);
|
||||
Assert.AreEqual(13, new BikeInfo(12, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), 13).CurrentStation);
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, new BikeInfo(12, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), 13).State.Value);
|
||||
Assert.AreEqual ("12",new BikeInfo("12", 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "13").Id);
|
||||
Assert.AreEqual("13", new BikeInfo("12", 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "13").CurrentStation);
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, new BikeInfo("12", 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "13").State.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCtorRequested()
|
||||
{
|
||||
Assert.AreEqual(12, new BikeInfo(12, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", 13, null, null, dateTimeProvider: () => new DateTime(2019, 1, 1)).Id);
|
||||
Assert.AreEqual(112, new BikeInfo(12, 112, new Guid(), null, null, null, new DateTime(2020,1,1), "a@b", 13, null, null, dateTimeProvider: () => new DateTime(2019, 1, 1)).LockInfo.Id);
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, new BikeInfo(12, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", 13, null, null, dateTimeProvider: () => new DateTime(2019, 1, 1)).State.Value);
|
||||
Assert.AreEqual("12", new BikeInfo("12", 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null, null, dateTimeProvider: () => new DateTime(2019, 1, 1)).Id);
|
||||
Assert.AreEqual(112, new BikeInfo("12", 112, new Guid(), null, null, null, new DateTime(2020,1,1), "a@b", "13", null, null, dateTimeProvider: () => new DateTime(2019, 1, 1)).LockInfo.Id);
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, new BikeInfo("12", 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null, null, dateTimeProvider: () => new DateTime(2019, 1, 1)).State.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCtorBooked()
|
||||
{
|
||||
Assert.AreEqual(12, new BikeInfo(12, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", 13, null /*operator uri*/).Id);
|
||||
Assert.AreEqual(112, new BikeInfo(12, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", 13, null /*operator uri*/).LockInfo.Id);
|
||||
Assert.AreEqual(InUseStateEnum.Booked, new BikeInfo(12, 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", 13, null /*operator uri*/).State.Value);
|
||||
Assert.AreEqual("12", new BikeInfo("12", 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null /*operator uri*/).Id);
|
||||
Assert.AreEqual(112, new BikeInfo("12", 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null /*operator uri*/).LockInfo.Id);
|
||||
Assert.AreEqual(InUseStateEnum.Booked, new BikeInfo("12", 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null /*operator uri*/).State.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,14 +10,14 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
|
|||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var l_oBike = new Bike(43);
|
||||
Assert.AreEqual(43, l_oBike.Id);
|
||||
var l_oBike = new Bike("43");
|
||||
Assert.AreEqual("43", l_oBike.Id);
|
||||
Assert.AreEqual(null, l_oBike.TypeOfBike);
|
||||
Assert.AreEqual(null, l_oBike.WheelType);
|
||||
|
||||
l_oBike = new Bike(43, WheelType.Mono, TypeOfBike.Cargo);
|
||||
l_oBike = new Bike("43", WheelType.Mono, TypeOfBike.Cargo);
|
||||
|
||||
Assert.AreEqual(43, l_oBike.Id);
|
||||
Assert.AreEqual("43", l_oBike.Id);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, l_oBike.TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Mono, l_oBike.WheelType);
|
||||
}
|
||||
|
@ -25,21 +25,21 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
|
|||
[Test]
|
||||
public void TestCompare()
|
||||
{
|
||||
var l_oBike1 = new Bike(43);
|
||||
Assert.AreEqual(43, l_oBike1.Id);
|
||||
var l_oBike1 = new Bike("43");
|
||||
Assert.AreEqual("43", l_oBike1.Id);
|
||||
Assert.AreEqual(null, l_oBike1.TypeOfBike);
|
||||
Assert.AreEqual(null, l_oBike1.WheelType);
|
||||
|
||||
var l_oBike2 = new Bike(42, WheelType.Two, TypeOfBike.Allround);
|
||||
var l_oBike2 = new Bike("42", WheelType.Two, TypeOfBike.Allround);
|
||||
Assert.IsFalse(l_oBike1 == l_oBike2);
|
||||
|
||||
l_oBike2 = new Bike(43, WheelType.Mono, TypeOfBike.Allround);
|
||||
l_oBike2 = new Bike("43", WheelType.Mono, TypeOfBike.Allround);
|
||||
Assert.IsFalse(l_oBike1 == l_oBike2);
|
||||
|
||||
l_oBike2 = new Bike(43, WheelType.Two, TypeOfBike.Cargo);
|
||||
l_oBike2 = new Bike("43", WheelType.Two, TypeOfBike.Cargo);
|
||||
Assert.IsFalse(l_oBike1 == l_oBike2);
|
||||
|
||||
l_oBike2 = new Bike(43, null, null);
|
||||
l_oBike2 = new Bike("43", null, null);
|
||||
Assert.IsTrue(l_oBike1 == l_oBike2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace TestTINKLib
|
|||
var l_oColl = new BikeCollection();
|
||||
|
||||
Assert.AreEqual(0, l_oColl.Count);
|
||||
Assert.IsNull(l_oColl.GetById(1));
|
||||
Assert.IsNull(l_oColl.GetById("1"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,13 +17,13 @@ namespace TestTINKLib
|
|||
private class BikeInfoMutable : TINK.Model.Bike.BC.BikeInfoMutable
|
||||
{
|
||||
public BikeInfoMutable(
|
||||
int id,
|
||||
string id,
|
||||
bool isDemo = false,
|
||||
IEnumerable<string> group = null,
|
||||
WheelType? wheelType = null,
|
||||
TypeOfBike? typeOfBike = null,
|
||||
string description = null,
|
||||
int? currentStationId = null,
|
||||
string currentStationId = null,
|
||||
Uri operatorUri = null,
|
||||
TariffDescription tariffDescription = null,
|
||||
Func<DateTime> dateTimeProvider = null,
|
||||
|
@ -38,72 +38,72 @@ namespace TestTINKLib
|
|||
{
|
||||
var l_oColl = new BikeCollectionMutable();
|
||||
|
||||
l_oColl.Add(new BikeInfoMutable(57, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround));
|
||||
l_oColl.Add(new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround));
|
||||
|
||||
Assert.Throws<Exception>(() => l_oColl.Add(new BikeInfoMutable(57, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo)));
|
||||
Assert.Throws<Exception>(() => l_oColl.Add(new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUpdate_Null()
|
||||
{
|
||||
var l_oBikeRequested = new BikeInfoMutable(20, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround);
|
||||
var l_oBikeRequested = new BikeInfoMutable("20", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround);
|
||||
l_oBikeRequested.State.Load(new StateInfo(() => DateTime.Now, DateTime.Now, "john@long", "1234"));
|
||||
|
||||
var l_oBikeColl = new BikeCollectionMutable
|
||||
{
|
||||
new BikeInfoMutable(63, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround),
|
||||
new BikeInfoMutable(57, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
|
||||
new BikeInfoMutable("63", false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround),
|
||||
new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
|
||||
l_oBikeRequested,
|
||||
};
|
||||
|
||||
// Verify initial state
|
||||
Assert.NotNull(l_oBikeColl.GetById(63));
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeColl.GetById(57).State.Value);
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oBikeColl.GetById(20).State.Value);
|
||||
Assert.Null(l_oBikeColl.GetById(33));
|
||||
Assert.NotNull(l_oBikeColl.GetById("63"));
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeColl.GetById("57").State.Value);
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oBikeColl.GetById("20").State.Value);
|
||||
Assert.Null(l_oBikeColl.GetById("33"));
|
||||
|
||||
l_oBikeColl.Update(null);
|
||||
|
||||
// Verify modified state
|
||||
Assert.Null(l_oBikeColl.GetById(63));
|
||||
Assert.Null(l_oBikeColl.GetById(57));
|
||||
Assert.Null(l_oBikeColl.GetById(20));
|
||||
Assert.Null(l_oBikeColl.GetById(33));
|
||||
Assert.Null(l_oBikeColl.GetById("63"));
|
||||
Assert.Null(l_oBikeColl.GetById("57"));
|
||||
Assert.Null(l_oBikeColl.GetById("20"));
|
||||
Assert.Null(l_oBikeColl.GetById("33"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUpdate()
|
||||
{
|
||||
var l_oBikeRequested = new BikeInfoMutable(20, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround);
|
||||
var l_oBikeRequested = new BikeInfoMutable("20", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround);
|
||||
l_oBikeRequested.State.Load(new StateInfo(() => DateTime.Now, DateTime.Now, "john@long", "1234"));
|
||||
|
||||
var l_oBikeColl = new BikeCollectionMutable
|
||||
{
|
||||
new BikeInfoMutable(63, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround),
|
||||
new BikeInfoMutable(57, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
|
||||
new BikeInfoMutable("63", false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround),
|
||||
new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
|
||||
l_oBikeRequested,
|
||||
};
|
||||
|
||||
// Verify initial state
|
||||
Assert.NotNull(l_oBikeColl.GetById(63)); // Will be removed
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeColl.GetById(57).State.Value); // Will be requested
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oBikeColl.GetById(20).State.Value); // Will be booked
|
||||
Assert.Null(l_oBikeColl.GetById(33)); //
|
||||
Assert.NotNull(l_oBikeColl.GetById("63")); // Will be removed
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeColl.GetById("57").State.Value); // Will be requested
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oBikeColl.GetById("20").State.Value); // Will be booked
|
||||
Assert.Null(l_oBikeColl.GetById("33")); //
|
||||
|
||||
var l_oBikeResponse = new List<BikeInfo>
|
||||
{
|
||||
new BikeInfo(57, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", 7, null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
|
||||
new BikeInfo(20, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", 7, null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
|
||||
new BikeInfo(33, 7, null /*operator uri*/, null, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround),
|
||||
new BikeInfo("57", false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "7", null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
|
||||
new BikeInfo("20", false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "7", null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
|
||||
new BikeInfo("33", "7", null /*operator uri*/, null, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround),
|
||||
};
|
||||
|
||||
l_oBikeColl.Update(l_oBikeResponse);
|
||||
|
||||
// Verify modified state
|
||||
Assert.Null(l_oBikeColl.GetById(63));
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oBikeColl.GetById(57).State.Value);
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oBikeColl.GetById(20).State.Value);
|
||||
Assert.NotNull(l_oBikeColl.GetById(33));
|
||||
Assert.Null(l_oBikeColl.GetById("63"));
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oBikeColl.GetById("57").State.Value);
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oBikeColl.GetById("20").State.Value);
|
||||
Assert.NotNull(l_oBikeColl.GetById("33"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
160
TestShareeLib/Model/Connector/TestCachetimings.cs
Normal file
160
TestShareeLib/Model/Connector/TestCachetimings.cs
Normal file
|
@ -0,0 +1,160 @@
|
|||
using MonkeyCache.FileStore;
|
||||
using NUnit.Framework;
|
||||
using Serilog;
|
||||
using System;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Services.CopriApi.ServerUris;
|
||||
using UITest.Fixtures.Connector;
|
||||
|
||||
namespace TestTINKLib.Fixtures.Misc
|
||||
{
|
||||
[TestFixture]
|
||||
[Explicit("Run with care because this stress impact live system.")]
|
||||
[Category(TestCopriCallsHttps.CATEGORY_REQUIRESCOPRI)]
|
||||
public class TestCachetimings
|
||||
{
|
||||
[Test]
|
||||
#if !NOLIVESERVER
|
||||
[Explicit("Run with care because this stress impact live system.")]
|
||||
//[Category(TestCopriCallsHttps.CATEGORY_USESLIVESERVER)]
|
||||
#elif !NODEVELSERVER
|
||||
[Category(TestCopriCallsHttps.CATEGORY_USESDEVELSERVER)]
|
||||
#endif
|
||||
public void TestCachedQuery_GetStationsAll(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url,
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)] string url,
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url,
|
||||
#endif
|
||||
[Values(";", "6103_4da3044c8657a04ba60e2eaa753bc51a_;javaminister@gmail.com")] string cookieAndMail)
|
||||
{
|
||||
Barrel.ApplicationId = GetType().Name + nameof(TestCachedQuery_GetStationsAll);
|
||||
|
||||
Log .Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.ControlledBy(new Serilog.Core.LoggingLevelSwitch(Serilog.Events.LogEventLevel.Error))
|
||||
.WriteTo.Debug()
|
||||
.CreateLogger();
|
||||
|
||||
var connector = ConnectorFactory.Create(
|
||||
true, // Is connected
|
||||
new Uri(url),
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/" + nameof(TestCachedQuery_GetStationsAll),
|
||||
cookieAndMail.Split(';')[0],
|
||||
cookieAndMail.Split(';')[1],
|
||||
TimeSpan.FromSeconds(3)); // See task #97 for need of custom expiresAfter value.
|
||||
|
||||
var start = DateTime.Now;
|
||||
|
||||
var queryIndex = 1;
|
||||
while (DateTime.Now.Subtract(start).TotalSeconds < 60)
|
||||
{
|
||||
Log.ForContext<TestCachetimings>().Information($"Query #{queryIndex}");
|
||||
|
||||
var result = connector.Query.GetBikesAndStationsAsync().Result;
|
||||
Assert.IsNull(result.Exception, $"Exception message: {result.Exception?.Message}");
|
||||
|
||||
queryIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// From COPRI version v4.1 switched from TINK devel https://tinkwwp.copri-bike.de/APIjsonserver to sharee devel https://shareeapp-primary.copri-bike.de/APIjsonserver
|
||||
/// </summary>
|
||||
/// <param name="uri"></param>
|
||||
/// <param name="cookieAndMail"></param>
|
||||
[Test]
|
||||
#if !NOLIVESERVER
|
||||
[Explicit("Run with care because this stress impact live system.")]
|
||||
//[Category(TestCopriCallsHttps.CATEGORY_USESLIVESERVER)]
|
||||
#elif !NODEVELSERVER
|
||||
[Category(TestCopriCallsHttps.CATEGORY_USESDEVELSERVER)]
|
||||
#endif
|
||||
public void TestCachedQuery_GetBikes(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url,
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)] string url,
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url,
|
||||
#endif
|
||||
[Values(";", "6103_4da3044c8657a04ba60e2eaa753bc51a_;javaminister@gmail.com")] string cookieAndMail)
|
||||
{
|
||||
Barrel.ApplicationId = GetType().Name + nameof(TestCachedQuery_GetBikes);
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.ControlledBy(new Serilog.Core.LoggingLevelSwitch(Serilog.Events.LogEventLevel.Error))
|
||||
.WriteTo.Debug()
|
||||
.CreateLogger();
|
||||
|
||||
var connector = ConnectorFactory.Create(
|
||||
true, // Is connected
|
||||
new Uri(url),
|
||||
"Testsharee.bikeApp/3.0.223 AutomatedTestEnvirnoment/" + nameof(TestCachedQuery_GetBikes),
|
||||
cookieAndMail.Split(';')[0],
|
||||
cookieAndMail.Split(';')[1],
|
||||
TimeSpan.FromSeconds(3)); // See task #97 for need of custom expiresAfter value.
|
||||
|
||||
var start = DateTime.Now;
|
||||
|
||||
var queryIndex = 1;
|
||||
while (DateTime.Now.Subtract(start).TotalSeconds < 60)
|
||||
{
|
||||
Log.ForContext<TestCachetimings>().Information($"Query #{queryIndex}");
|
||||
|
||||
var result = connector.Query.GetBikesAsync().Result;
|
||||
Assert.IsNull(result.Exception, $"Exception message: {result.Exception?.Message}");
|
||||
|
||||
queryIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
#if !NOLIVESERVER
|
||||
[Explicit("Run with care because this stress impact live system.")]
|
||||
//[Category(TestCopriCallsHttps.CATEGORY_USESLIVESERVER)]
|
||||
#elif !NODEVELSERVER
|
||||
[Category(TestCopriCallsHttps.CATEGORY_USESDEVELSERVER)]
|
||||
#endif
|
||||
public void TestCachedQuery_GetBikesOccupied(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url,
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)] string url,
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url,
|
||||
#endif
|
||||
[Values("6103_4da3044c8657a04ba60e2eaa753bc51a_;javaminister@gmail.com")] string cookieAndMail)
|
||||
{
|
||||
Barrel.ApplicationId = GetType().Name + nameof(TestCachedQuery_GetBikes);
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.ControlledBy(new Serilog.Core.LoggingLevelSwitch(Serilog.Events.LogEventLevel.Verbose))
|
||||
.WriteTo.Debug()
|
||||
.WriteTo.File($"Log{nameof(TestCachedQuery_GetBikes)}.log")
|
||||
.CreateLogger();
|
||||
|
||||
var connector = ConnectorFactory.Create(
|
||||
true, // Is connected
|
||||
new Uri(url),
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/" + nameof(TestCachedQuery_GetBikes),
|
||||
cookieAndMail.Split(';')[0],
|
||||
cookieAndMail.Split(';')[1],
|
||||
TimeSpan.FromSeconds(3)); // See task #97 for need of custom expiresAfter value.
|
||||
|
||||
var start = DateTime.Now;
|
||||
|
||||
var queryIndex = 1;
|
||||
while (DateTime.Now.Subtract(start).TotalSeconds < 60)
|
||||
{
|
||||
Log.ForContext<TestCachetimings>().Information($"Query #{queryIndex}");
|
||||
|
||||
var result = connector.Query.GetBikesOccupiedAsync().Result;
|
||||
Assert.IsNull(result.Exception, $"Exception message: {result.Exception?.Message}");
|
||||
|
||||
queryIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
30
TestShareeLib/Model/Connector/TestConnectorFactory.cs
Normal file
30
TestShareeLib/Model/Connector/TestConnectorFactory.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using MonkeyCache.FileStore;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Connector;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestConnectorFactory
|
||||
{
|
||||
[Test]
|
||||
public void TestCreate()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Barrel.ApplicationId))
|
||||
{
|
||||
Barrel.ApplicationId = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
||||
}
|
||||
|
||||
var connector = ConnectorFactory.Create(false, new Uri("https://1.2.3.4"), "TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", "123456789", "a@b");
|
||||
Assert.AreEqual(typeof(ConnectorCache), connector.GetType());
|
||||
|
||||
connector = ConnectorFactory.Create(true, new Uri("https://1.2.3.4"), "TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", "123456789", "a@b");
|
||||
Assert.AreEqual(typeof(TINK.Model.Connector.Connector), connector.GetType());
|
||||
}
|
||||
}
|
||||
}
|
514
TestShareeLib/Model/Connector/TestCopriProviderHttps.cs
Normal file
514
TestShareeLib/Model/Connector/TestCopriProviderHttps.cs
Normal file
|
@ -0,0 +1,514 @@
|
|||
using MonkeyCache.FileStore;
|
||||
using Newtonsoft.Json;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCopriProviderHttps
|
||||
{
|
||||
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 = @"{
|
||||
""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 TestGetBikesAvailable_NotExpired()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer >();
|
||||
|
||||
cache.IsBikesAvailableExpired.Returns(false);
|
||||
cache.GetBikesAvailableAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123", // Merchant id
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"456", // cookie
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesAvailable();
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, bikes.Source.Name);
|
||||
Assert.IsNull(bikes.Exception);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesAvailable_ExpiredForceCache()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesAvailableExpired.Returns(true);
|
||||
cache.GetBikesAvailableAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesAvailable(true);
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, bikes.Source.Name);
|
||||
Assert.IsNull(bikes.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesAvailable_Expired()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesAvailableExpired.Returns(true);
|
||||
https.GetBikesAvailableAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesAvailable();
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps).Name, bikes.Source.Name);
|
||||
Assert.IsNull(bikes.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesAvailable_Exception()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesAvailableExpired.Returns(true);
|
||||
cache.GetBikesAvailableAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
https.GetBikesAvailableAsync().Returns<BikesAvailableResponse>(x => { throw new WebConnectFailureException("Bang...", new Exception()); });
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesAvailable();
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, bikes.Source.Name);
|
||||
Assert.AreEqual("Bang...", bikes.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied_NotExpired()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesOccupiedExpired.Returns(false);
|
||||
cache.GetBikesOccupiedAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"12345678", // Merchant id
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"f782a208d9399291ba8d086b5dcc2509", // Auth cookie
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesOccupied();
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes_occupied.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, bikes.Source.Name);
|
||||
Assert.IsNull(bikes.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied_ExpiredForceCache()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesOccupiedExpired.Returns(true);
|
||||
cache.GetBikesOccupiedAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"12345678", // Merchant id
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"f782a208d9399291ba8d086b5dcc2509", // Auth cookie
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesOccupied(true);
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes_occupied.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, bikes.Source.Name);
|
||||
Assert.IsNull(bikes.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied_Expired()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesOccupiedExpired.Returns(true);
|
||||
https.GetBikesOccupiedAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"12345678", // Merchant id
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"f782a208d9399291ba8d086b5dcc2509", // Auth cookie
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesOccupied();
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes_occupied.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps).Name, bikes.Source.Name);
|
||||
Assert.IsNull(bikes.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied_Exception()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesOccupiedExpired.Returns(true);
|
||||
cache.GetBikesOccupiedAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
https.GetBikesOccupiedAsync().Returns<BikesReservedOccupiedResponse>(x => { throw new WebConnectFailureException("Bang...", new Exception()); });
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"12345678", // Merchant id
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"f782a208d9399291ba8d086b5dcc2509", // Auth cookie
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesOccupied();
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes_occupied.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, bikes.Source.Name);
|
||||
Assert.AreEqual("Bang...", bikes.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_NotExpired()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsStationsExpired.Returns(false);
|
||||
cache.GetStationsAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123", // Merchant id
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"456", // cookie
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var stations = await provider.GetStations();
|
||||
|
||||
Assert.AreEqual(3, stations.Response.stations.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, stations.Source.Name);
|
||||
Assert.IsNull(stations.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_ExpiredForceCache()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsStationsExpired.Returns(true);
|
||||
cache.GetStationsAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var stations = await provider.GetStations(true);
|
||||
|
||||
Assert.AreEqual(3, stations.Response.stations.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, stations.Source.Name);
|
||||
Assert.IsNull(stations.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_Expired()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsStationsExpired.Returns(true);
|
||||
https.GetStationsAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var stations = await provider.GetStations();
|
||||
|
||||
Assert.AreEqual(3, stations.Response.stations.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps).Name, stations.Source.Name);
|
||||
Assert.IsNull(stations.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_Exception()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsStationsExpired.Returns(true);
|
||||
cache.GetStationsAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
https.GetStationsAsync().Returns<StationsAllResponse>(x => { throw new WebConnectFailureException("Bang...", new Exception()); });
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var stations = await provider.GetStations();
|
||||
|
||||
Assert.AreEqual(3, stations.Response.stations.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, stations.Source.Name);
|
||||
Assert.AreEqual("Bang...", stations.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Test_AddToCache_Stations()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Barrel.ApplicationId))
|
||||
{
|
||||
Barrel.ApplicationId = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
||||
}
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123456789",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default");
|
||||
|
||||
var stations = await provider.GetStations(true);
|
||||
Assert.AreEqual(0, stations.Response.stations.Count);
|
||||
|
||||
try
|
||||
{
|
||||
// Do not add if an excption occurred
|
||||
provider.AddToCache(new Result<StationsAllResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL), new System.Exception("Bang...")));
|
||||
stations = await provider.GetStations(true);
|
||||
Assert.AreEqual(0, stations.Response.stations.Count);
|
||||
|
||||
// Do not add if results from cache
|
||||
provider.AddToCache(new Result<StationsAllResponse>(typeof(CopriCallsMonkeyStore), JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
stations = await provider.GetStations(true);
|
||||
Assert.AreEqual(0, stations.Response.stations.Count);
|
||||
|
||||
// Add result
|
||||
provider.AddToCache(new Result<StationsAllResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
stations = await provider.GetStations(true);
|
||||
Assert.AreEqual(3, stations.Response.stations.Count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Barrel.Current.EmptyAll();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Test_AddToCache_BikesAvailable()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Barrel.ApplicationId))
|
||||
{
|
||||
Barrel.ApplicationId = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
||||
}
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123456789",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default");
|
||||
|
||||
var bikes = await provider.GetBikesAvailable(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes.Count);
|
||||
|
||||
try
|
||||
{
|
||||
// Do not add if an excption occurred
|
||||
provider.AddToCache(new Result<BikesAvailableResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE), new System.Exception("Bang...")));
|
||||
bikes = await provider.GetBikesAvailable(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes.Count);
|
||||
|
||||
// Do not add if results from cache
|
||||
provider.AddToCache(new Result<BikesAvailableResponse>(typeof(CopriCallsMonkeyStore), JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
bikes = await provider.GetBikesAvailable(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes.Count);
|
||||
|
||||
// Add result
|
||||
provider.AddToCache(new Result<BikesAvailableResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
bikes = await provider.GetBikesAvailable(true);
|
||||
Assert.AreEqual(1, bikes.Response.bikes.Count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Barrel.Current.EmptyAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task Test_AddToCache_BikesOccupied()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Barrel.ApplicationId))
|
||||
{
|
||||
Barrel.ApplicationId = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
||||
}
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123456789",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"876");
|
||||
|
||||
var bikes = await provider.GetBikesOccupied(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes_occupied.Count);
|
||||
|
||||
try
|
||||
{
|
||||
// Do not add if an excption occurred
|
||||
provider.AddToCache(new Result<BikesReservedOccupiedResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED), new System.Exception("Bang...")));
|
||||
bikes = await provider.GetBikesOccupied(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes_occupied.Count);
|
||||
|
||||
// Do not add if results from cache
|
||||
provider.AddToCache(new Result<BikesReservedOccupiedResponse>(typeof(CopriCallsMonkeyStore), JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
bikes = await provider.GetBikesOccupied(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes_occupied.Count);
|
||||
|
||||
// Add result
|
||||
provider.AddToCache(new Result<BikesReservedOccupiedResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
bikes = await provider.GetBikesOccupied(true);
|
||||
Assert.AreEqual(1, bikes.Response.bikes_occupied.Count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Barrel.Current.EmptyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
866
TestShareeLib/Model/Connector/TestUpdaterJSON.cs
Normal file
866
TestShareeLib/Model/Connector/TestUpdaterJSON.cs
Normal file
|
@ -0,0 +1,866 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using TINK.Model;
|
||||
using TINK.Model.Bike;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Repository.Response;
|
||||
using TINK.Model.State;
|
||||
using TINK.Repository;
|
||||
|
||||
using static TINK.Repository.CopriCallsMemory;
|
||||
|
||||
using BikeInfo = TINK.Model.Bike.BluetoothLock.BikeInfo;
|
||||
using TINK.Model.User.Account;
|
||||
|
||||
namespace TestTINKLib.Fixtures.Connector
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestUpdaterJSON
|
||||
{
|
||||
[Test]
|
||||
public void TestGetAllStations()
|
||||
{
|
||||
var l_oStationsTarget = UpdaterJSON.GetStationsAllMutable(new CopriCallsMemory(SampleSets.Set2, 1).GetStationsAsync().Result);
|
||||
|
||||
Assert.AreEqual(9, l_oStationsTarget.Count);
|
||||
|
||||
// Check first entry.
|
||||
Assert.NotNull(l_oStationsTarget.GetById("4"));
|
||||
Assert.AreEqual("TINK", String.Join(",", l_oStationsTarget.GetById("4").Group.ToArray()));
|
||||
Assert.AreEqual("4", l_oStationsTarget.GetById("4").Id);
|
||||
Assert.AreEqual(47.6586936667, l_oStationsTarget.GetById("4").Position.Latitude);
|
||||
Assert.AreEqual(9.16863116667, l_oStationsTarget.GetById("4").Position.Longitude);
|
||||
|
||||
Assert.NotNull(l_oStationsTarget.GetById("14"));
|
||||
Assert.AreEqual("Konrad", String.Join(",", l_oStationsTarget.GetById("14").Group.ToArray()));
|
||||
|
||||
Assert.NotNull(l_oStationsTarget.GetById("31"));
|
||||
Assert.AreEqual("TINK,Konrad", String.Join(",", l_oStationsTarget.GetById("31").Group.ToArray()));
|
||||
Assert.AreEqual("Südstadt Station", l_oStationsTarget.GetById("31").StationName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUpdateBikesAvailable_BikeNr5GetBooked()
|
||||
{
|
||||
// Bike 5 is availalbe.
|
||||
var l_oBikesTarget = UpdaterJSON.GetBikesAvailable(
|
||||
GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 1));
|
||||
|
||||
Assert.AreEqual(12, l_oBikesTarget.Count, "Bike 5 is available an must be part of available bikes collection");
|
||||
|
||||
// Verify state of bike 5.
|
||||
Assert.NotNull(l_oBikesTarget.GetById("5"));
|
||||
Assert.AreEqual("5", l_oBikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, l_oBikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, l_oBikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikesTarget.GetById("5").State.Value);
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5").State.Code);
|
||||
|
||||
// Bike 5 is reserved.
|
||||
// Count of bikes must decrease and bike #5 no more in list of bikes.
|
||||
l_oBikesTarget = UpdaterJSON.GetBikesAvailable(
|
||||
GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 2));
|
||||
|
||||
Assert.AreEqual(11, l_oBikesTarget.Count, "One bike (nr. 5) got reserved");
|
||||
Assert.Null(l_oBikesTarget.GetById("5"), "Bike 5 got requested and must not be part of available bikes collection");
|
||||
|
||||
// Bike 5 is booked.
|
||||
// Count of bikes must decrease and bike #5 no more in list of bikes.
|
||||
l_oBikesTarget = UpdaterJSON.GetBikesAvailable(
|
||||
GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 3));
|
||||
|
||||
Assert.Null(l_oBikesTarget.GetById("5"), "Bike 5 got booked and must not be part of available bikes collection");
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUpdateBikesOccupied_BikeNr5GetBooked()
|
||||
{
|
||||
var l_oBikesTarget = UpdaterJSON.GetBikesOccupied(
|
||||
GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 1),
|
||||
"a@B",
|
||||
() => new DateTime(2017, 11, 28, 14, 8, 14)); // Date time now for bikes which are reserved
|
||||
|
||||
// Check initial count of bikes.
|
||||
Assert.AreEqual(2, l_oBikesTarget.Count);
|
||||
|
||||
// Bike 5 is reserved
|
||||
l_oBikesTarget = UpdaterJSON.GetBikesOccupied(
|
||||
GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 2),
|
||||
"a@B",
|
||||
() => new DateTime(2017, 11, 28, 14, 08, 36).Add(new TimeSpan(0, 2, 0))); // Date time now for bikes which are reserved
|
||||
|
||||
Assert.AreEqual(3, l_oBikesTarget.Count, "One bike (nr. 5) got reserved");
|
||||
|
||||
Assert.NotNull(l_oBikesTarget.GetById("5"));
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oBikesTarget.GetById("5").State.Value);
|
||||
Assert.AreEqual("5", l_oBikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, l_oBikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, l_oBikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(DateTime.Parse("2017-11-28 14:07:13.745568+01"), l_oBikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
Assert.AreEqual("2360", l_oBikesTarget.GetById("5").State.Code);
|
||||
|
||||
|
||||
// Bike 5 is booked
|
||||
l_oBikesTarget = UpdaterJSON.GetBikesOccupied(
|
||||
GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 3),
|
||||
"a@B",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(3, l_oBikesTarget.Count, "One bike (nr. 5) got booked");
|
||||
|
||||
Assert.IsNotNull(l_oBikesTarget.GetById("5"));
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oBikesTarget.GetById("5").State.Value);
|
||||
Assert.AreEqual("5", l_oBikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, l_oBikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, l_oBikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(DateTime.Parse("2017 -11-28 14:08:32.756368+01"), l_oBikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
Assert.AreEqual("2360", l_oBikesTarget.GetById("5").State.Code);
|
||||
}
|
||||
|
||||
public void TestGetBikesAvailable_BikeNr5GetBooked()
|
||||
{
|
||||
// Bike 5 is availalbe.
|
||||
var l_oBikesTarget = UpdaterJSON.GetBikesAvailable(GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 1));
|
||||
|
||||
Assert.AreEqual(11, l_oBikesTarget.Count, "Bike 5 is available an must be part of available bikes collection");
|
||||
|
||||
// Verify state of bike 5.
|
||||
Assert.NotNull(l_oBikesTarget.GetById("5"));
|
||||
Assert.AreEqual(5, l_oBikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, l_oBikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, l_oBikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikesTarget.GetById("5").State.Value);
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5").State.Code);
|
||||
|
||||
// Bike 5 is reserved.
|
||||
// Count of bikes must decrease and bike #5 no more in list of bikes.
|
||||
l_oBikesTarget = UpdaterJSON.GetBikesAvailable(GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 2));
|
||||
|
||||
Assert.AreEqual(10, l_oBikesTarget.Count, "One bike (nr. 5) got reserved");
|
||||
Assert.Null(l_oBikesTarget.GetById("5"), "Bike 5 got requested and must not be part of available bikes collection");
|
||||
|
||||
// Bike 5 is booked.
|
||||
// Count of bikes must decrease and bike #5 no more in list of bikes.
|
||||
l_oBikesTarget = UpdaterJSON.GetBikesAvailable(GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 3));
|
||||
|
||||
Assert.Null(l_oBikesTarget.GetById("5"), "Bike 5 got booked and must not be part of available bikes collection");
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesOccupied_BikeNr5GetBooked()
|
||||
{
|
||||
var l_oBikesTarget = UpdaterJSON.GetBikesOccupied(
|
||||
GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 1),
|
||||
"a@B",
|
||||
() => new DateTime(2017, 11, 28, 14, 8, 14)); // Date time now for bikes which are reserved
|
||||
|
||||
// Check initial count of bikes.
|
||||
Assert.AreEqual(2, l_oBikesTarget.Count);
|
||||
|
||||
// Bike 5 is reserved
|
||||
l_oBikesTarget = UpdaterJSON.GetBikesOccupied(
|
||||
GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 2),
|
||||
"a@B",
|
||||
() => new DateTime(2017, 11, 28, 14, 08, 36).Add(new TimeSpan(0, 2, 0))); // Date time now for bikes which are reserved
|
||||
|
||||
Assert.AreEqual(3, l_oBikesTarget.Count, "One bike (nr. 5) got reserved");
|
||||
|
||||
Assert.NotNull(l_oBikesTarget.GetById("5"));
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, l_oBikesTarget.GetById("5").State.Value);
|
||||
Assert.AreEqual("5", l_oBikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, l_oBikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, l_oBikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(DateTime.Parse("2017-11-28 14:07:13.745568+01"), l_oBikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
Assert.AreEqual("2360", l_oBikesTarget.GetById("5").State.Code);
|
||||
|
||||
|
||||
// Bike 5 is booked
|
||||
l_oBikesTarget = UpdaterJSON.GetBikesOccupied(
|
||||
CopriCallsMemory.GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 3),
|
||||
"a@B",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(3, l_oBikesTarget.Count, "One bike (nr. 5) got booked");
|
||||
|
||||
Assert.IsNotNull(l_oBikesTarget.GetById("5"));
|
||||
Assert.AreEqual(InUseStateEnum.Booked, l_oBikesTarget.GetById("5").State.Value);
|
||||
Assert.AreEqual("5", l_oBikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, l_oBikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, l_oBikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(DateTime.Parse("2017 -11-28 14:08:32.756368+01"), l_oBikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
Assert.AreEqual("2360", l_oBikesTarget.GetById("5").State.Code);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAvailable()
|
||||
{
|
||||
var l_oBikesTarget = UpdaterJSON.GetBikesAvailable(
|
||||
GetBikesAvailable(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 1));
|
||||
|
||||
// Verify count of bikes
|
||||
Assert.AreEqual(12, l_oBikesTarget.Count);
|
||||
|
||||
// Verify properties of bike 5
|
||||
Assert.NotNull(l_oBikesTarget.GetById("5"));
|
||||
Assert.AreEqual("5", l_oBikesTarget.GetById("5").Id);
|
||||
Assert.AreEqual("TINK", l_oBikesTarget.GetById("5").Group.ToArray()[0]);
|
||||
Assert.AreEqual(TypeOfBike.Cargo, l_oBikesTarget.GetById("5").TypeOfBike);
|
||||
Assert.AreEqual(WheelType.Two, l_oBikesTarget.GetById("5").WheelType);
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikesTarget.GetById("5").State.Value);
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5").State.From); // Sommer/ Winterzeit!
|
||||
Assert.IsNull(l_oBikesTarget.GetById("5").State.Code);
|
||||
|
||||
// Verify properties of bike 52
|
||||
Assert.NotNull(l_oBikesTarget.GetById("52"));
|
||||
Assert.AreEqual("52", l_oBikesTarget.GetById("52").Id);
|
||||
Assert.AreEqual("Konrad", l_oBikesTarget.GetById("52").Group.ToArray()[0]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesOccupied()
|
||||
{
|
||||
var l_oBikesTarget = UpdaterJSON.GetBikesOccupied(
|
||||
GetBikesOccupied(TinkApp.MerchantId, SampleSets.Set2, 1),
|
||||
"a@b",
|
||||
() => DateTime.Now);
|
||||
|
||||
// Verify count of bikes
|
||||
Assert.AreEqual(0, l_oBikesTarget.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAll_BikesAvaialbleResponse()
|
||||
{
|
||||
var availableResponse = JsonConvert.DeserializeObject<BikesAvailableResponse>(
|
||||
@"{
|
||||
""bikes"" : {
|
||||
""2352"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
||||
""station"" : ""9"",
|
||||
""system"" : ""Ilockit""
|
||||
},
|
||||
""2379"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""19"",
|
||||
""gps"" : { ""latitude"": ""47.6597846667"", ""longitude"": ""9.177439"" },
|
||||
""station"" : ""3""
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var bikes = UpdaterJSON.GetBikesAll(
|
||||
availableResponse,
|
||||
null,
|
||||
"Heinz.Mustermann@posteo.de",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(
|
||||
2,
|
||||
bikes.Count);
|
||||
|
||||
Assert.AreEqual(
|
||||
1,
|
||||
bikes.Where(x => x is BikeInfo).Count(),
|
||||
"There must be one ILockitBike and one BC bike (BikeInfo class).");
|
||||
}
|
||||
[Test]
|
||||
public void TestGetBikesAll_BikesAvaialbleResponse_InvalidState()
|
||||
{
|
||||
var availableResponse = JsonConvert.DeserializeObject<BikesAvailableResponse>(
|
||||
@"{
|
||||
""bikes"" : {
|
||||
""2352"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""reserved"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
||||
""station"" : ""9""
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var bikes = UpdaterJSON.GetBikesAll(
|
||||
availableResponse,
|
||||
null,
|
||||
"Heinz.Mustermann@posteo.de",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
bikes.Count,
|
||||
"State of a element of BikesAvailableResponse must never be reserved.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAll_BikesAvaialbleResponse_InvalidStation()
|
||||
{
|
||||
var availableResponse = JsonConvert.DeserializeObject<BikesAvailableResponse>(
|
||||
@"{
|
||||
""bikes"" : {
|
||||
""2352"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
||||
""station"" : """"
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var bikes = UpdaterJSON.GetBikesAll(
|
||||
availableResponse,
|
||||
null,
|
||||
"Heinz.Mustermann@posteo.de",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
bikes.Count,
|
||||
"Station of a element of BikesAvailableResponse must always be defined.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAll_BikesAvaialbleResponse_DuplicateId()
|
||||
{
|
||||
var availableResponse = JsonConvert.DeserializeObject<BikesAvailableResponse>(
|
||||
@"{
|
||||
""bikes"" : {
|
||||
""2352"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
||||
""station"" : ""9""
|
||||
},
|
||||
""2379"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.6597846667"", ""longitude"": ""9.177439"" },
|
||||
""station"" : ""3""
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var bikes = UpdaterJSON.GetBikesAll(
|
||||
availableResponse,
|
||||
null,
|
||||
"Heinz.Mustermann@posteo.de",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
bikes.Count,
|
||||
"Ids of a elements of BikesAvailableResponse must be unique.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAll_BikesReservedOccupiedResponse_InvalidState()
|
||||
{
|
||||
var reservedOccupiedResponse = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(
|
||||
@"{
|
||||
""bikes_occupied"" : {
|
||||
""87785"" : {
|
||||
""station"" : ""2"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""20"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""start_time"" : ""2017-12-01 22:21:57.740069+01"",
|
||||
""timeCode"" : ""6603""
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var bikes = UpdaterJSON.GetBikesAll(
|
||||
null,
|
||||
reservedOccupiedResponse,
|
||||
"Heinz.Mustermann@posteo.de",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
bikes.Count,
|
||||
"State of a element of BikesAvailableResponse must never be reserved.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAll_BikesReservedOccupiedResponse_DuplicateId()
|
||||
{
|
||||
var reservedOccupiedResponse = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(
|
||||
@"{
|
||||
""bikes_occupied"" : {
|
||||
""87785"" : {
|
||||
""station"" : ""2"",
|
||||
""state"" : ""occupied"",
|
||||
""bike"" : ""20"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""start_time"" : ""2017-12-01 22:21:57.740069+01"",
|
||||
""timeCode"" : ""6603""
|
||||
},
|
||||
""87782"" : {
|
||||
""station"" : ""4"",
|
||||
""state"" : ""occupied"",
|
||||
""bike"" : ""20"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""start_time"" : ""2017-11-28 13:06:55.147368+01"",
|
||||
""timeCode"" : ""2931""
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var bikes = UpdaterJSON.GetBikesAll(
|
||||
null,
|
||||
reservedOccupiedResponse,
|
||||
"Heinz.Mustermann@posteo.de",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
bikes.Count,
|
||||
"Ids of a elements of BikesAvailableResponse must be unique.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAll_BikesReservedOccupiedResponse()
|
||||
{
|
||||
var reservedOccupiedResponse = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(
|
||||
@"{
|
||||
""bikes_occupied"" : {
|
||||
""87785"" : {
|
||||
""station"" : ""2"",
|
||||
""state"" : ""occupied"",
|
||||
""bike"" : ""20"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""start_time"" : ""2017-12-01 22:21:57.740069+01"",
|
||||
""timeCode"" : ""6603"",
|
||||
""system"" : ""Ilockit""
|
||||
},
|
||||
""87782"" : {
|
||||
""station"" : ""4"",
|
||||
""state"" : ""occupied"",
|
||||
""bike"" : ""7"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""start_time"" : ""2017-11-28 13:06:55.147368+01"",
|
||||
""timeCode"" : ""2931""
|
||||
}
|
||||
}
|
||||
}");
|
||||
|
||||
var bikes = UpdaterJSON.GetBikesAll(
|
||||
null,
|
||||
reservedOccupiedResponse,
|
||||
"Heinz.Mustermann@posteo.de",
|
||||
() => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(
|
||||
2,
|
||||
bikes.Count,
|
||||
"Ids of a elements of BikesAvailableResponse must be unique.");
|
||||
|
||||
Assert.AreEqual(
|
||||
1,
|
||||
bikes.Where(x => x is BikeInfo).Count(),
|
||||
"There must be one ILockitBike and one BC bike (BikeInfo class).");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLoad_Reserved_CalculateAuthKeys()
|
||||
{
|
||||
// Construct requested bike.
|
||||
var bike = new TINK.Model.Bike.BluetoothLock.BikeInfoMutable(new BikeInfo(
|
||||
"17",
|
||||
22,
|
||||
new Guid("0000f00d-1212-efde-1523-785fef13d123"),
|
||||
new [] { (byte) 1, (byte)3, (byte)4 },
|
||||
new [] { (byte)11, (byte)3, (byte)1 },
|
||||
new [] { (byte)12, (byte)7, (byte)4 },
|
||||
DateTime.Now,
|
||||
"a@b",
|
||||
"1",
|
||||
null,
|
||||
null,
|
||||
() => DateTime.Now));
|
||||
|
||||
var response = JsonConvert.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
||||
{
|
||||
""Ilockit_ID"": ""ISHAREIT+0815"",
|
||||
""state"": ""requested"",
|
||||
""start_time"": ""2018-01-27 17:33:00.989464+01"",
|
||||
""K_seed"": ""[-18, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
||||
""K_u"": ""[99, 104, 120, 121, 63, 99, -10, -110, 94, 70, 15, -112, -6, 101, 117, -90, -113, -54, -90, -95, 0, 0, 0, 0]"",
|
||||
}");
|
||||
|
||||
// Update from new auth keys.
|
||||
bike.Load(response, "a@b", () => DateTime.Now);
|
||||
|
||||
// Verify that keys are correctly updated.
|
||||
Assert.IsTrue(new byte[] { 256 - 18, 256 - 80, 20, 256 - 90, 3, 69, 96, 4, 256 - 35, 75, 256 - 95, 102, 7, 121, 256 - 122, 15 }.SequenceEqual(bike.LockInfo.Seed));
|
||||
Assert.IsTrue(new byte[] { 99, 104, 120, 121, 63, 99, 256 - 10, 256 - 110, 94, 70, 15, 256 - 112, 256 - 6, 101, 117, 256-90, 256 - 113, 256 - 54, 256 - 90, 256 - 95, 0, 0, 0, 0 }.SequenceEqual(bike.LockInfo.UserKey));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLoad_Booked_CalculateAuthKeys()
|
||||
{
|
||||
// Construct occupied bike.
|
||||
var bike = new TINK.Model.Bike.BluetoothLock.BikeInfoMutable(new BikeInfo(
|
||||
"17",
|
||||
22,
|
||||
new Guid("0000f00d-1212-efde-1523-785fef13d123"),
|
||||
new[] { (byte)1, (byte)3, (byte)4 },
|
||||
new[] { (byte)11, (byte)3, (byte)1 },
|
||||
new[] { (byte)12, (byte)7, (byte)4 },
|
||||
DateTime.Now,
|
||||
"a@b",
|
||||
"1",
|
||||
null /*operator uri*/));
|
||||
|
||||
var response = JsonConvert.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
||||
{
|
||||
""Ilockit_ID"": ""ISHAREIT+0815"",
|
||||
""state"": ""occupied"",
|
||||
""start_time"": ""2018-01-27 17:33:00.989464+01"",
|
||||
""K_seed"": ""[-18, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
||||
""K_u"": ""[99, 104, 120, 121, 63, 99, -10, -110, 94, 70, 15, -112, -6, 101, 117, -90, -113, -54, -90, -95, 0, 0, 0, 0]"",
|
||||
}");
|
||||
|
||||
// Update from new auth keys.
|
||||
bike.Load(response, "a@b", () => DateTime.Now);
|
||||
|
||||
// Verify that keys are correctly updated.
|
||||
Assert.IsTrue(new byte[] { 256 - 18, 256 - 80, 20, 256 - 90, 3, 69, 96, 4, 256 - 35, 75, 256 - 95, 102, 7, 121, 256 - 122, 15 }.SequenceEqual(bike.LockInfo.Seed));
|
||||
Assert.IsTrue(new byte[] { 99, 104, 120, 121, 63, 99, 256 - 10, 256 - 110, 94, 70, 15, 256 - 112, 256 - 6, 101, 117, 256 - 90, 256 - 113, 256 - 54, 256 - 90, 256 - 95, 0, 0, 0, 0 }.SequenceEqual(bike.LockInfo.UserKey));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLoad_Reserved_DoBook()
|
||||
{
|
||||
// Construct requested bike.
|
||||
var bike = new TINK.Model.Bike.BluetoothLock.BikeInfoMutable(new BikeInfo(
|
||||
"17",
|
||||
22,
|
||||
new Guid("0000f00d-1212-efde-1523-785fef13d123"),
|
||||
new[] { (byte)1, (byte)3, (byte)4 },
|
||||
new[] { (byte)11, (byte)3, (byte)1 },
|
||||
new[] { (byte)12, (byte)7, (byte)4 },
|
||||
DateTime.Now,
|
||||
"a@b",
|
||||
"1",
|
||||
null,
|
||||
null,
|
||||
() => DateTime.Now));
|
||||
|
||||
Assert.AreEqual(InUseStateEnum.Reserved, bike.State.Value);
|
||||
|
||||
var response = JsonConvert.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
||||
{
|
||||
""Ilockit_ID"": ""ISHAREIT+0815"",
|
||||
""state"": ""occupied"",
|
||||
""start_time"": ""2018-01-27 17:33:00.989464+01"",
|
||||
""K_seed"": ""[-18, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
||||
""K_u"": ""[99, 104, 120, 121, 63, 99, -10, -110, 94, 70, 15, -112, -6, 101, 117, -90, -113, -54, -90, -95, 0, 0, 0, 0]"",
|
||||
}");
|
||||
|
||||
// Update from new auth keys.
|
||||
bike.Load(response, "a@b", () => DateTime.Now);
|
||||
|
||||
Assert.AreEqual(InUseStateEnum.Booked, bike.State.Value);
|
||||
}
|
||||
|
||||
/// <summary> Verifies loading a default user without special permissions.</summary>
|
||||
[Test]
|
||||
public void TestGetAccount_DebugLevelNone()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<AuthorizationResponse>(@"
|
||||
{
|
||||
""response_state"" : ""OK: nothing todo "",
|
||||
""user_group"" : [ ""300029"", ""300001"" ],
|
||||
""user_id"" : ""ohauff@posteo.de"",
|
||||
""authcookie"" : ""5781_f172cf59108fe53e7524c841847fee69_oiF2kahH"",
|
||||
""response"" : ""authorization"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""response_text"" : ""Herzlich willkommen im Fahrradmietsystem"",
|
||||
""debuglevel"" : ""0"",
|
||||
""apiserver"" : ""https://shareeapp-fr01.copri.eu""
|
||||
}");
|
||||
|
||||
var account = response.GetAccount("merch123", "hallo@welt", "0815");
|
||||
|
||||
Assert.That(
|
||||
account.DebugLevel,
|
||||
Is.EqualTo(Permissions.None));
|
||||
}
|
||||
|
||||
/// <summary> Verifies loading a admin user with all special permissions.</summary>
|
||||
[Test]
|
||||
public void TestGetAccount_DebugLevelAll()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<AuthorizationResponse>(@"
|
||||
{
|
||||
""response_state"" : ""OK: nothing todo "",
|
||||
""user_group"" : [ ""300029"", ""300001"" ],
|
||||
""user_id"" : ""ohauff@posteo.de"",
|
||||
""authcookie"" : ""5781_f172cf59108fe53e7524c841847fee69_oiF2kahH"",
|
||||
""response"" : ""authorization"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""response_text"" : ""Herzlich willkommen im Fahrradmietsystem"",
|
||||
""debuglevel"" : ""1"",
|
||||
""apiserver"" : ""https://shareeapp-fr01.copri.eu""
|
||||
}");
|
||||
|
||||
var account = response.GetAccount("merch123", "hallo@welt", "0815");
|
||||
|
||||
Assert.That(
|
||||
account.DebugLevel,
|
||||
Is.EqualTo(Permissions.All));
|
||||
}
|
||||
|
||||
/// <summary> Verifies loading a admin user with all special permissions.</summary>
|
||||
[Test]
|
||||
public void TestGetAccount_DebugLevel_Logging()
|
||||
{
|
||||
var response = JsonConvert.DeserializeObject<AuthorizationResponse>(@"
|
||||
{
|
||||
""response_state"" : ""OK: nothing todo "",
|
||||
""user_group"" : [ ""300029"", ""300001"" ],
|
||||
""user_id"" : ""ohauff@posteo.de"",
|
||||
""authcookie"" : ""5781_f172cf59108fe53e7524c841847fee69_oiF2kahH"",
|
||||
""response"" : ""authorization"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""response_text"" : ""Herzlich willkommen im Fahrradmietsystem"",
|
||||
""debuglevel"" : ""64"",
|
||||
""apiserver"" : ""https://shareeapp-fr01.copri.eu""
|
||||
}");
|
||||
|
||||
var account = response.GetAccount("merch123", "hallo@welt", "0815");
|
||||
|
||||
Assert.That(
|
||||
account.DebugLevel,
|
||||
Is.EqualTo(Permissions.PickLoggingLevel));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription()
|
||||
{
|
||||
var tariffDescription = TINK.Repository.Response.JsonConvertRethrow.DeserializeObject<TINK.Repository.Response.TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.50"",
|
||||
""abo_eur_per_month"" : ""920.99"",
|
||||
""free_hours"" : ""1.50"",
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().Name,
|
||||
Is.EqualTo("Tester Basic"));
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().Number,
|
||||
Is.EqualTo(5494));
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().FreeTimePerSession,
|
||||
Is.EqualTo(TimeSpan.FromMinutes(90)));
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().FeeEuroPerHour,
|
||||
Is.EqualTo(10.5));
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().AboEuroPerMonth,
|
||||
Is.EqualTo(920.99));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_Name()
|
||||
{
|
||||
var tariffDescription = TINK.Repository.Response.JsonConvertRethrow.DeserializeObject<TINK.Repository.Response.TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.50"",
|
||||
""abo_eur_per_month"" : ""920.99"",
|
||||
""free_hours"" : ""1.50"",
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().Name,
|
||||
Is.EqualTo("Tester Basic"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_Number()
|
||||
{
|
||||
var tariffDescription = TINK.Repository.Response.JsonConvertRethrow.DeserializeObject<TINK.Repository.Response.TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.50"",
|
||||
""abo_eur_per_month"" : ""920.99"",
|
||||
""free_hours"" : ""1.50"",
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().Number,
|
||||
Is.EqualTo(5494));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_FreeTimePerSession()
|
||||
{
|
||||
var tariffDescription = TINK.Repository.Response.JsonConvertRethrow.DeserializeObject<TINK.Repository.Response.TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.50"",
|
||||
""abo_eur_per_month"" : ""920.99"",
|
||||
""free_hours"" : ""1.50"",
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().FreeTimePerSession,
|
||||
Is.EqualTo(TimeSpan.FromMinutes(90)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_FeeEuroPerHour()
|
||||
{
|
||||
var tariffDescription = TINK.Repository.Response.JsonConvertRethrow.DeserializeObject<TINK.Repository.Response.TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.50"",
|
||||
""abo_eur_per_month"" : ""920.99"",
|
||||
""free_hours"" : ""1.50"",
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().FeeEuroPerHour,
|
||||
Is.EqualTo(10.5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_AboEuroPerMonth()
|
||||
{
|
||||
var tariffDescription = TINK.Repository.Response.JsonConvertRethrow.DeserializeObject<TINK.Repository.Response.TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.50"",
|
||||
""abo_eur_per_month"" : ""920.99"",
|
||||
""free_hours"" : ""1.50"",
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().AboEuroPerMonth,
|
||||
Is.EqualTo(920.99));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_Name_Empty()
|
||||
{
|
||||
var tariffDescription = TINK.Repository.Response.JsonConvertRethrow.DeserializeObject<TINK.Repository.Response.TariffDescription>(
|
||||
@"{}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().Name,
|
||||
Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_Number_Empty()
|
||||
{
|
||||
var tariffDescription = TINK.Repository.Response.JsonConvertRethrow.DeserializeObject<TINK.Repository.Response.TariffDescription>(
|
||||
@"{}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().Number,
|
||||
Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_FreeTimePerSession_Empty()
|
||||
{
|
||||
var tariffDescription = TINK.Repository.Response.JsonConvertRethrow.DeserializeObject<TINK.Repository.Response.TariffDescription>(
|
||||
@"{}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().FreeTimePerSession,
|
||||
Is.EqualTo(TimeSpan.Zero));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_FeeEuroPerHour_Empty()
|
||||
{
|
||||
var tariffDescription = TINK.Repository.Response.JsonConvertRethrow.DeserializeObject<TINK.Repository.Response.TariffDescription>(
|
||||
@"{}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().FeeEuroPerHour,
|
||||
Is.NaN);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_AboEuroPerMonth_Empty()
|
||||
{
|
||||
var tariffDescription = TINK.Repository.Response.JsonConvertRethrow.DeserializeObject<TINK.Repository.Response.TariffDescription>(
|
||||
@"{}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.Create().AboEuroPerMonth,
|
||||
Is.NaN);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_Name_Null()
|
||||
{
|
||||
Assert.That(
|
||||
BikeInfoFactory.Create((TINK.Repository.Response.TariffDescription)null).Name,
|
||||
Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_Number_Null()
|
||||
{
|
||||
Assert.That(
|
||||
BikeInfoFactory.Create((TINK.Repository.Response.TariffDescription)null).Number,
|
||||
Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_FreeTimePerSession_Null()
|
||||
{
|
||||
Assert.That(
|
||||
BikeInfoFactory.Create((TINK.Repository.Response.TariffDescription)null).FreeTimePerSession,
|
||||
Is.EqualTo(TimeSpan.Zero));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_FeeEuroPerHour_Null()
|
||||
{
|
||||
Assert.That(
|
||||
BikeInfoFactory.Create((TINK.Repository.Response.TariffDescription)null).FeeEuroPerHour,
|
||||
Is.NaN);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateTariffDescription_AboEuroPerMonth_Null()
|
||||
{
|
||||
Assert.That(
|
||||
BikeInfoFactory.Create((TINK.Repository.Response.TariffDescription)null).AboEuroPerMonth,
|
||||
Is.NaN);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,16 +13,16 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
|
|||
public void TestGetAtStation()
|
||||
{
|
||||
var coll = new BikeCollection(
|
||||
new Dictionary<int, TINK.Model.Bike.BC.BikeInfo>
|
||||
new Dictionary<string, TINK.Model.Bike.BC.BikeInfo>
|
||||
{
|
||||
{3, new TINK.Model.Bike.BC.BikeInfo(7, 3 /* Stadion id */) },
|
||||
{7, new TINK.Model.Bike.BC.BikeInfo(8, 12 /* Stadion id */) },
|
||||
{12, new TINK.Model.Bike.BC.BikeInfo(33, 12 /* Stadion id */) }
|
||||
{"3", new TINK.Model.Bike.BC.BikeInfo("7", "3" /* Stadion id */) },
|
||||
{"7", new TINK.Model.Bike.BC.BikeInfo("8", "12" /* Stadion id */) },
|
||||
{"12", new TINK.Model.Bike.BC.BikeInfo("33", "12" /* Stadion id */) }
|
||||
});
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
BikeCollectionFilter.GetAtStation(null, 12).Count);
|
||||
BikeCollectionFilter.GetAtStation(null, "12").Count);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
|
@ -30,15 +30,15 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
|
|||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
coll.GetAtStation(22).Count);
|
||||
coll.GetAtStation("22").Count);
|
||||
|
||||
Assert.AreEqual(
|
||||
1,
|
||||
coll.GetAtStation(3).Count);
|
||||
coll.GetAtStation("3").Count);
|
||||
|
||||
Assert.AreEqual(
|
||||
2,
|
||||
coll.GetAtStation(12).Count);
|
||||
coll.GetAtStation("12").Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -54,10 +54,10 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
|
|||
{
|
||||
// Holds no LockIt bikes
|
||||
var coll = new BikeCollection(
|
||||
new Dictionary<int, TINK.Model.Bike.BC.BikeInfo>
|
||||
new Dictionary<string, TINK.Model.Bike.BC.BikeInfo>
|
||||
{
|
||||
{7, new TINK.Model.Bike.BC.BikeInfo(8, 12 /* Stadion id */) },
|
||||
{12, new TINK.Model.Bike.BC.BikeInfo(33, 12 /* Stadion id */) }
|
||||
{"7", new TINK.Model.Bike.BC.BikeInfo("8", "12" /* Stadion id */) },
|
||||
{"12", new TINK.Model.Bike.BC.BikeInfo("33", "12" /* Stadion id */) }
|
||||
});
|
||||
|
||||
Assert.AreEqual(
|
||||
|
@ -71,11 +71,11 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
|
|||
|
||||
// Holds no LockIt bike with matching station number.
|
||||
var coll = new BikeCollection(
|
||||
new Dictionary<int, TINK.Model.Bike.BC.BikeInfo>
|
||||
new Dictionary<string, TINK.Model.Bike.BC.BikeInfo>
|
||||
{
|
||||
{7, new TINK.Model.Bike.BC.BikeInfo(8, 12 /* Stadion id */) },
|
||||
{11, new TINK.Model.Bike.BluetoothLock.BikeInfo(33, 5200544, new Guid("00000000-0000-0000-0000-000000000001"),12 /* Stadion id */) },
|
||||
{12, new TINK.Model.Bike.BC.BikeInfo(33, 12 /* Stadion id */) }
|
||||
{"7", new TINK.Model.Bike.BC.BikeInfo("8", "12" /* Stadion id */) },
|
||||
{"11", new TINK.Model.Bike.BluetoothLock.BikeInfo("33", 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "12" /* Stadion id */) },
|
||||
{"12", new TINK.Model.Bike.BC.BikeInfo("33", "12" /* Stadion id */) }
|
||||
});
|
||||
|
||||
Assert.AreEqual(
|
||||
|
|
74
TestShareeLib/Model/TestTinkApp.cs
Normal file
74
TestShareeLib/Model/TestTinkApp.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using TINK.Model;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Repository;
|
||||
using TINK.Model.Services.CopriApi.ServerUris;
|
||||
using static TINK.Repository.CopriCallsMemory;
|
||||
using TINK.Services;
|
||||
using NSubstitute;
|
||||
using TINK.Model.Services.Geolocation;
|
||||
using TINK.Services.BluetoothLock;
|
||||
using TINK.Model.Device;
|
||||
using TINK.Model.User.Account;
|
||||
using Plugin.Permissions.Abstractions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TestTINKLib.Fixtures.UseCases.Logout
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestTinkApp
|
||||
{
|
||||
[Test]
|
||||
public void Logout()
|
||||
{
|
||||
var accountStore = Substitute.For<IStore>();
|
||||
var locksService = Substitute.For<ILocksService>();
|
||||
var device = Substitute.For<ISmartDevice>();
|
||||
var specialFolder = Substitute.For<ISpecialFolder>();
|
||||
var permissions = Substitute.For<IPermissions>();
|
||||
var account = Substitute.For<IAccount>();
|
||||
|
||||
accountStore.Load().Returns(account);
|
||||
account.Mail.Returns("javaminister@gmail.com");
|
||||
account.Pwd.Returns("javaminister");
|
||||
account.SessionCookie.Returns("4da3044c8657a04ba60e2eaa753bc51a");
|
||||
account.Group.Returns(new List<string> { "TINK" });
|
||||
|
||||
// No user logged in is initial state to verify.
|
||||
var l_oTinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
activeLockService: locksService.GetType().FullName,
|
||||
activeGeolocationService: "NotRelevantActiveGeoloactionServiceName",
|
||||
activeUri: new Uri(CopriServerUriList.TINK_DEVEL)),
|
||||
accountStore,
|
||||
(isConnected, uri, sessionCookie, mail, expiresAfter) => string.IsNullOrEmpty(sessionCookie)
|
||||
? new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1))
|
||||
: new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)),
|
||||
Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService,
|
||||
device,
|
||||
specialFolder,
|
||||
null, // Cipher
|
||||
permissions,
|
||||
isConnectedFunc: () => true,
|
||||
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.IsTrue(l_oTinkApp.ActiveUser.IsLoggedIn);
|
||||
Assert.AreEqual(13, l_oTinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count);
|
||||
Assert.AreEqual(2, l_oTinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count);
|
||||
Assert.AreEqual("4da3044c8657a04ba60e2eaa753bc51a", l_oTinkApp.GetConnector(true).Command.SessionCookie);
|
||||
|
||||
// Log user out.
|
||||
l_oTinkApp.GetConnector(true).Command.DoLogout().Wait();
|
||||
l_oTinkApp.ActiveUser.Logout();
|
||||
|
||||
Assert.IsFalse(l_oTinkApp.ActiveUser.IsLoggedIn);
|
||||
Assert.AreEqual(11, l_oTinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count);
|
||||
Assert.AreEqual(0, l_oTinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count);
|
||||
Assert.IsNull(l_oTinkApp.GetConnector(true).Command.SessionCookie);
|
||||
}
|
||||
}
|
||||
}
|
67
TestShareeLib/Model/TestTinkAppLogin.cs
Normal file
67
TestShareeLib/Model/TestTinkAppLogin.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using TINK.Model;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Repository;
|
||||
using TINK.Model.Services.CopriApi.ServerUris;
|
||||
using static TINK.Repository.CopriCallsMemory;
|
||||
using TINK.Services;
|
||||
using NSubstitute;
|
||||
using TINK.Model.Services.Geolocation;
|
||||
using TINK.Services.BluetoothLock;
|
||||
using TINK.Model.Device;
|
||||
using TINK.Model.User.Account;
|
||||
using Plugin.Permissions.Abstractions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TestTINKLib.Fixtures.UseCases.Login
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestTinkApp
|
||||
{
|
||||
[Test]
|
||||
public async Task Login()
|
||||
{
|
||||
var accountStore = Substitute.For<IStore>();
|
||||
var locksService = Substitute.For<ILocksService>();
|
||||
var device = Substitute.For<ISmartDevice>();
|
||||
var specialFolder = Substitute.For<ISpecialFolder>();
|
||||
var permissions = Substitute.For<IPermissions>();
|
||||
|
||||
// No user logged in is initial state to verify.
|
||||
var l_oTinkApp = new TinkApp(
|
||||
new TINK.Model.Settings.Settings(
|
||||
activeLockService: locksService.GetType().FullName,
|
||||
activeGeolocationService: "NotRelevantActiveGeoloactionServiceName",
|
||||
activeUri: new Uri(CopriServerUriList.TINK_DEVEL)),
|
||||
accountStore,
|
||||
(isConnected, uri, sessionCookie, mail, expiresAfter) => string.IsNullOrEmpty(sessionCookie)
|
||||
? new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1)) as IConnector
|
||||
: new ConnectorCache(sessionCookie, mail, new CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)),
|
||||
Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService,
|
||||
device,
|
||||
specialFolder,
|
||||
null, // Cipher
|
||||
permissions,
|
||||
isConnectedFunc: () => true,
|
||||
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 lastVersion*/);
|
||||
|
||||
Assert.IsFalse(l_oTinkApp.ActiveUser.IsLoggedIn);
|
||||
Assert.AreEqual(11, l_oTinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count);
|
||||
Assert.AreEqual(0, l_oTinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count);
|
||||
Assert.IsNull(l_oTinkApp.GetConnector(true).Command.SessionCookie);
|
||||
|
||||
// Log user out.
|
||||
var l_oAccount = l_oTinkApp.GetConnector(true).Command.DoLogin("javaminister@gmail.com", "javaminister", "HwId1000000000000").Result;
|
||||
await l_oTinkApp.ActiveUser.Login(l_oAccount);
|
||||
|
||||
Assert.IsTrue(l_oTinkApp.ActiveUser.IsLoggedIn);
|
||||
Assert.AreEqual(13, l_oTinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count);
|
||||
Assert.AreEqual(2, l_oTinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count);
|
||||
Assert.AreEqual("4da3044c8657a04ba60e2eaa753bc51a", l_oTinkApp.GetConnector(true).Command.SessionCookie);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.Repository.Response;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Bike
|
||||
{
|
||||
|
@ -20,19 +20,21 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
|
|||
""bike"" : ""231"",
|
||||
""description"" : ""Stadtrad"",
|
||||
""system"" : ""BC"",
|
||||
""bike_group"" : ""Konrad"",
|
||||
""bike_group"" : [ ""Konrad"" ],
|
||||
""station"" : """",
|
||||
""state"" : ""available"",
|
||||
""gps"" : ""9.1594501, 47.6749928""
|
||||
""gps"" : { ""latitude"": ""9.1594501"", ""longitude"": ""47.6749928"" }
|
||||
}
|
||||
},
|
||||
""copri_version"" : ""3.0.0.0"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""authcookie"" : """",
|
||||
""response_state"" : ""OK""
|
||||
}
|
||||
");
|
||||
|
||||
Assert.IsNull(l_oBikes.bikes[231].station);
|
||||
Assert.That(
|
||||
l_oBikes.bikes["231"].station,
|
||||
Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -48,18 +50,18 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
|
|||
""bike"" : ""231"",
|
||||
""description"" : ""Stadtrad"",
|
||||
""system"" : ""BC"",
|
||||
""bike_group"" : ""Konrad"",
|
||||
""bike_group"" : [ ""Konrad"" ],
|
||||
""state"" : ""available"",
|
||||
""gps"" : ""9.1594501, 47.6749928""
|
||||
""gps"" : { ""latitude"": ""9.1594501"", ""longitude"": ""47.6749928"" }
|
||||
}
|
||||
},
|
||||
""copri_version"" : ""3.0.0.0"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""authcookie"" : """",
|
||||
""response_state"" : ""OK""
|
||||
}
|
||||
");
|
||||
|
||||
Assert.IsNull(l_oBikes.bikes[231].station);
|
||||
Assert.IsNull(l_oBikes.bikes["231"].station);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace TestShareeLib.Model.Repository.Response
|
|||
public void TestDeserializeObject()
|
||||
{
|
||||
Assert.That(
|
||||
() => JsonConvert.DeserializeObject<TariffDescription>(
|
||||
() => JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.00"",
|
||||
""abo_eur_per_month"" : ""920.00"",
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace TestShareeLib.Repository.Response
|
|||
[Test]
|
||||
public void TestDeserialize()
|
||||
{
|
||||
var tariffDescription = JsonConvert.DeserializeObject<TariffDescription>(
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.00"",
|
||||
""abo_eur_per_month"" : ""920.00"",
|
||||
|
@ -45,7 +45,7 @@ namespace TestShareeLib.Repository.Response
|
|||
[Test]
|
||||
public void TestDeserialize_Missing()
|
||||
{
|
||||
var tariffDescription = JsonConvert.DeserializeObject<TariffDescription>(
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
|
@ -78,7 +78,7 @@ namespace TestShareeLib.Repository.Response
|
|||
[Test]
|
||||
public void TestDeserialize_NewElement()
|
||||
{
|
||||
var tariffDescription = JsonConvert.DeserializeObject<TariffDescription>(
|
||||
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic"",
|
||||
|
|
17
TestShareeLib/Repository/TestCopriCallsHttps.cs
Normal file
17
TestShareeLib/Repository/TestCopriCallsHttps.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using NUnit.Framework;
|
||||
|
||||
namespace UITest.Fixtures.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCopriCallsHttps
|
||||
{
|
||||
public const string CATEGORY_REQUIRESCOPRI = "RequiresCOPRI";
|
||||
|
||||
public const string CATEGORY_USESLIVESERVER = "RequiresCOPRI.Live";
|
||||
|
||||
public const string CATEGORY_USESDEVELSERVER = "RequiresCOPRI.Devel";
|
||||
|
||||
public const string TESTAGENT = "TestShareeLib";
|
||||
|
||||
}
|
||||
}
|
83
TestShareeLib/Repository/TestCopriCallsMonkeyStore.cs
Normal file
83
TestShareeLib/Repository/TestCopriCallsMonkeyStore.cs
Normal file
|
@ -0,0 +1,83 @@
|
|||
using MonkeyCache.FileStore;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace UITest.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCopriCallsMonkeyStore
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var bikesAvailable = JsonConvert.DeserializeObject<BikesAvailableResponse>(CopriCallsMonkeyStore.BIKESAVAILABLE);
|
||||
Assert.NotNull(bikesAvailable?.bikes);
|
||||
|
||||
var bikesOccupied = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(CopriCallsMonkeyStore.BIKESOCCUPIED);
|
||||
Assert.NotNull(bikesOccupied?.bikes_occupied);
|
||||
|
||||
var stations = JsonConvert.DeserializeObject<StationsAllResponse>(CopriCallsMonkeyStore.STATIONSALL);
|
||||
Assert.NotNull(stations?.stations);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Barrel.ApplicationId))
|
||||
{
|
||||
Barrel.ApplicationId = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var cache = new CopriCallsMonkeyStore("123456789");
|
||||
Assert.AreEqual(0, (await cache.GetStationsAsync()).stations.Count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Barrel.Current.EmptyAll();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesAvailable()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Barrel.ApplicationId))
|
||||
{
|
||||
Barrel.ApplicationId = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var cache = new CopriCallsMonkeyStore("123456789");
|
||||
Assert.AreEqual(0, (await cache.GetBikesAvailableAsync()).bikes.Count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Barrel.Current.EmptyAll();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Barrel.ApplicationId))
|
||||
{
|
||||
Barrel.ApplicationId = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var cache = new CopriCallsMonkeyStore("123456789", "abc");
|
||||
Assert.AreEqual(0, (await cache.GetBikesOccupiedAsync()).bikes_occupied.Count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Barrel.Current.EmptyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
86
TestShareeLib/Repository/TestCopriCallsStatic.cs
Normal file
86
TestShareeLib/Repository/TestCopriCallsStatic.cs
Normal file
|
@ -0,0 +1,86 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using TINK.Repository.Response;
|
||||
using TINK.Repository;
|
||||
|
||||
namespace TestShareeLib.Repository
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCopriCallsStatic
|
||||
{
|
||||
[Test]
|
||||
public void TestDeserializeResponse_Factory_SupportedVersion()
|
||||
{
|
||||
var response = @"
|
||||
{
|
||||
""shareejson"" :
|
||||
{
|
||||
""copri_version"" : ""4.1.5.7""
|
||||
}
|
||||
}";
|
||||
|
||||
Assert.That(
|
||||
response.DeserializeResponse(version => new ResponseBase()).copri_version,
|
||||
Is.EqualTo("4.1.5.7"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeserializeResponse_Factory_UnspportedVersion()
|
||||
{
|
||||
// Future version
|
||||
var response = @"
|
||||
{
|
||||
""shareejson"" :
|
||||
{
|
||||
""copri_version"" : ""4.2.5.7""
|
||||
}
|
||||
}";
|
||||
|
||||
var factoryObject = JsonConvert.DeserializeObject<ResponseContainer<ResponseBase>>(
|
||||
@"{
|
||||
""shareejson"" :
|
||||
{
|
||||
""copri_version"" : ""9.9.9.9""
|
||||
}
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
response.DeserializeResponse(version => factoryObject).shareejson.copri_version,
|
||||
Is.EqualTo("9.9.9.9"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeserializeResponse_Exception_SupportedVersion()
|
||||
{
|
||||
// Future version
|
||||
var response = @"
|
||||
{
|
||||
""shareejson"" :
|
||||
{
|
||||
""copri_version"" : ""4.1.5.7""
|
||||
}
|
||||
}";
|
||||
|
||||
Assert.That(
|
||||
response.DeserializeResponse<ResponseBase>(version => new System.Exception("hello")).copri_version,
|
||||
Is.EqualTo("4.1.5.7"),
|
||||
"No exception must be thrown because version 4.1.x is supported.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeserializeResponse_Exception_UnspportedVersion()
|
||||
{
|
||||
var response = @"
|
||||
{
|
||||
""shareejson"" :
|
||||
{
|
||||
""copri_version"" : ""4.2.5.7""
|
||||
}
|
||||
}";
|
||||
|
||||
Assert.That(
|
||||
() => response.DeserializeResponse<ResponseBase>(version => new System.Exception("Ho")).copri_version,
|
||||
Throws.InstanceOf<System.Exception>());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,17 +27,14 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NSubstitute" Version="4.2.2" />
|
||||
<PackageReference Include="NUnit" Version="3.13.1" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
|
||||
<PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TINKLib\TINKLib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Model\Connector\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -5,7 +5,7 @@ using System.Threading.Tasks;
|
|||
using TINK.Model.Bike.BluetoothLock;
|
||||
using TINK.Model.Bikes.Bike.BluetoothLock;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Repository.Exception;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Services.BluetoothLock;
|
||||
using TINK.Services.BluetoothLock.Exception;
|
||||
using TINK.Services.BluetoothLock.Tdo;
|
||||
|
@ -16,10 +16,10 @@ using TINK.ViewModel;
|
|||
using TINK.ViewModel.Bikes;
|
||||
using TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
|
||||
using TINK.Model.User;
|
||||
using TINK.Model.Repository.Request;
|
||||
using TINK.Model.Repository.Response;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Request;
|
||||
using TINK.Repository.Response;
|
||||
using Newtonsoft.Json;
|
||||
using TINK.Model.Device;
|
||||
|
||||
namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
||||
{
|
||||
|
@ -40,6 +40,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
Substitute.For<IGeolocation>(),
|
||||
Substitute.For<ILocksService>(),
|
||||
() => Substitute.For<IPollingUpdateTaskManager>(),
|
||||
Substitute.For<ISmartDevice>(),
|
||||
Substitute.For<IViewService>(),
|
||||
Substitute.For<IBikesViewModel>(),
|
||||
Substitute.For<IUser>());
|
||||
|
@ -75,6 +76,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -95,7 +97,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, null);
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
|
@ -135,6 +137,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -156,7 +159,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "";
|
||||
viewService.DisplayAlert("Lock can not be opened!", "Lock cannot be opened until bike is near.", "OK");
|
||||
viewService.DisplayAlert("Error while opening lock!", "Lock cannot be opened until bike is near.", "OK");
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
|
@ -194,12 +197,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
locks[0].OpenAsync()
|
||||
.Returns<Task<LockitLockingState?>>(x => throw new CouldntOpenBoldBlockedException());
|
||||
.Returns<Task<LockitLockingState?>>(x => throw new CouldntOpenBoldIsBlockedException());
|
||||
|
||||
bike.State.Value.Returns(InUseStateEnum.Booked);
|
||||
bike.LockInfo.State.Returns(LockingState.Closed);
|
||||
|
@ -215,7 +219,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "";
|
||||
viewService.DisplayAlert("Lock can not be opened!", "Lock is blocked. Please ensure that no obstacle prevents lock from opening and try again.", "OK");
|
||||
viewService.DisplayAlert("Error while opening lock!", "Lock is blocked. Please ensure that no obstacle prevents lock from opening and try again.", "OK");
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
|
@ -253,6 +257,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -274,7 +279,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "";
|
||||
viewService.DisplayAlert("Lock can not be opened!", "After try to open lock state closed is reported.", "OK");
|
||||
viewService.DisplayAlert("Error while opening lock!", "After try to open lock state closed is reported.", "OK");
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
|
@ -312,12 +317,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
locks[0].OpenAsync()
|
||||
.Returns<Task<LockitLockingState?>>(x => throw new CouldntOpenInconsistentStateExecption(LockingState.Unknown));
|
||||
.Returns<Task<LockitLockingState?>>(x => throw new CouldntOpenBoldWasBlockedException());
|
||||
|
||||
bike.State.Value.Returns(InUseStateEnum.Booked);
|
||||
bike.LockInfo.State.Returns(LockingState.Closed);
|
||||
|
@ -333,7 +339,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "";
|
||||
viewService.DisplayAlert("Lock can not be opened!", "Lock reports unknown bold position.", "OK");
|
||||
viewService.DisplayAlert("Lock can not be opened!", "Lock was blocked and might still be. Please ensure that no obstacle prevents lock from opening and try again.", "OK");
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
|
@ -371,6 +377,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -392,7 +399,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "";
|
||||
viewService.DisplayAlert("Lock can not be opened!", "Exception message.", "OK");
|
||||
viewService.DisplayAlert("Error while opening lock!", "Exception message.", "OK");
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
|
@ -406,6 +413,135 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
Assert.IsTrue(subsequent.IsLockitButtonVisible);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use case: Opens lock
|
||||
/// Final state: Booked opened.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestOpenGetBatteryPercentageAsyncThrowsOutOfReachException()
|
||||
{
|
||||
var bike = Substitute.For<IBikeInfoMutable>();
|
||||
var connector = Substitute.For<IConnector>();
|
||||
var command = Substitute.For<ICommand>();
|
||||
var geolocation = Substitute.For<IGeolocation>();
|
||||
var locks = Substitute.For<ILocksService>();
|
||||
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
||||
var activeUser = Substitute.For<IUser>();
|
||||
|
||||
var handler = new BookedUnknown(
|
||||
bike,
|
||||
() => true, // isConnectedDelegate
|
||||
(isConnexted) => connector,
|
||||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
locks[0].OpenAsync()
|
||||
.Returns(Task.FromResult((LockitLockingState?)LockitLockingState.Open)); // Return lock state indicating success
|
||||
|
||||
locks[0].GetBatteryPercentageAsync().Returns<Task<double>>(x => throw new OutOfReachException());
|
||||
|
||||
bike.State.Value.Returns(InUseStateEnum.Booked);
|
||||
|
||||
var subsequent = handler.HandleRequestOption1().Result;
|
||||
|
||||
// Verify behaviour
|
||||
Received.InOrder(() =>
|
||||
{
|
||||
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
||||
bikesViewModel.ActionText = "One moment please...";
|
||||
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
||||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Battery status can only be read when bike is nearby.";
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, null);
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
||||
});
|
||||
|
||||
// Verify state "Booked Closed" after action
|
||||
Assert.AreEqual("Close lock & return bike", subsequent.ButtonText);
|
||||
Assert.IsTrue(subsequent.IsButtonVisible);
|
||||
Assert.AreEqual("Close lock", subsequent.LockitButtonText);
|
||||
Assert.IsTrue(subsequent.IsLockitButtonVisible);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Use case: Opens lock
|
||||
/// Final state: Booked opened.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestOpenGetBatteryPercentageAsyncThrowsExcepton()
|
||||
{
|
||||
var bike = Substitute.For<IBikeInfoMutable>();
|
||||
var connector = Substitute.For<IConnector>();
|
||||
var command = Substitute.For<ICommand>();
|
||||
var geolocation = Substitute.For<IGeolocation>();
|
||||
var locks = Substitute.For<ILocksService>();
|
||||
var pollingManager = Substitute.For<IPollingUpdateTaskManager>();
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var bikesViewModel = Substitute.For<IBikesViewModel>();
|
||||
var activeUser = Substitute.For<IUser>();
|
||||
|
||||
var handler = new BookedUnknown(
|
||||
bike,
|
||||
() => true, // isConnectedDelegate
|
||||
(isConnexted) => connector,
|
||||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
locks[0].OpenAsync()
|
||||
.Returns(Task.FromResult((LockitLockingState?)LockitLockingState.Open)); // Return lock state indicating success
|
||||
|
||||
locks[0].GetBatteryPercentageAsync().Returns<Task<double>>(x => throw new Exception());
|
||||
|
||||
bike.State.Value.Returns(InUseStateEnum.Booked);
|
||||
|
||||
var subsequent = handler.HandleRequestOption1().Result;
|
||||
|
||||
// Verify behaviour
|
||||
Received.InOrder(() =>
|
||||
{
|
||||
bikesViewModel.Received(1).IsIdle = false; // GUI must be locked
|
||||
bikesViewModel.ActionText = "One moment please...";
|
||||
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
|
||||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Battery status cannot be read.";
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, null);
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
bikesViewModel.Received(1).IsIdle = true; // GUI must be unlocked
|
||||
});
|
||||
|
||||
// Verify state "Booked Closed" after action
|
||||
Assert.AreEqual("Close lock & return bike", subsequent.ButtonText);
|
||||
Assert.IsTrue(subsequent.IsButtonVisible);
|
||||
Assert.AreEqual("Close lock", subsequent.LockitButtonText);
|
||||
Assert.IsTrue(subsequent.IsLockitButtonVisible);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use case: Open lock
|
||||
/// Final state: Booked open.
|
||||
|
@ -430,6 +566,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -453,7 +590,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, null);
|
||||
bikesViewModel.ActionText = "No web error on updating locking status.";
|
||||
|
@ -494,6 +631,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -517,7 +655,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, Arg.Any<LocationDto>());
|
||||
bikesViewModel.ActionText = "Connection error on updating locking status.";
|
||||
|
@ -558,6 +696,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -582,7 +721,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, Arg.Any<LocationDto>());
|
||||
bikesViewModel.ActionText = "Status error on updating lock state.";
|
||||
|
@ -623,6 +762,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -681,6 +821,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -740,6 +881,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -799,6 +941,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -860,6 +1003,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -921,6 +1065,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
|
|
@ -6,8 +6,8 @@ using System.Threading.Tasks;
|
|||
using TINK.Model.Bike.BluetoothLock;
|
||||
using TINK.Model.Bikes.Bike.BluetoothLock;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Repository.Exception;
|
||||
using TINK.Model.Repository.Response;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Response;
|
||||
using TINK.Services.BluetoothLock;
|
||||
using TINK.Services.BluetoothLock.Exception;
|
||||
using TINK.Services.BluetoothLock.Tdo;
|
||||
|
@ -18,8 +18,8 @@ using TINK.ViewModel;
|
|||
using TINK.ViewModel.Bikes;
|
||||
using TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
|
||||
using TINK.Model.User;
|
||||
using TINK.Model.Repository.Request;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Request;
|
||||
using TINK.Model.Device;
|
||||
|
||||
namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
||||
{
|
||||
|
@ -39,6 +39,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
Substitute.For<IGeolocation>(),
|
||||
Substitute.For<ILocksService>(),
|
||||
() => Substitute.For<IPollingUpdateTaskManager>(),
|
||||
Substitute.For<ISmartDevice>(),
|
||||
Substitute.For<IViewService>(),
|
||||
Substitute.For<IBikesViewModel>(),
|
||||
Substitute.For<IUser>());
|
||||
|
@ -75,10 +76,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Cancel reservation for bike {0}?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(false));
|
||||
|
||||
var subsequent = handler.HandleRequestOption1().Result;
|
||||
|
@ -124,10 +128,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Cancel reservation for bike {0}?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
bike.State.Value.Returns(InUseStateEnum.Disposable); // Reqesthandler factory queries state to create appropriate request handler object.
|
||||
bike.LockInfo.State.Returns(LockingState.Disconnected); // Requsthandler factory queries lock state to create appropriate request handler object.
|
||||
|
@ -182,17 +189,20 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Cancel reservation for bike {0}?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
var response = JsonConvert.DeserializeObject<AuthorizationResponse>(@"
|
||||
{
|
||||
""response"" : ""authorization"",
|
||||
""authcookie"" : ""4da3044c8657a04ba60e2eaa753bc51a"",
|
||||
""user_group"" : ""TINK,Konrad"",
|
||||
""user_group"" : [ ""TINK"", ""Konrad"" ],
|
||||
""response_state"" : ""OK"",
|
||||
""apiserver"" : ""https://tinkwwp.copri-bike.de""
|
||||
}");
|
||||
|
@ -253,10 +263,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Cancel reservation for bike {0}?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
connector.Command.DoCancelReservation(bike).Returns(x => throw new WebConnectFailureException("Context info.", new Exception("chub")));
|
||||
|
@ -315,10 +328,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Cancel reservation for bike {0}?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
connector.Command.DoCancelReservation(bike).Returns(x => throw new Exception("Exception message."));
|
||||
|
@ -377,6 +393,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -424,10 +441,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Rent bike {0} and open lock?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
locks[0].OpenAsync()
|
||||
|
@ -448,7 +468,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be opened
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, null);
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
|
@ -489,10 +509,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Rent bike {0} and open lock?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
bike.LockInfo.State.Returns(LockingState.Closed); // Locking state does not change.
|
||||
|
@ -554,10 +577,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Rent bike {0} and open lock?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
bike.LockInfo.State.Returns(LockingState.Closed); // Locking state does not change.
|
||||
|
@ -619,10 +645,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Rent bike {0} and open lock?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
locks[0].OpenAsync()
|
||||
|
@ -644,7 +673,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be opened
|
||||
bikesViewModel.ActionText = "";
|
||||
viewService.DisplayAlert("Lock can not be opened!", "Lock cannot be opened until bike is near.", "OK");
|
||||
viewService.DisplayAlert("Error while opening lock!", "Lock cannot be opened until bike is near.", "OK");
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
|
@ -683,16 +712,19 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Rent bike {0} and open lock?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
locks[0].OpenAsync()
|
||||
.Returns<Task<LockitLockingState?>>(x => throw new Exception("Exception message.")); // Return lock state indicating success
|
||||
|
||||
bike.State.Value.Returns(TINK.Model.State.InUseStateEnum.Reserved); // Booking call leads to setting of state to booked.
|
||||
bike.State.Value.Returns(InUseStateEnum.Reserved); // Booking call leads to setting of state to booked.
|
||||
bike.LockInfo.State.Returns(LockingState.Unknown);
|
||||
|
||||
var subsequent = handler.HandleRequestOption2().Result;
|
||||
|
@ -708,7 +740,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be opened
|
||||
bikesViewModel.ActionText = "";
|
||||
viewService.DisplayAlert("Lock can not be opened!", "Exception message.", "OK");
|
||||
viewService.DisplayAlert("Error while opening lock!", "Exception message.", "OK");
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
|
@ -747,10 +779,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Rent bike {0} and open lock?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
locks[0].OpenAsync()
|
||||
|
@ -808,10 +843,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Rent bike {0} and open lock?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
locks[0].OpenAsync()
|
||||
|
@ -834,7 +872,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be opened
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Battery status can only be read when bike is nearby.";
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, null);
|
||||
|
@ -876,10 +914,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Rent bike {0} and open lock?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
locks[0].OpenAsync()
|
||||
|
@ -902,7 +943,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be opened
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Battery status cannot be read.";
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, null);
|
||||
|
@ -944,10 +985,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Rent bike {0} and open lock?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
locks[0].OpenAsync()
|
||||
|
@ -970,7 +1014,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be opened
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, null);
|
||||
bikesViewModel.ActionText = "No web error on updating locking status.";
|
||||
|
@ -1012,10 +1056,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Rent bike {0} and open lock?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
locks[0].OpenAsync()
|
||||
|
@ -1038,7 +1085,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be opened
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, Arg.Any<LocationDto>());
|
||||
bikesViewModel.ActionText = "Connection error on updating locking status.";
|
||||
|
@ -1080,10 +1127,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
bike.Id.Returns("0");
|
||||
|
||||
viewService.DisplayAlert(string.Empty, string.Format("Rent bike {0} and open lock?", "Nr. 0"), "Yes", "No").Returns(Task.FromResult(true));
|
||||
|
||||
locks[0].OpenAsync()
|
||||
|
@ -1107,7 +1157,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be opened
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, Arg.Any<LocationDto>());
|
||||
bikesViewModel.ActionText = "Status error on updating lock state.";
|
||||
|
|
|
@ -5,7 +5,7 @@ using System.Threading.Tasks;
|
|||
using TINK.Model.Bike.BluetoothLock;
|
||||
using TINK.Model.Bikes.Bike.BluetoothLock;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Repository.Exception;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Services.BluetoothLock;
|
||||
using TINK.Services.BluetoothLock.Exception;
|
||||
using TINK.Services.BluetoothLock.Tdo;
|
||||
|
@ -16,10 +16,10 @@ using TINK.ViewModel;
|
|||
using TINK.ViewModel.Bikes;
|
||||
using TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
|
||||
using TINK.Model.User;
|
||||
using TINK.Model.Repository.Request;
|
||||
using TINK.Model.Repository.Response;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Request;
|
||||
using TINK.Repository.Response;
|
||||
using Newtonsoft.Json;
|
||||
using TINK.Model.Device;
|
||||
|
||||
namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
||||
{
|
||||
|
@ -42,6 +42,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
Substitute.For<IGeolocation>(),
|
||||
Substitute.For<ILocksService>(),
|
||||
() => Substitute.For<IPollingUpdateTaskManager>(),
|
||||
Substitute.For<ISmartDevice>(),
|
||||
Substitute.For<IViewService>(),
|
||||
Substitute.For<IBikesViewModel>(),
|
||||
Substitute.For<IUser>());
|
||||
|
@ -77,6 +78,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -97,7 +99,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, null);
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
|
@ -137,6 +139,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -158,7 +161,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "";
|
||||
viewService.DisplayAlert("Lock can not be opened!", "Lock cannot be opened until bike is near.", "OK");
|
||||
viewService.DisplayAlert("Error while opening lock!", "Lock cannot be opened until bike is near.", "OK");
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
|
@ -196,12 +199,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
locks[0].OpenAsync()
|
||||
.Returns<Task<LockitLockingState?>>(x => throw new CouldntOpenBoldBlockedException());
|
||||
.Returns<Task<LockitLockingState?>>(x => throw new CouldntOpenBoldIsBlockedException());
|
||||
|
||||
bike.State.Value.Returns(InUseStateEnum.Booked);
|
||||
bike.LockInfo.State.Returns(LockingState.Closed);
|
||||
|
@ -217,7 +221,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "";
|
||||
viewService.DisplayAlert("Lock can not be opened!", "Lock is blocked. Please ensure that no obstacle prevents lock from opening and try again.", "OK");
|
||||
viewService.DisplayAlert("Error while opening lock!", "Lock is blocked. Please ensure that no obstacle prevents lock from opening and try again.", "OK");
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
|
@ -255,6 +259,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -276,7 +281,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "";
|
||||
viewService.DisplayAlert("Lock can not be opened!", "After try to open lock state closed is reported.", "OK");
|
||||
viewService.DisplayAlert("Error while opening lock!", "After try to open lock state closed is reported.", "OK");
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
|
@ -314,12 +319,13 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
||||
locks[0].OpenAsync()
|
||||
.Returns<Task<LockitLockingState?>>(x => throw new CouldntOpenInconsistentStateExecption(LockingState.Unknown));
|
||||
.Returns<Task<LockitLockingState?>>(x => throw new CouldntOpenBoldWasBlockedException());
|
||||
|
||||
bike.State.Value.Returns(InUseStateEnum.Booked);
|
||||
bike.LockInfo.State.Returns(LockingState.Closed);
|
||||
|
@ -335,7 +341,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "";
|
||||
viewService.DisplayAlert("Lock can not be opened!", "Lock reports unknown bold position.", "OK");
|
||||
viewService.DisplayAlert("Lock can not be opened!", "Lock was blocked and might still be. Please ensure that no obstacle prevents lock from opening and try again.", "OK");
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
|
@ -373,6 +379,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -394,7 +401,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "";
|
||||
viewService.DisplayAlert("Lock can not be opened!", "Exception message.", "OK");
|
||||
viewService.DisplayAlert("Error while opening lock!", "Exception message.", "OK");
|
||||
bikesViewModel.ActionText = "Updating...";
|
||||
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
|
||||
bikesViewModel.ActionText = "";
|
||||
|
@ -432,6 +439,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -455,7 +463,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, null);
|
||||
bikesViewModel.ActionText = "No web error on updating locking status.";
|
||||
|
@ -496,6 +504,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -519,7 +528,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, Arg.Any<LocationDto>());
|
||||
bikesViewModel.ActionText = "Connection error on updating locking status.";
|
||||
|
@ -560,6 +569,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -584,7 +594,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
bikesViewModel.ActionText = "Opening lock...";
|
||||
locks.Received()[0].OpenAsync(); // Lock must be closed
|
||||
bikesViewModel.ActionText = "Reading charging level...";
|
||||
locks[bike.Id].GetBatteryPercentageAsync();
|
||||
locks[0].GetBatteryPercentageAsync();
|
||||
bikesViewModel.ActionText = "Updating lock state...";
|
||||
connector.Command.UpdateLockingStateAsync(bike, Arg.Any<LocationDto>());
|
||||
bikesViewModel.ActionText = "Status error on updating lock state.";
|
||||
|
@ -625,6 +635,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -679,6 +690,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -738,6 +750,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -798,6 +811,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -859,6 +873,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
@ -920,6 +935,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
geolocation,
|
||||
locks,
|
||||
() => pollingManager,
|
||||
Substitute.For<ISmartDevice>(),
|
||||
viewService,
|
||||
bikesViewModel,
|
||||
activeUser);
|
||||
|
|
95
TestShareeLib/ViewModel/TestViewModelHelper.cs
Normal file
95
TestShareeLib/ViewModel/TestViewModelHelper.cs
Normal file
|
@ -0,0 +1,95 @@
|
|||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.Bikes.Bike.BC;
|
||||
using TINK.ViewModel;
|
||||
|
||||
namespace TestShareeLib.ViewModel
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestViewModelHelper
|
||||
{
|
||||
[Test]
|
||||
public void TestGetFullDisplayName()
|
||||
{
|
||||
var bike = Substitute.For<IBikeInfoMutable>();
|
||||
bike.Description.Returns("MyStation");
|
||||
bike.Id.Returns("MyId");
|
||||
|
||||
Assert.That(
|
||||
bike.GetFullDisplayName(),
|
||||
Is.EqualTo("MyStation, Nr. MyId"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetFullDisplayNameIdEmpty()
|
||||
{
|
||||
var bike = Substitute.For<IBikeInfoMutable>();
|
||||
bike.Description.Returns("MyStation");
|
||||
bike.Id.Returns("");
|
||||
|
||||
Assert.That(
|
||||
bike.GetFullDisplayName(),
|
||||
Is.EqualTo("MyStation, Nr. "));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetFullDisplayNameEmpty()
|
||||
{
|
||||
var bike = Substitute.For<IBikeInfoMutable>();
|
||||
bike.Description.Returns("");
|
||||
bike.Id.Returns("Id33");
|
||||
|
||||
Assert.That(
|
||||
bike.GetDisplayName(),
|
||||
Is.EqualTo("Id33"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetDisplayName()
|
||||
{
|
||||
var bike = Substitute.For<IBikeInfoMutable>();
|
||||
bike.Description.Returns("MyStation");
|
||||
bike.Id.Returns("Id33");
|
||||
|
||||
Assert.That(
|
||||
bike.GetDisplayName(),
|
||||
Is.EqualTo("MyStation"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetDisplayNameEmpty()
|
||||
{
|
||||
var bike = Substitute.For<IBikeInfoMutable>();
|
||||
bike.Description.Returns("");
|
||||
bike.Id.Returns("Id33");
|
||||
|
||||
Assert.That(
|
||||
bike.GetDisplayName(),
|
||||
Is.EqualTo("Id33"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetDisplayId()
|
||||
{
|
||||
var bike = Substitute.For<IBikeInfoMutable>();
|
||||
bike.Description.Returns("ValidName");
|
||||
bike.Id.Returns("Id33");
|
||||
|
||||
Assert.That(
|
||||
bike.GetDisplayId(),
|
||||
Is.EqualTo("Id33"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetDisplayIdNameEmpty()
|
||||
{
|
||||
var bike = Substitute.For<IBikeInfoMutable>();
|
||||
bike.Description.Returns("");
|
||||
bike.Id.Returns("Id33");
|
||||
|
||||
Assert.That(
|
||||
bike.GetDisplayId(),
|
||||
Is.EqualTo(""));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue