2023-04-19 12:14:14 +02:00
using System ;
2021-07-12 21:31:46 +02:00
using System.Linq ;
2022-08-30 15:42:25 +02:00
using System.Reflection ;
2021-07-12 21:31:46 +02:00
using System.Threading ;
2022-08-30 15:42:25 +02:00
using NUnit.Framework ;
2021-07-12 21:31:46 +02:00
using TINK.Model ;
2022-08-30 15:42:25 +02:00
using TINK.Model.Services.CopriApi.ServerUris ;
2021-07-12 21:31:46 +02:00
using TINK.Repository ;
using TINK.Repository.Exception ;
using TINK.Repository.Request ;
2022-08-30 15:42:25 +02:00
using TINK.Repository.Response ;
2021-07-12 21:31:46 +02:00
using static TINK . Repository . CopriCallsHttps ;
namespace UITest.Fixtures.Connector
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestCopriCallsHttps
{
public const string CATEGORY_REQUIRESCOPRI = "RequiresCOPRI" ;
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
public const string CATEGORY_USESLIVESERVER = "RequiresCOPRI.Live" ;
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
public const string CATEGORY_USESDEVELSERVER = "RequiresCOPRI.Devel" ;
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
public const string TESTAGENT = "TestShareeLib" ;
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[TearDown]
public void TearDown ( )
{
Thread . Sleep ( 2000 ) ; // Sleep, otherwise copri will block requested calls.
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[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 ) ;
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
#if ! NOLIVESERVER
2021-07-12 21:31:46 +02:00
[Category(CATEGORY_USESLIVESERVER)]
#elif ! NODEVELSERVER
2022-09-06 16:08:19 +02:00
[Category(CATEGORY_USESDEVELSERVER)]
2021-07-12 21:31:46 +02:00
#endif
2022-09-06 16:08:19 +02:00
public void TestLogin (
2021-07-12 21:31:46 +02:00
#if NOLIVESERVER
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL)] string url )
2021-07-12 21:31:46 +02:00
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)]
string url )
#else
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url )
#endif
2022-09-06 16:08:19 +02:00
{
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
2021-07-12 21:31:46 +02:00
[Category(CATEGORY_USESLIVESERVER)]
#elif ! NODEVELSERVER
2022-09-06 16:08:19 +02:00
[Category(CATEGORY_USESDEVELSERVER)]
2021-07-12 21:31:46 +02:00
#endif
2022-09-06 16:08:19 +02:00
public void TestLogin_UserUnknown (
2021-07-12 21:31:46 +02:00
#if NOLIVESERVER
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL)] string url )
2021-07-12 21:31:46 +02:00
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)]
string url )
#else
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url )
#endif
2022-09-06 16:08:19 +02:00
{
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
2021-07-12 21:31:46 +02:00
[Category(CATEGORY_USESLIVESERVER)]
#elif ! NODEVELSERVER
2022-09-06 16:08:19 +02:00
[Category(CATEGORY_USESDEVELSERVER)]
2021-07-12 21:31:46 +02:00
#endif
2022-09-06 16:08:19 +02:00
public void TestLogout (
2021-07-12 21:31:46 +02:00
#if NOLIVESERVER
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL)] string url )
2021-07-12 21:31:46 +02:00
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)]
string url )
#else
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url )
#endif
2022-09-06 16:08:19 +02:00
{
// 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
2021-07-12 21:31:46 +02:00
[Category(CATEGORY_USESLIVESERVER)]
#elif ! NODEVELSERVER
2022-09-06 16:08:19 +02:00
[Category(CATEGORY_USESDEVELSERVER)]
2021-07-12 21:31:46 +02:00
#endif
2022-09-06 16:08:19 +02:00
public void TestLogout_NotLoggedIn (
2021-07-12 21:31:46 +02:00
#if NOLIVESERVER
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL)] string url )
2021-07-12 21:31:46 +02:00
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)]
string url )
#else
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url )
#endif
2022-09-06 16:08:19 +02:00
{
// 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
2021-07-12 21:31:46 +02:00
[Category(CATEGORY_USESLIVESERVER)]
#elif ! NODEVELSERVER
2022-09-06 16:08:19 +02:00
[Category(CATEGORY_USESDEVELSERVER)]
2021-07-12 21:31:46 +02:00
#endif
2022-09-06 16:08:19 +02:00
public void TestLogout_AuthcookieUnknown (
2021-07-12 21:31:46 +02:00
#if NOLIVESERVER
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL)] string url )
2021-07-12 21:31:46 +02:00
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)]
string url )
#else
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url )
#endif
2022-09-06 16:08:19 +02:00
{
// 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
2021-07-12 21:31:46 +02:00
[Category(CATEGORY_USESLIVESERVER)]
#elif ! NODEVELSERVER
2022-09-06 16:08:19 +02:00
[Category(CATEGORY_USESDEVELSERVER)]
2021-07-12 21:31:46 +02:00
#endif
2022-09-06 16:08:19 +02:00
public void TestGetBikesAvailalbleCall_LoggedId (
2021-07-12 21:31:46 +02:00
#if NOLIVESERVER
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL)] string url )
2021-07-12 21:31:46 +02:00
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)] string url )
#else
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url )
#endif
2022-09-06 16:08:19 +02:00
{
// 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 ,
2023-04-19 12:14:14 +02:00
"Bike description must never be empty." ) ;
2022-09-06 16:08:19 +02:00
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
2021-07-12 21:31:46 +02:00
[Category(CATEGORY_USESLIVESERVER)]
#elif ! NODEVELSERVER
2022-09-06 16:08:19 +02:00
[Category(CATEGORY_USESDEVELSERVER)]
2021-07-12 21:31:46 +02:00
#endif
2022-09-06 16:08:19 +02:00
public void TestGetBikesAvailalbleCall_NotLoggedId (
2021-07-12 21:31:46 +02:00
#if NOLIVESERVER
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL)] string url )
2021-07-12 21:31:46 +02:00
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)] string url )
#else
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url )
#endif
2022-09-06 16:08:19 +02:00
{
// 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 ,
2023-04-19 12:14:14 +02:00
"Bike description must never be empty." ) ;
2022-09-06 16:08:19 +02:00
Assert . That (
bike . bike ,
Is . Not . Null ,
"Bike index must never be null" ) ;
Assert . AreEqual (
"available" ,
bike . state ,
"Bike state must be available" ) ;
}
/// <summary>
2023-04-19 12:14:14 +02:00
/// Attention: Behaves different if called with a period smaller 15minutes because bike will already be reserved.
2022-09-06 16:08:19 +02:00
/// </summary>
[Test, Explicit, Ignore("Avoid testrunner running explicit tests.")]
public void TestDoReserveCall (
2021-07-12 21:31:46 +02:00
#if NOLIVESERVER
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL)] string url )
2021-07-12 21:31:46 +02:00
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)]
string url )
#else
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url )
#endif
2022-09-06 16:08:19 +02:00
{
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 ,
2023-04-19 12:14:14 +02:00
"Prerequisites check failed: Bike with given id must be available;" ) ;
2022-09-06 16:08:19 +02:00
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>
2023-04-19 12:14:14 +02:00
/// Attention: Behaves different if called with a period smaller 15minutes because bike will already be reserved.
2022-09-06 16:08:19 +02:00
/// </summary>
[Test, Explicit, Ignore("Avoid testrunner running explicit tests.")]
public void TestDoCancelReservationCall (
2021-07-12 21:31:46 +02:00
#if NOLIVESERVER
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL)] string url )
2021-07-12 21:31:46 +02:00
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)]
string url )
#else
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url )
#endif
2022-09-06 16:08:19 +02:00
{
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 )
{
2023-04-19 12:14:14 +02:00
// Bike is available. Do request before unning test.
2022-09-06 16:08:19 +02:00
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
2021-07-12 21:31:46 +02:00
[Category(CATEGORY_USESLIVESERVER)]
#elif ! NODEVELSERVER
2022-09-06 16:08:19 +02:00
[Category(CATEGORY_USESDEVELSERVER)]
2021-07-12 21:31:46 +02:00
#endif
2022-09-06 16:08:19 +02:00
public void TestGetBikesOccupiedCall_SomeRequestedBooked (
2021-07-12 21:31:46 +02:00
#if NOLIVESERVER
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL)] string url )
2021-07-12 21:31:46 +02:00
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)]
string url )
#else
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url )
#endif
2022-09-06 16:08:19 +02:00
{
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 ) ;
2023-04-19 12:14:14 +02:00
Assert . Greater ( l_oBike . description . Length , 0 , "Bike description must never be empty." ) ;
2022-09-06 16:08:19 +02:00
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
2021-07-12 21:31:46 +02:00
[Category(CATEGORY_USESLIVESERVER)]
#elif ! NODEVELSERVER
2022-09-06 16:08:19 +02:00
[Category(CATEGORY_USESDEVELSERVER)]
2021-07-12 21:31:46 +02:00
#endif
2022-09-06 16:08:19 +02:00
public void TestGetBikesOccupiedCall_KeksGibtsNet (
2021-07-12 21:31:46 +02:00
#if NOLIVESERVER
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL)] string url )
2021-07-12 21:31:46 +02:00
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)] string url )
#else
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url )
#endif
2022-09-06 16:08:19 +02:00
{
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
2021-07-12 21:31:46 +02:00
[Category(CATEGORY_USESLIVESERVER)]
#endif
2022-09-06 16:08:19 +02:00
public void TestGetStationsAllCall_NotLoggedIn (
2021-07-12 21:31:46 +02:00
#if NOLIVESERVER
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL)] string url )
2021-07-12 21:31:46 +02:00
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)] string url )
#else
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url )
#endif
2022-09-06 16:08:19 +02:00
{
// 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
2021-07-12 21:31:46 +02:00
[Category(CATEGORY_USESLIVESERVER)]
#elif ! NODEVELSERVER
2022-09-06 16:08:19 +02:00
[Category(CATEGORY_USESDEVELSERVER)]
2021-07-12 21:31:46 +02:00
#endif
2022-09-06 16:08:19 +02:00
public void TestGetStationsAllCall_LoggedIn (
2021-07-12 21:31:46 +02:00
#if NOLIVESERVER
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL)] string url )
2021-07-12 21:31:46 +02:00
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)] string url )
#else
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url )
#endif
2022-09-06 16:08:19 +02:00
{
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." ) ;
}
}
2021-07-12 21:31:46 +02:00
}