mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-06 02:56:32 +01:00
691 lines
26 KiB
C#
691 lines
26 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Threading;
|
|
using NUnit.Framework;
|
|
using TINK.Model;
|
|
using TINK.Model.Services.CopriApi.ServerUris;
|
|
using TINK.Repository;
|
|
using TINK.Repository.Exception;
|
|
using TINK.Repository.Request;
|
|
using TINK.Repository.Response;
|
|
using static TINK.Repository.CopriCallsHttps;
|
|
|
|
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";
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
Thread.Sleep(2000); // Sleep, otherwise copri will block requested calls.
|
|
}
|
|
|
|
[Test]
|
|
public void TestIsConnected()
|
|
{
|
|
Assert.IsTrue(new CopriCallsHttps(new Uri("http://127.0.0.0/api"), new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)), "123").IsConnected);
|
|
}
|
|
|
|
[Test]
|
|
#if !NOLIVESERVER
|
|
[Category(CATEGORY_USESLIVESERVER)]
|
|
#elif !NODEVELSERVER
|
|
[Category(CATEGORY_USESDEVELSERVER)]
|
|
#endif
|
|
public void TestLogin(
|
|
#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
|
|
{
|
|
Func<string, string> command = (password) => new RequestBuilder(TinkApp.MerchantId, null /*UI language */).DoAuthorization(
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
|
password,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
|
|
|
var l_oSessionCookieJM_Dev1 = DoAuthorizationAsync(
|
|
url,
|
|
command(TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd),
|
|
() => command("*******"),
|
|
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogin)}").Result;
|
|
|
|
Assert.AreEqual(
|
|
string.Format("{0}{1}", "6103_4da3044c8657a04ba60e2eaa753bc51a_", "oiF2kahH"),
|
|
l_oSessionCookieJM_Dev1.authcookie,
|
|
"Session cookie must never change if user and hardware id does not change.");
|
|
}
|
|
|
|
[Test]
|
|
#if !NOLIVESERVER
|
|
[Category(CATEGORY_USESLIVESERVER)]
|
|
#elif !NODEVELSERVER
|
|
[Category(CATEGORY_USESDEVELSERVER)]
|
|
#endif
|
|
public void TestLogin_UserUnknown(
|
|
#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
|
|
{
|
|
Func<string, string> command = (password) => new RequestBuilder(TinkApp.MerchantId, null /*UI language */).DoAuthorization(
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerGibtsNet.Mail,
|
|
password,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerGibtsNet.DeviceId);
|
|
|
|
var l_oSessionCookieJM_Dev1 = DoAuthorizationAsync(
|
|
url,
|
|
command(TestTINKLib.LoginSessionCopriInfo.JavaministerGibtsNet.Pwd),
|
|
() => command("***********"),
|
|
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogin_UserUnknown)}").Result;
|
|
|
|
Assert.That(
|
|
l_oSessionCookieJM_Dev1,
|
|
Is.Not.Null);
|
|
|
|
// From COPRI 4.1 cookie is empty, was null before
|
|
Assert.IsEmpty(l_oSessionCookieJM_Dev1.authcookie);
|
|
|
|
Assert.AreEqual(
|
|
"authorization",
|
|
l_oSessionCookieJM_Dev1.response);
|
|
|
|
Assert.AreEqual(
|
|
"Failure: cannot generate authcookie",
|
|
l_oSessionCookieJM_Dev1.response_state);
|
|
}
|
|
|
|
/// <summary> Log out functionality is only for test purposes. </summary>
|
|
[Test]
|
|
#if !NOLIVESERVER
|
|
[Category(CATEGORY_USESLIVESERVER)]
|
|
#elif !NODEVELSERVER
|
|
[Category(CATEGORY_USESDEVELSERVER)]
|
|
#endif
|
|
public void TestLogout(
|
|
#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
|
|
{
|
|
// Prerequisite: Login must be performed before logging out.
|
|
var l_oSessionCookie = CopriCallsHttpsReference.DoAuthorizeCall(
|
|
url,
|
|
TinkApp.MerchantId,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
|
|
|
Assert.IsFalse(
|
|
string.IsNullOrEmpty(l_oSessionCookie?.authcookie),
|
|
"Prerequisites not matched: User must be logged on before beeing able to log out.");
|
|
|
|
// Verify logout
|
|
try
|
|
{
|
|
Assert.NotNull(DoAuthoutAsync(
|
|
url,
|
|
new RequestBuilderLoggedIn(
|
|
TinkApp.MerchantId,
|
|
null /*UI language */,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).DoAuthout(),
|
|
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogout)}"
|
|
).Result.GetIsResponseOk());
|
|
}
|
|
finally
|
|
{
|
|
// Log in again to ensure that tests do not change state of database (assumtion: user is always logged in).
|
|
CopriCallsHttpsReference.DoAuthorizeCall(
|
|
url,
|
|
TinkApp.MerchantId,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Log out functionality is only for test purposes.
|
|
/// </summary>
|
|
[Test]
|
|
#if !NOLIVESERVER
|
|
[Category(CATEGORY_USESLIVESERVER)]
|
|
#elif !NODEVELSERVER
|
|
[Category(CATEGORY_USESDEVELSERVER)]
|
|
#endif
|
|
public void TestLogout_NotLoggedIn(
|
|
#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
|
|
{
|
|
// Prerequisite:
|
|
// Ensure that user is really logged out and get valid session cookie before verifying logout behavior.
|
|
var l_oLoginResponse = CopriCallsHttpsReference.DoAuthorizeCall(
|
|
url,
|
|
TinkApp.MerchantId,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
|
|
|
Assert.IsFalse(
|
|
string.IsNullOrEmpty(l_oLoginResponse?.authcookie),
|
|
"Prerequisites not matched: User must be logged out before beeing able to log out.");
|
|
|
|
CopriCallsHttpsReference.DoAuthoutCall(url, TinkApp.MerchantId, l_oLoginResponse.authcookie);
|
|
|
|
try
|
|
{
|
|
// Verify logout
|
|
Assert.Throws<AuthcookieNotDefinedException>(
|
|
() => DoAuthoutAsync(
|
|
url,
|
|
new RequestBuilderLoggedIn(TinkApp.MerchantId, null /*UI language */, l_oLoginResponse.authcookie).DoAuthout(),
|
|
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogout_NotLoggedIn)}").Result.GetIsResponseOk());
|
|
}
|
|
finally
|
|
{
|
|
// Log in again. Otherwise subsequent tests might fail.
|
|
l_oLoginResponse = CopriCallsHttpsReference.DoAuthorizeCall(
|
|
new CopriServerUriList().ActiveUri.AbsoluteUri,
|
|
TinkApp.MerchantId,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Log out is performed by app programmatically if authcookie is no more valid.
|
|
/// Must work even if authcookie is no more valid, otherwise login would not be avalable.
|
|
/// </summary>
|
|
[Test]
|
|
#if !NOLIVESERVER
|
|
[Category(CATEGORY_USESLIVESERVER)]
|
|
#elif !NODEVELSERVER
|
|
[Category(CATEGORY_USESDEVELSERVER)]
|
|
#endif
|
|
public void TestLogout_AuthcookieUnknown(
|
|
#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
|
|
{
|
|
// Prerequisite: Login must be formormed before logging out.
|
|
var l_oSessionCookie = CopriCallsHttpsReference.DoAuthorizeCall(
|
|
url,
|
|
TinkApp.MerchantId,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
|
|
|
Assert.IsFalse(
|
|
string.IsNullOrEmpty(l_oSessionCookie?.authcookie),
|
|
"Prerequisites not matched: User must be logged on before beeing able to log out.");
|
|
|
|
// Verify logout that expected excepton is thrown.
|
|
try
|
|
{
|
|
Assert.AreEqual(
|
|
"Failure 1001: authcookie not defined", // Up to 2020-12-05 COPRI returned: "Failure 1004: authcookie not defined"
|
|
DoAuthoutAsync(
|
|
url,
|
|
new RequestBuilderLoggedIn(
|
|
TinkApp.MerchantId,
|
|
null /*UI language */,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerKeksGibtsNet.AuthCookie).DoAuthout(),
|
|
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogout_AuthcookieUnknown)}"
|
|
).Result.response_state);
|
|
}
|
|
finally
|
|
{
|
|
// Log in again to ensure that tests do not change state of database (assumtion: user is always logged in).
|
|
CopriCallsHttpsReference.DoAuthorizeCall(
|
|
url,
|
|
TinkApp.MerchantId,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
|
}
|
|
}
|
|
|
|
/// <remarks>
|
|
/// From COPRI version v4.1 switched from TINK devel CopriServerUriList.TINK_DEVEL and CopriServerUriList.TINK_LIVE to CopriServerUriList.SHAREE_DEVEL.
|
|
/// </remarks>
|
|
[Test]
|
|
#if !NOLIVESERVER
|
|
[Category(CATEGORY_USESLIVESERVER)]
|
|
#elif !NODEVELSERVER
|
|
[Category(CATEGORY_USESDEVELSERVER)]
|
|
#endif
|
|
public void TestGetBikesAvailalbleCall_LoggedId(
|
|
#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
|
|
{
|
|
// Check prerequisites: At least one bike must be available.
|
|
var bikesReference = CopriCallsHttpsReference.GetBikesAvailableCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes;
|
|
Assert.NotNull(bikesReference);
|
|
var bikeReference = bikesReference.FirstOrDefault().Value;
|
|
Assert.That(
|
|
bikeReference,
|
|
Is.Not.Null,
|
|
$"Prerequisites are not matched: No bikes available from server {url} returned but at least one bike for verification required.");
|
|
|
|
// Verify list of bikes returned from first device
|
|
var request = new RequestBuilderLoggedIn(
|
|
TinkApp.MerchantId,
|
|
null /*UI language */,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).GetBikesAvailable();
|
|
|
|
var bikes = GetBikesAvailableAsync(
|
|
url,
|
|
request).Result.bikes;
|
|
|
|
Assert.That(
|
|
bikes,
|
|
Is.Not.Null,
|
|
"Response is null.");
|
|
|
|
var bike = bikes.FirstOrDefault().Value;
|
|
Assert.That(
|
|
bike,
|
|
Is.Not.Null,
|
|
"Response on GetBikesAvailableCall must contain at leas one bike.");
|
|
|
|
// Check if entries are valid.
|
|
Assert.Greater(
|
|
bike.description.Length,
|
|
0,
|
|
"Bike despcription must never be empty.");
|
|
|
|
Assert.That(
|
|
bike.bike,
|
|
Is.Not.Null,
|
|
"Bike index must never be null");
|
|
|
|
Assert.AreEqual(
|
|
"available",
|
|
bike.state,
|
|
"Bike state must be available");
|
|
}
|
|
|
|
/// <remarks>
|
|
/// From COPRI version v4.1 switched from TINK devel CopriServerUriList.TINK_DEVEL and CopriServerUriList.TINK_LIVE to CopriServerUriList.SHAREE_DEVEL.
|
|
/// </remarks>
|
|
[Test]
|
|
#if !NOLIVESERVER
|
|
[Category(CATEGORY_USESLIVESERVER)]
|
|
#elif !NODEVELSERVER
|
|
[Category(CATEGORY_USESDEVELSERVER)]
|
|
#endif
|
|
public void TestGetBikesAvailalbleCall_NotLoggedId(
|
|
#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
|
|
{
|
|
// Check prerequisites: At least one bike must be available.
|
|
var bikeReference = CopriCallsHttpsReference.GetBikesAvailableCall(url, TinkApp.MerchantId)?.bikes?.FirstOrDefault().Value;
|
|
Assert.That(
|
|
bikeReference,
|
|
Is.Not.Null,
|
|
$"Prerequisites are not matched: No bikes available from server {url} returned but at least one bike for verification required.");
|
|
|
|
// Verify list of bikes returned from first device
|
|
var request = new RequestBuilder(TinkApp.MerchantId, null /*UI language */).GetBikesAvailable();
|
|
|
|
var bikes = GetBikesAvailableAsync(
|
|
url,
|
|
request,
|
|
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetBikesAvailalbleCall_NotLoggedId)}").Result.bikes;
|
|
|
|
Assert.That(
|
|
bikes,
|
|
Is.Not.Null,
|
|
"Response is null.");
|
|
|
|
var bike = bikes.FirstOrDefault().Value;
|
|
Assert.That(
|
|
bike,
|
|
Is.Not.Null,
|
|
"Response on GetBikesAvailableCall must contain at leas one bike.");
|
|
|
|
// Check if entries are valid.
|
|
Assert.Greater(
|
|
bike.description.Length,
|
|
0,
|
|
"Bike despcription must never be empty.");
|
|
|
|
Assert.That(
|
|
bike.bike,
|
|
Is.Not.Null,
|
|
"Bike index must never be null");
|
|
|
|
Assert.AreEqual(
|
|
"available",
|
|
bike.state,
|
|
"Bike state must be available");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attention: Behaves different if called with a period smaller 15minutes because bike will alreay be reserved.
|
|
/// </summary>
|
|
[Test, Explicit, Ignore("Avoid testrunner running explicit tests.")]
|
|
public void TestDoReserveCall(
|
|
#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
|
|
{
|
|
Assert.Less(
|
|
CopriCallsHttpsReference.GetBikesOccupiedCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes_occupied.Count,
|
|
3,
|
|
"Too many bikes requested/ booked.");
|
|
|
|
var l_oBikesAvailable = CopriCallsHttpsReference.GetBikesAvailableCall(CopriServerUriList.DevelopUri.AbsoluteUri, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes;
|
|
|
|
Assert.Greater(
|
|
l_oBikesAvailable.Count,
|
|
0,
|
|
"There must be at least one bike available.");
|
|
|
|
// Id of bike to book
|
|
string l_oBikeId = l_oBikesAvailable.ToArray()[0].Value.bike;
|
|
|
|
// Check prerequisites.
|
|
// State of bike for which to cancel booking must be available.
|
|
Assert.NotNull(
|
|
CopriCallsHttpsReference.GetBikesAvailableCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes?.FirstOrDefault(x => x.Value.bike == l_oBikeId).Value,
|
|
"Prerequities check failed: Bike with given id must be available;");
|
|
|
|
var l_oBookingResponse = DoReserveAsync(
|
|
CopriServerUriList.DevelopUri.AbsoluteUri,
|
|
new RequestBuilderLoggedIn(
|
|
TinkApp.MerchantId, null /*UI language */, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).DoReserve(l_oBikeId)).Result;
|
|
|
|
try
|
|
{
|
|
// If response_state is "Failure 2001: booking bike 20 . maybe not available" probale test was run already and bike got reserved.
|
|
Assert.AreEqual(string.Format("OK: requested bike {0}", l_oBikeId), l_oBookingResponse.response_state);
|
|
}
|
|
finally
|
|
{
|
|
// Clean up to ensure that running tests does not modify data base.
|
|
CopriCallsHttpsReference.DoCancelReservationCall(url, TinkApp.MerchantId, l_oBikeId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attention: Behaves different if called with a period smaller 15minutes because bike will alreay be reserved.
|
|
/// </summary>
|
|
[Test, Explicit, Ignore("Avoid testrunner running explicit tests.")]
|
|
public void TestDoCancelReservationCall(
|
|
#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
|
|
|
|
{
|
|
Assert.Less(
|
|
CopriCallsHttpsReference.GetBikesOccupiedCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes_occupied.Count,
|
|
3,
|
|
"Too many bikes requested/ booked.");
|
|
|
|
var l_oBikesAvailable = CopriCallsHttpsReference.GetBikesAvailableCall(CopriServerUriList.DevelopUri.AbsoluteUri, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes;
|
|
|
|
Assert.Greater(
|
|
l_oBikesAvailable.Count,
|
|
0,
|
|
"There must be at least one bike available.");
|
|
|
|
// Id of bike to book
|
|
string l_oBikeId = l_oBikesAvailable.ToArray()[0].Value.bike;
|
|
|
|
// Check prerequisites.
|
|
var l_oBikeToCancel = CopriCallsHttpsReference.GetBikesAvailableCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes?.FirstOrDefault(x => x.Value.bike == l_oBikeId).Value;
|
|
if (l_oBikeToCancel != null)
|
|
{
|
|
// Bike is avilable. Do request before unning test.
|
|
CopriCallsHttpsReference.DoReserveCall(url, TinkApp.MerchantId, l_oBikeId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie);
|
|
}
|
|
|
|
// State of bike for which to cancel booking must be reserved.
|
|
var l_oReservedBike = CopriCallsHttpsReference.GetBikesOccupiedCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).bikes_occupied.FirstOrDefault(x => x.Value.bike == l_oBikeId).Value;
|
|
Assert.NotNull(l_oReservedBike, string.Format("Setup test failed. Bike with id {0} must be booked before verifying cancel of booking.", l_oReservedBike));
|
|
Assert.AreEqual("requested", l_oReservedBike.state, string.Format("Setup test failed. Bike with id {0} must be booked before verifying cancel of booking.", l_oReservedBike));
|
|
|
|
// Test cancel booking
|
|
var l_oBookingResponse = DoCancelReservationAsync(
|
|
CopriServerUriList.DevelopUri.AbsoluteUri,
|
|
new RequestBuilderLoggedIn(
|
|
TinkApp.MerchantId,
|
|
null /*UI language */,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).DoReserve(l_oBikeId)).Result;
|
|
|
|
try
|
|
{
|
|
Assert.AreEqual(string.Format("OK: canceled bike {0}", l_oBikeId), l_oBookingResponse.response_state);
|
|
}
|
|
catch
|
|
{
|
|
// Clean up to ensure that running tests does not modify data base.
|
|
CopriCallsHttpsReference.DoCancelReservationCall(url, TinkApp.MerchantId, l_oBikeId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie);
|
|
}
|
|
}
|
|
|
|
/// <summary>Tests the member.</summary>
|
|
/// <remarks>Timecode is no more verified since COPRI 4.1.</remarks>
|
|
[Test]
|
|
#if !NOLIVESERVER
|
|
[Category(CATEGORY_USESLIVESERVER)]
|
|
#elif !NODEVELSERVER
|
|
[Category(CATEGORY_USESDEVELSERVER)]
|
|
#endif
|
|
public void TestGetBikesOccupiedCall_SomeRequestedBooked(
|
|
#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
|
|
{
|
|
BikesReservedOccupiedResponse l_oBookingResponse;
|
|
var bikesOccupied = CopriCallsHttpsReference.GetBikesOccupiedCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes_occupied;
|
|
if (bikesOccupied == null || bikesOccupied.Count < 1)
|
|
{
|
|
// There must be at least one bike booked.
|
|
var bikesAvailable = CopriCallsHttpsReference.GetBikesAvailableCall(
|
|
url,
|
|
TinkApp.MerchantId,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes;
|
|
|
|
Assert.Greater(
|
|
bikesAvailable.Count,
|
|
0,
|
|
"Prerequisites are not matched: There must be at least one bike available.");
|
|
|
|
// Id of bike to book
|
|
var bike = bikesAvailable.ToArray()[0].Value;
|
|
|
|
l_oBookingResponse = CopriCallsHttpsReference.DoReserveCall(
|
|
bike.uri_operator + "/APIjsonserver",
|
|
TinkApp.MerchantId,
|
|
bike.bike,
|
|
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie);
|
|
|
|
Assert.That(l_oBookingResponse.GetIsResponseOk("Testing cotext"),
|
|
!Is.Null,
|
|
$"Booking must succeed. {l_oBookingResponse.response_text}");
|
|
}
|
|
|
|
// Verify GetBikesOccupied call.
|
|
var l_oBike = CopriCallsHttpsReference.GetBikesOccupiedCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes_occupied?.FirstOrDefault().Value;
|
|
Assert.NotNull(l_oBike, "Response on GetBikesOccupiedCall of must contain at least one bike.");
|
|
|
|
l_oBookingResponse = GetBikesOccupiedAsync(
|
|
url,
|
|
new RequestBuilderLoggedIn(TinkApp.MerchantId, null /*UI language */, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).GetBikesOccupied(),
|
|
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetBikesOccupiedCall_SomeRequestedBooked)}").Result;
|
|
|
|
// Check first entry.
|
|
Assert.AreEqual(
|
|
string.Format("{0}{1}", TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie, TinkApp.MerchantId),
|
|
l_oBookingResponse.authcookie);
|
|
|
|
Assert.Greater(l_oBike.description.Length, 0, "Bike despcription must never be empty.");
|
|
Assert.That(l_oBike.bike, Is.Not.Null, "Bike index must not be null.");
|
|
Assert.That(
|
|
l_oBike.station,
|
|
Is.Not.Null,
|
|
"Station index must never be null");
|
|
Assert.Greater(l_oBike.state.Length, 0, "State info must never be null or empty.");
|
|
// Todo: Requested bikes do not have a gps position. What is about booked bikes?
|
|
// Assert.Greater(l_oBike.gps.Length, 0, "Gps position must never be empty.");
|
|
Assert.Greater(l_oBike.start_time.Length, 0, "Time when request/ booking was performed must never be null or empty.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests the member.
|
|
/// Call GetBikesOccupiedCall is first call of app which fails (throws AuthcookieNotDefinedException) if auth cookie is invalid.
|
|
/// If app detects AuthcookieNotDefinedException exception user is logged out.
|
|
/// </summary>
|
|
[Test]
|
|
#if !NOLIVESERVER
|
|
[Category(CATEGORY_USESLIVESERVER)]
|
|
#elif !NODEVELSERVER
|
|
[Category(CATEGORY_USESDEVELSERVER)]
|
|
#endif
|
|
public void TestGetBikesOccupiedCall_KeksGibtsNet(
|
|
#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
|
|
{
|
|
var request = new RequestBuilderLoggedIn(TinkApp.MerchantId, null /*UI language */, TestTINKLib.LoginSessionCopriInfo.JavaministerKeksGibtsNet.AuthCookie).GetBikesOccupied();
|
|
|
|
var l_oBookingResponse = GetBikesOccupiedAsync(
|
|
url,
|
|
request,
|
|
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetBikesOccupiedCall_KeksGibtsNet)}").Result;
|
|
|
|
Assert.AreEqual(
|
|
"Failure 1001: authcookie on primary not defined",
|
|
l_oBookingResponse.response_state); // Up to 2020-12-05 COPRI returned: "Failure 1003: authcookie not defined"
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests the member.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// From COPRI version v4.1 switched from TINK devel CopriServerUriList.TINK_DEVEL and CopriServerUriList.TINK_LIVE to CopriServerUriList.SHAREE_DEVEL.
|
|
/// </remarks>
|
|
[Test]
|
|
[Category(CATEGORY_REQUIRESCOPRI)]
|
|
#if !NOLIVESERVER
|
|
[Category(CATEGORY_USESLIVESERVER)]
|
|
#endif
|
|
public void TestGetStationsAllCall_NotLoggedIn(
|
|
#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
|
|
{
|
|
// Check prerequisites: At least one bike must be available.
|
|
var l_oStationsReference = CopriCallsHttpsReference.GetStationsAllCall(url, TinkApp.MerchantId)?.stations;
|
|
Assert.IsTrue(
|
|
l_oStationsReference != null && l_oStationsReference.Count > 0,
|
|
"Prerequisites are not matched: There are no stations.");
|
|
|
|
// Verify implementation
|
|
var l_oStationsAll = GetStationsAsync(url, new RequestBuilder(TinkApp.MerchantId, null /*UI language */).GetStations()).Result;
|
|
Assert.NotNull(l_oStationsAll?.stations);
|
|
Assert.Greater(l_oStationsAll.stations.Count, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests the member.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// From COPRI version v4.1 switched from TINK devel CopriServerUriList.TINK_DEVEL and CopriServerUriList.TINK_LIVE to CopriServerUriList.SHAREE_DEVEL.
|
|
/// </remarks>
|
|
[Test]
|
|
#if !NOLIVESERVER
|
|
[Category(CATEGORY_USESLIVESERVER)]
|
|
#elif !NODEVELSERVER
|
|
[Category(CATEGORY_USESDEVELSERVER)]
|
|
#endif
|
|
public void TestGetStationsAllCall_LoggedIn(
|
|
#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
|
|
{
|
|
var stationsAll = GetStationsAsync(
|
|
url,
|
|
new RequestBuilderLoggedIn(TinkApp.MerchantId, null /*UI language */, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).GetStations(),
|
|
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetStationsAllCall_LoggedIn)}").Result;
|
|
|
|
Assert.NotNull(stationsAll?.stations);
|
|
Assert.That(
|
|
stationsAll.stations.Count,
|
|
Is.GreaterThan(0),
|
|
$"There must be at least one station.");
|
|
}
|
|
}
|
|
}
|