Version 3.0.356

This commit is contained in:
Oliver Hauff 2022-12-27 21:08:09 +01:00
parent d23aff6daf
commit 5980410182
48 changed files with 242 additions and 362 deletions

View file

@ -0,0 +1,36 @@
using System;
using NUnit.Framework;
using TINK.Model.Connector;
using TINK.Repository.Request;
namespace TestShareeLib.Repository.Request
{
[TestFixture]
public class TestRequestBuilderHelper
{
[Test]
public void TestGetLockStateNull()
=> Assert.That(
RequestBuilderHelper.GetLockState(null),
Is.Null);
[Test]
public void TestGetLockState([Values] LockingAction action)
{
switch (action)
{
case LockingAction.Open:
case LockingAction.Close:
break;
default:
throw new ArgumentException("Tests need possibly exended.");
}
Assert.That(
RequestBuilderHelper.GetLockState(action),
Is.EqualTo(action == LockingAction.Open ? lock_state.unlocking : lock_state.locking));
}
}
}

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Net;
using NUnit.Framework;
using TINK.Model.Connector;
using TINK.Repository.Exception;
using TINK.Repository.Request;
@ -117,18 +118,35 @@ namespace TestShareeLib.Repository.Request
public void TestDoBook()
{
Assert.AreEqual(
"request=booking_update&bike=42&authcookie=456123&Ilockit_GUID=0000f00d-1212-efde-1523-785fef13d123&state=occupied&lock_state=unlocked&voltage=33.21",
new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"), 33.21));
"request=booking_update&bike=42&authcookie=456123&Ilockit_GUID=0000f00d-1212-efde-1523-785fef13d123&state=occupied&lock_state=unlocking&voltage=33.21",
new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"), 33.21, LockingAction.Open));
}
[Test]
public void TestDoBookNoBatery()
{
Assert.AreEqual(
"request=booking_update&bike=42&authcookie=456123&Ilockit_GUID=0000f00d-1212-efde-1523-785fef13d123&state=occupied&lock_state=unlocked",
"request=booking_update&bike=42&authcookie=456123&Ilockit_GUID=0000f00d-1212-efde-1523-785fef13d123&state=occupied",
new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"), double.NaN));
}
[Test]
public void TestDoBookActionNone()
{
Assert.AreEqual(
"request=booking_update&bike=42&authcookie=456123&Ilockit_GUID=0000f00d-1212-efde-1523-785fef13d123&state=occupied",
new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"), double.NaN));
}
/// <summary> Hypothetical scenario.</summary>
[Test]
public void TestDoBookActionClose()
{
Assert.AreEqual(
"request=booking_update&bike=42&authcookie=456123&Ilockit_GUID=0000f00d-1212-efde-1523-785fef13d123&state=occupied&lock_state=locking",
new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"), double.NaN, LockingAction.Close));
}
[Test]
public void TestBookAndStartOpening()
=> Assert.That(

View file

@ -157,7 +157,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.Re
locks.ConnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>());
bikesViewModel.ActionText = "";
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike); // Booking must be performed
connector.Command.DoBookAsync(bike, LockingAction.Open); // Booking must be performed
bikesViewModel.ActionText = "<h4><b>Lock is opening.<br/>Please wait until it is completely open.</b></h4>";
locks.Received()[0].OpenAsync(); // Lock must be opened
bikesViewModel.ActionText = "Reading charging level...";

View file

@ -281,7 +281,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.Re
bikesViewModel.ActionText = "Reading charging level...";
locks[0].GetBatteryPercentageAsync();
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike);
connector.Command.DoBookAsync(bike);
bikesViewModel.ActionText = "Updating...";
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
bikesViewModel.ActionText = "";
@ -328,7 +328,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.Re
viewService.DisplayAlert(string.Empty, "Fahrrad Nr. 0 mieten oder Schloss schließen?", "Mieten", "Schloss schließen").Returns(Task.FromResult(true));
connector.Command.DoBook(bike).Returns(x => throw new WebConnectFailureException("Context info.", new Exception("chub")));
connector.Command.DoBookAsync(bike).Returns(x => throw new WebConnectFailureException("Context info.", new Exception("chub")));
locks[0].CloseAsync().Returns(Task.FromResult((LockitLockingState?)LockitLockingState.Closed));
@ -345,7 +345,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.Re
bikesViewModel.ActionText = "Reading charging level...";
locks[0].GetBatteryPercentageAsync();
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike);
connector.Command.DoBookAsync(bike);
bikesViewModel.ActionText = "";
viewService.DisplayAlert(
"Connection error when renting the bike!",
@ -401,7 +401,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.Re
viewService.DisplayAlert(string.Empty, "Fahrrad Nr. 0 mieten oder Schloss schließen?", "Mieten", "Schloss schließen").Returns(Task.FromResult(true));
connector.Command.DoBook(bike).Returns(x => throw new Exception("Exception message."));
connector.Command.DoBookAsync(bike).Returns(x => throw new Exception("Exception message."));
locks[0].CloseAsync().Returns(Task.FromResult((LockitLockingState?)LockitLockingState.Closed));
@ -418,7 +418,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.Re
bikesViewModel.ActionText = "Reading charging level...";
locks[0].GetBatteryPercentageAsync();
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike);
connector.Command.DoBookAsync(bike);
bikesViewModel.ActionText = "";
viewService.DisplayAlert("Error when renting the bike!", "Attention: Lock is closed!\r\nException message.", "OK");
bikesViewModel.ActionText = "Verschließe Schloss...";

View file

@ -472,7 +472,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike); // Booking must be performed
connector.Command.DoBookAsync(bike, LockingAction.Open); // Booking must be performed
bikesViewModel.ActionText = "<h4><b>Lock is opening.<br/>Please wait until it is completely open.</b></h4>";
locks.Received()[0].OpenAsync(); // Lock must be opened
bikesViewModel.ActionText = "Reading charging level...";
@ -528,7 +528,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
bike.LockInfo.State.Returns(LockingState.Closed); // Locking state does not change.
connector.Command.DoBook(bike).Returns(x => throw new WebConnectFailureException("Context info", new Exception("Tst")));
connector.Command.DoBookAsync(bike, LockingAction.Open).Returns(x => throw new WebConnectFailureException("Context info", new Exception("Tst")));
bike.State.Value.Returns(InUseStateEnum.Reserved); // State remains reserved because booking request failed.
@ -541,7 +541,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike); // Booking must be performed
connector.Command.DoBookAsync(bike, LockingAction.Open); // Booking must be performed
bikesViewModel.ActionText = "";
viewService.DisplayAdvancedAlert(
"Connection error when renting the bike!",
@ -597,7 +597,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
bike.LockInfo.State.Returns(LockingState.Closed); // Locking state does not change.
connector.Command.DoBook(bike).Returns(x => throw new Exception("Exception message."));
connector.Command.DoBookAsync(bike, LockingAction.Open).Returns(x => throw new Exception("Exception message."));
bike.State.Value.Returns(InUseStateEnum.Reserved); // When booking fails state remains reserved.
@ -610,7 +610,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike); // Booking must be performed
connector.Command.DoBookAsync(bike, LockingAction.Open); // Booking must be performed
bikesViewModel.ActionText = "";
viewService.DisplayAdvancedAlert(
"Error when renting the bike!",
@ -679,7 +679,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike); // Booking must be performed
connector.Command.DoBookAsync(bike, LockingAction.Open); // Booking must be performed
bikesViewModel.ActionText = "<h4><b>Lock is opening.<br/>Please wait until it is completely open.</b></h4>";
locks.Received()[0].OpenAsync(); // Lock must be opened
bikesViewModel.ActionText = "";
@ -746,7 +746,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike); // Booking must be performed
connector.Command.DoBookAsync(bike, LockingAction.Open); // Booking must be performed
bikesViewModel.ActionText = "<h4><b>Lock is opening.<br/>Please wait until it is completely open.</b></h4>";
locks.Received()[0].OpenAsync(); // Lock must be opened
bikesViewModel.ActionText = "";
@ -812,7 +812,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike); // Booking must be performed
connector.Command.DoBookAsync(bike, LockingAction.Open); // Booking must be performed
bikesViewModel.ActionText = "<h4><b>Lock is opening.<br/>Please wait until it is completely open.</b></h4>";
locks.Received()[0].OpenAsync(); // Lock must be opened
bikesViewModel.ActionText = "Updating...";
@ -878,7 +878,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike); // Booking must be performed
connector.Command.DoBookAsync(bike, LockingAction.Open); // Booking must be performed
bikesViewModel.ActionText = "<h4><b>Lock is opening.<br/>Please wait until it is completely open.</b></h4>";
locks.Received()[0].OpenAsync(); // Lock must be opened
bikesViewModel.ActionText = "Reading charging level...";
@ -949,7 +949,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike); // Booking must be performed
connector.Command.DoBookAsync(bike, LockingAction.Open); // Booking must be performed
bikesViewModel.ActionText = "<h4><b>Lock is opening.<br/>Please wait until it is completely open.</b></h4>";
locks.Received()[0].OpenAsync(); // Lock must be opened
bikesViewModel.ActionText = "Reading charging level...";
@ -1020,7 +1020,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike); // Booking must be performed
connector.Command.DoBookAsync(bike, LockingAction.Open); // Booking must be performed
bikesViewModel.ActionText = "<h4><b>Lock is opening.<br/>Please wait until it is completely open.</b></h4>";
locks.Received()[0].OpenAsync(); // Lock must be opened
bikesViewModel.ActionText = "Reading charging level...";
@ -1091,7 +1091,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike); // Booking must be performed
connector.Command.DoBookAsync(bike, LockingAction.Open); // Booking must be performed
bikesViewModel.ActionText = "<h4><b>Lock is opening.<br/>Please wait until it is completely open.</b></h4>";
locks.Received()[0].OpenAsync(); // Lock must be opened
bikesViewModel.ActionText = "Reading charging level...";
@ -1163,7 +1163,7 @@ namespace TestShareeLib.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
bikesViewModel.ActionText = "One moment please...";
pollingManager.StopUpdatePeridically(); // Polling must be stopped before any COPR and lock service action
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike); // Booking must be performed
connector.Command.DoBookAsync(bike, LockingAction.Open); // Booking must be performed
bikesViewModel.ActionText = "<h4><b>Lock is opening.<br/>Please wait until it is completely open.</b></h4>";
locks.Received()[0].OpenAsync(); // Lock must be opened
bikesViewModel.ActionText = "Reading charging level...";

View file

@ -422,7 +422,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.Re
locks.ConnectAsync(Arg.Any<LockInfoAuthTdo>(), Arg.Any<TimeSpan>());
bikesViewModel.ActionText = "";
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike); // Booking must be performed
connector.Command.DoBookAsync(bike, LockingAction.Open); // Booking must be performed
bikesViewModel.ActionText = "<h4><b>Lock is opening.<br/>Please wait until it is completely open.</b></h4>";
locks.Received()[0].OpenAsync(); // Lock must be opened
bikesViewModel.ActionText = "Reading charging level...";

View file

@ -94,7 +94,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.Re
bikesViewModel.ActionText = "Reading charging level...";
locks[0].GetBatteryPercentageAsync();
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike);
connector.Command.DoBookAsync(bike);
bikesViewModel.ActionText = "Updating...";
pollingManager.StartUpdateAyncPeridically(); // polling must be restarted again
bikesViewModel.ActionText = "";
@ -139,7 +139,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.Re
viewService.DisplayAlert(string.Empty, "Rad Nr. 0 abschließen und zurückgeben oder Rad mieten?", "Zurückgeben", "Mieten").Returns(Task.FromResult(false));
connector.Command.DoBook(bike).Returns(x => throw new WebConnectFailureException("Context info.", new Exception("Tst")));
connector.Command.DoBookAsync(bike).Returns(x => throw new WebConnectFailureException("Context info.", new Exception("Tst")));
locks[0].CloseAsync().Returns(LockitLockingState.Closed);
@ -156,7 +156,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.Re
bikesViewModel.ActionText = "Reading charging level...";
locks[0].GetBatteryPercentageAsync();
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike);
connector.Command.DoBookAsync(bike);
bikesViewModel.ActionText = "";
viewService.DisplayAlert(
"Connection error when renting the bike!",
@ -208,7 +208,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.Re
viewService.DisplayAlert(string.Empty, "Rad Nr. 0 abschließen und zurückgeben oder Rad mieten?", "Zurückgeben", "Mieten").Returns(Task.FromResult(false));
connector.Command.DoBook(bike).Returns(x => throw new Exception("Exception message."));
connector.Command.DoBookAsync(bike).Returns(x => throw new Exception("Exception message."));
locks[0].CloseAsync().Returns(LockitLockingState.Closed);
@ -225,7 +225,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Bikes.Bike.BluetoothLock.Re
bikesViewModel.ActionText = "Reading charging level...";
locks[0].GetBatteryPercentageAsync();
bikesViewModel.ActionText = "Renting bike...";
connector.Command.DoBook(bike);
connector.Command.DoBookAsync(bike);
bikesViewModel.ActionText = "";
viewService.DisplayAlert("Error when renting the bike!", "Attention: Lock is closed!\r\nException message.", "OK");
bikesViewModel.ActionText = "Wiederverschließe Schloss...";