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 ;
2024-04-09 12:53:23 +02:00
using ShareeBike.Model ;
using ShareeBike.Model.Services.CopriApi.ServerUris ;
using ShareeBike.Repository ;
using ShareeBike.Repository.Exception ;
using ShareeBike.Repository.Request ;
using ShareeBike.Repository.Response ;
using static ShareeBike . Repository . CopriCallsHttps ;
2021-07-12 21:31:46 +02:00
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
2024-04-09 12:53:23 +02:00
public const string TESTAGENT = "SharedBusinessLogic.Tests" ;
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 ( )
{
2024-04-09 12:53:23 +02:00
Assert . That ( new CopriCallsHttps ( new Uri ( "http://127.0.0.0/api" ) , new AppContextInfo ( "oiF2kahH" , "sharee.bike.test" , new Version ( 3 , 0 , 267 ) ) , "123" ) . IsConnected , Is . True ) ;
2022-09-06 16:08:19 +02:00
}
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
{
2024-04-09 12:53:23 +02:00
Func < string , string > command = ( password ) = > new RequestBuilder ( ShareeBikeApp . MerchantId , null /*UI language */ ) . DoAuthorization (
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Mail ,
2022-09-06 16:08:19 +02:00
password ,
2024-04-09 12:53:23 +02:00
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . DeviceId ) ;
2022-09-06 16:08:19 +02:00
var l_oSessionCookieJM_Dev1 = DoAuthorizationAsync (
url ,
2024-04-09 12:53:23 +02:00
command ( SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Pwd ) ,
2022-09-06 16:08:19 +02:00
( ) = > command ( "*******" ) ,
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogin)}" ) . Result ;
2024-04-09 12:53:23 +02:00
Assert . That (
l_oSessionCookieJM_Dev1 . authcookie , Is . EqualTo ( string . Format ( "{0}{1}" , "6103_4da3044c8657a04ba60e2eaa753bc51a_" , "oiF2kahH" ) ) ,
2022-09-06 16:08:19 +02:00
"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
{
2024-04-09 12:53:23 +02:00
Func < string , string > command = ( password ) = > new RequestBuilder ( ShareeBikeApp . MerchantId , null /*UI language */ ) . DoAuthorization (
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerGibtsNet . Mail ,
2022-09-06 16:08:19 +02:00
password ,
2024-04-09 12:53:23 +02:00
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerGibtsNet . DeviceId ) ;
2022-09-06 16:08:19 +02:00
var l_oSessionCookieJM_Dev1 = DoAuthorizationAsync (
url ,
2024-04-09 12:53:23 +02:00
command ( SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerGibtsNet . Pwd ) ,
2022-09-06 16:08:19 +02:00
( ) = > 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
2024-04-09 12:53:23 +02:00
Assert . That ( l_oSessionCookieJM_Dev1 . authcookie , Is . Empty ) ;
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
Assert . That (
l_oSessionCookieJM_Dev1 . response , Is . EqualTo ( "authorization" ) ) ;
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
Assert . That (
l_oSessionCookieJM_Dev1 . response_state , Is . EqualTo ( "Failure: cannot generate authcookie" ) ) ;
2022-09-06 16:08:19 +02:00
}
/// <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 ,
2024-04-09 12:53:23 +02:00
ShareeBikeApp . MerchantId ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Mail ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Pwd ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . DeviceId ) ;
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
Assert . That (
string . IsNullOrEmpty ( l_oSessionCookie ? . authcookie ) , Is . False ,
2022-09-06 16:08:19 +02:00
"Prerequisites not matched: User must be logged on before beeing able to log out." ) ;
// Verify logout
try
{
2024-04-09 12:53:23 +02:00
Assert . That ( DoAuthoutAsync (
2022-09-06 16:08:19 +02:00
url ,
new RequestBuilderLoggedIn (
2024-04-09 12:53:23 +02:00
ShareeBikeApp . MerchantId ,
2022-09-06 16:08:19 +02:00
null /*UI language */ ,
2024-04-09 12:53:23 +02:00
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) . DoAuthout ( ) ,
2022-09-06 16:08:19 +02:00
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogout)}"
2024-04-09 12:53:23 +02:00
) . Result . GetIsResponseOk ( ) , Is . Not . Null ) ;
2022-09-06 16:08:19 +02:00
}
finally
{
// Log in again to ensure that tests do not change state of database (assumtion: user is always logged in).
CopriCallsHttpsReference . DoAuthorizeCall (
url ,
2024-04-09 12:53:23 +02:00
ShareeBikeApp . MerchantId ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Mail ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Pwd ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . DeviceId ) ;
2022-09-06 16:08:19 +02:00
}
}
/// <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 ,
2024-04-09 12:53:23 +02:00
ShareeBikeApp . MerchantId ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Mail ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Pwd ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . DeviceId ) ;
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
Assert . That (
string . IsNullOrEmpty ( l_oLoginResponse ? . authcookie ) , Is . False ,
2022-09-06 16:08:19 +02:00
"Prerequisites not matched: User must be logged out before beeing able to log out." ) ;
2024-04-09 12:53:23 +02:00
CopriCallsHttpsReference . DoAuthoutCall ( url , ShareeBikeApp . MerchantId , l_oLoginResponse . authcookie ) ;
2022-09-06 16:08:19 +02:00
try
{
// Verify logout
Assert . Throws < AuthcookieNotDefinedException > (
( ) = > DoAuthoutAsync (
url ,
2024-04-09 12:53:23 +02:00
new RequestBuilderLoggedIn ( ShareeBikeApp . MerchantId , null /*UI language */ , l_oLoginResponse . authcookie ) . DoAuthout ( ) ,
2022-09-06 16:08:19 +02:00
$"{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 ,
2024-04-09 12:53:23 +02:00
ShareeBikeApp . MerchantId ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Mail ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Pwd ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . DeviceId ) ;
2022-09-06 16:08:19 +02:00
}
}
/// <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 ,
2024-04-09 12:53:23 +02:00
ShareeBikeApp . MerchantId ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Mail ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Pwd ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . DeviceId ) ;
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
Assert . That (
string . IsNullOrEmpty ( l_oSessionCookie ? . authcookie ) , Is . False ,
2022-09-06 16:08:19 +02:00
"Prerequisites not matched: User must be logged on before beeing able to log out." ) ;
// Verify logout that expected excepton is thrown.
try
{
2024-04-09 12:53:23 +02:00
Assert . That (
2022-09-06 16:08:19 +02:00
DoAuthoutAsync (
url ,
new RequestBuilderLoggedIn (
2024-04-09 12:53:23 +02:00
ShareeBikeApp . MerchantId ,
2022-09-06 16:08:19 +02:00
null /*UI language */ ,
2024-04-09 12:53:23 +02:00
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerKeksGibtsNet . AuthCookie ) . DoAuthout ( ) ,
2022-09-06 16:08:19 +02:00
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogout_AuthcookieUnknown)}"
2024-04-09 12:53:23 +02:00
) . Result . response_state , Is . EqualTo ( "Failure 1001: authcookie not defined" ) ) ;
2022-09-06 16:08:19 +02:00
}
finally
{
// Log in again to ensure that tests do not change state of database (assumtion: user is always logged in).
CopriCallsHttpsReference . DoAuthorizeCall (
url ,
2024-04-09 12:53:23 +02:00
ShareeBikeApp . MerchantId ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Mail ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . Pwd ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . DeviceId ) ;
2022-09-06 16:08:19 +02:00
}
}
/// <remarks>
2024-04-09 12:53:23 +02:00
/// From COPRI version v4.1 switched from ShareeBike devel CopriServerUriList.ShareeBike_DEVEL and CopriServerUriList.ShareeBike_LIVE to CopriServerUriList.SHAREE_DEVEL.
2022-09-06 16:08:19 +02:00
/// </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.
2024-04-09 12:53:23 +02:00
var bikesReference = CopriCallsHttpsReference . GetBikesAvailableCall ( url , ShareeBikeApp . MerchantId , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ? . bikes ;
Assert . That ( bikesReference , Is . Not . Null ) ;
2022-09-06 16:08:19 +02:00
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 (
2024-04-09 12:53:23 +02:00
ShareeBikeApp . MerchantId ,
2022-09-06 16:08:19 +02:00
null /*UI language */ ,
2024-04-09 12:53:23 +02:00
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) . GetBikesAvailable ( ) ;
2022-09-06 16:08:19 +02:00
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.
2024-04-09 12:53:23 +02:00
Assert . That (
bike . description . Length , Is . GreaterThan ( 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" ) ;
2024-04-09 12:53:23 +02:00
Assert . That (
bike . state , Is . EqualTo ( "available" ) ,
2022-09-06 16:08:19 +02:00
"Bike state must be available" ) ;
}
/// <remarks>
2024-04-09 12:53:23 +02:00
/// From COPRI version v4.1 switched from ShareeBike devel CopriServerUriList.ShareeBike_DEVEL and CopriServerUriList.ShareeBike_LIVE to CopriServerUriList.SHAREE_DEVEL.
2022-09-06 16:08:19 +02:00
/// </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.
2024-04-09 12:53:23 +02:00
var bikeReference = CopriCallsHttpsReference . GetBikesAvailableCall ( url , ShareeBikeApp . MerchantId ) ? . bikes ? . FirstOrDefault ( ) . Value ;
2022-09-06 16:08:19 +02:00
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
2024-04-09 12:53:23 +02:00
var request = new RequestBuilder ( ShareeBikeApp . MerchantId , null /*UI language */ ) . GetBikesAvailable ( ) ;
2022-09-06 16:08:19 +02:00
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.
2024-04-09 12:53:23 +02:00
Assert . That (
bike . description . Length , Is . GreaterThan ( 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" ) ;
2024-04-09 12:53:23 +02:00
Assert . That (
bike . state , Is . EqualTo ( "available" ) ,
2022-09-06 16:08:19 +02:00
"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
{
2024-04-09 12:53:23 +02:00
Assert . That (
CopriCallsHttpsReference . GetBikesOccupiedCall ( url , ShareeBikeApp . MerchantId , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ? . bikes_occupied . Count ,
Is . LessThan ( 3 ) ,
2022-09-06 16:08:19 +02:00
"Too many bikes requested/ booked." ) ;
2024-04-09 12:53:23 +02:00
var l_oBikesAvailable = CopriCallsHttpsReference . GetBikesAvailableCall ( CopriServerUriList . DevelopUri . AbsoluteUri , ShareeBikeApp . MerchantId , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ? . bikes ;
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
Assert . That (
l_oBikesAvailable . Count , Is . GreaterThan ( 0 ) ,
2022-09-06 16:08:19 +02:00
"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.
2024-04-09 12:53:23 +02:00
Assert . That (
CopriCallsHttpsReference . GetBikesAvailableCall ( url , ShareeBikeApp . MerchantId , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ? . bikes ? . FirstOrDefault ( x = > x . Value . bike = = l_oBikeId ) . Value , Is . Not . Null ,
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 (
2024-04-09 12:53:23 +02:00
ShareeBikeApp . MerchantId , null /*UI language */ , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) . DoReserve ( l_oBikeId ) ) . Result ;
2022-09-06 16:08:19 +02:00
try
{
// If response_state is "Failure 2001: booking bike 20 . maybe not available" probale test was run already and bike got reserved.
2024-04-09 12:53:23 +02:00
Assert . That ( l_oBookingResponse . response_state , Is . EqualTo ( string . Format ( "OK: requested bike {0}" , l_oBikeId ) ) ) ;
2022-09-06 16:08:19 +02:00
}
finally
{
// Clean up to ensure that running tests does not modify data base.
2024-04-09 12:53:23 +02:00
CopriCallsHttpsReference . DoCancelReservationCall ( url , ShareeBikeApp . MerchantId , l_oBikeId , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ;
2022-09-06 16:08:19 +02:00
}
}
/// <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
{
2024-04-09 12:53:23 +02:00
Assert . That (
CopriCallsHttpsReference . GetBikesOccupiedCall ( url , ShareeBikeApp . MerchantId , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ? . bikes_occupied . Count ,
Is . LessThan ( 3 ) ,
2022-09-06 16:08:19 +02:00
"Too many bikes requested/ booked." ) ;
2024-04-09 12:53:23 +02:00
var l_oBikesAvailable = CopriCallsHttpsReference . GetBikesAvailableCall ( CopriServerUriList . DevelopUri . AbsoluteUri , ShareeBikeApp . MerchantId , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ? . bikes ;
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
Assert . That (
l_oBikesAvailable . Count , Is . GreaterThan ( 0 ) ,
2022-09-06 16:08:19 +02:00
"There must be at least one bike available." ) ;
// Id of bike to book
string l_oBikeId = l_oBikesAvailable . ToArray ( ) [ 0 ] . Value . bike ;
// Check prerequisites.
2024-04-09 12:53:23 +02:00
var l_oBikeToCancel = CopriCallsHttpsReference . GetBikesAvailableCall ( url , ShareeBikeApp . MerchantId , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ? . bikes ? . FirstOrDefault ( x = > x . Value . bike = = l_oBikeId ) . Value ;
2022-09-06 16:08:19 +02:00
if ( l_oBikeToCancel ! = null )
{
2024-04-09 12:53:23 +02:00
// Bike is available. Do request before running test.
CopriCallsHttpsReference . DoReserveCall ( url , ShareeBikeApp . MerchantId , l_oBikeId , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ;
2022-09-06 16:08:19 +02:00
}
// State of bike for which to cancel booking must be reserved.
2024-04-09 12:53:23 +02:00
var l_oReservedBike = CopriCallsHttpsReference . GetBikesOccupiedCall ( url , ShareeBikeApp . MerchantId , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) . bikes_occupied . FirstOrDefault ( x = > x . Value . bike = = l_oBikeId ) . Value ;
Assert . That ( l_oReservedBike , Is . Not . Null , string . Format ( "Setup test failed. Bike with id {0} must be booked before verifying cancel of booking." , l_oReservedBike ) ) ;
Assert . That ( l_oReservedBike . state , Is . EqualTo ( "requested" ) , string . Format ( "Setup test failed. Bike with id {0} must be booked before verifying cancel of booking." , l_oReservedBike ) ) ;
2022-09-06 16:08:19 +02:00
// Test cancel booking
var l_oBookingResponse = DoCancelReservationAsync (
CopriServerUriList . DevelopUri . AbsoluteUri ,
new RequestBuilderLoggedIn (
2024-04-09 12:53:23 +02:00
ShareeBikeApp . MerchantId ,
2022-09-06 16:08:19 +02:00
null /*UI language */ ,
2024-04-09 12:53:23 +02:00
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) . DoReserve ( l_oBikeId ) ) . Result ;
2022-09-06 16:08:19 +02:00
try
{
2024-04-09 12:53:23 +02:00
Assert . That ( l_oBookingResponse . response_state , Is . EqualTo ( string . Format ( "OK: canceled bike {0}" , l_oBikeId ) ) ) ;
2022-09-06 16:08:19 +02:00
}
catch
{
// Clean up to ensure that running tests does not modify data base.
2024-04-09 12:53:23 +02:00
CopriCallsHttpsReference . DoCancelReservationCall ( url , ShareeBikeApp . MerchantId , l_oBikeId , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ;
2022-09-06 16:08:19 +02:00
}
}
/// <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 ;
2024-04-09 12:53:23 +02:00
var bikesOccupied = CopriCallsHttpsReference . GetBikesOccupiedCall ( url , ShareeBikeApp . MerchantId , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ? . bikes_occupied ;
2022-09-06 16:08:19 +02:00
if ( bikesOccupied = = null | | bikesOccupied . Count < 1 )
{
// There must be at least one bike booked.
var bikesAvailable = CopriCallsHttpsReference . GetBikesAvailableCall (
url ,
2024-04-09 12:53:23 +02:00
ShareeBikeApp . MerchantId ,
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ? . bikes ;
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
Assert . That (
bikesAvailable . Count , Is . GreaterThan ( 0 ) ,
2022-09-06 16:08:19 +02:00
"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" ,
2024-04-09 12:53:23 +02:00
ShareeBikeApp . MerchantId ,
2022-09-06 16:08:19 +02:00
bike . bike ,
2024-04-09 12:53:23 +02:00
SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ;
2022-09-06 16:08:19 +02:00
Assert . That ( l_oBookingResponse . GetIsResponseOk ( "Testing cotext" ) ,
! Is . Null ,
$"Booking must succeed. {l_oBookingResponse.response_text}" ) ;
}
// Verify GetBikesOccupied call.
2024-04-09 12:53:23 +02:00
var l_oBike = CopriCallsHttpsReference . GetBikesOccupiedCall ( url , ShareeBikeApp . MerchantId , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) ? . bikes_occupied ? . FirstOrDefault ( ) . Value ;
Assert . That ( l_oBike , Is . Not . Null , "Response on GetBikesOccupiedCall of must contain at least one bike." ) ;
2022-09-06 16:08:19 +02:00
l_oBookingResponse = GetBikesOccupiedAsync (
url ,
2024-04-09 12:53:23 +02:00
new RequestBuilderLoggedIn ( ShareeBikeApp . MerchantId , null /*UI language */ , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) . GetBikesOccupied ( ) ,
2022-09-06 16:08:19 +02:00
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetBikesOccupiedCall_SomeRequestedBooked)}" ) . Result ;
// Check first entry.
2024-04-09 12:53:23 +02:00
Assert . That (
l_oBookingResponse . authcookie , Is . EqualTo ( string . Format ( "{0}{1}" , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie , ShareeBikeApp . MerchantId ) ) ) ;
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
Assert . That ( l_oBike . description . Length , Is . GreaterThan ( 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" ) ;
2024-04-09 12:53:23 +02:00
Assert . That ( l_oBike . state . Length , Is . GreaterThan ( 0 ) , "State info must never be null or empty." ) ;
2022-09-06 16:08:19 +02:00
// 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.");
2024-04-09 12:53:23 +02:00
Assert . That ( l_oBike . start_time . Length , Is . GreaterThan ( 0 ) , "Time when request/ booking was performed must never be null or empty." ) ;
2022-09-06 16:08:19 +02:00
}
/// <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
{
2024-04-09 12:53:23 +02:00
var request = new RequestBuilderLoggedIn ( ShareeBikeApp . MerchantId , null /*UI language */ , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerKeksGibtsNet . AuthCookie ) . GetBikesOccupied ( ) ;
2022-09-06 16:08:19 +02:00
var l_oBookingResponse = GetBikesOccupiedAsync (
url ,
request ,
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetBikesOccupiedCall_KeksGibtsNet)}" ) . Result ;
2024-04-09 12:53:23 +02:00
Assert . That (
l_oBookingResponse . response_state , Is . EqualTo ( "Failure 1001: authcookie on primary not defined" ) ) ; // Up to 2020-12-05 COPRI returned: "Failure 1003: authcookie not defined"
2022-09-06 16:08:19 +02:00
}
/// <summary>
/// Tests the member.
/// </summary>
/// <remarks>
2024-04-09 12:53:23 +02:00
/// From COPRI version v4.1 switched from ShareeBike devel CopriServerUriList.ShareeBike_DEVEL and CopriServerUriList.ShareeBike_LIVE to CopriServerUriList.SHAREE_DEVEL.
2022-09-06 16:08:19 +02:00
/// </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.
2024-04-09 12:53:23 +02:00
var l_oStationsReference = CopriCallsHttpsReference . GetStationsAllCall ( url , ShareeBikeApp . MerchantId ) ? . stations ;
Assert . That (
l_oStationsReference ! = null & & l_oStationsReference . Count > 0 , Is . True ,
2022-09-06 16:08:19 +02:00
"Prerequisites are not matched: There are no stations." ) ;
// Verify implementation
2024-04-09 12:53:23 +02:00
var l_oStationsAll = GetStationsAsync ( url , new RequestBuilder ( ShareeBikeApp . MerchantId , null /*UI language */ ) . GetStations ( ) ) . Result ;
Assert . That ( l_oStationsAll ? . stations , Is . Not . Null ) ;
Assert . That ( l_oStationsAll . stations . Count , Is . GreaterThan ( 0 ) ) ;
2022-09-06 16:08:19 +02:00
}
/// <summary>
/// Tests the member.
/// </summary>
/// <remarks>
2024-04-09 12:53:23 +02:00
/// From COPRI version v4.1 switched from ShareeBike devel CopriServerUriList.ShareeBike_DEVEL and CopriServerUriList.ShareeBike_LIVE to CopriServerUriList.SHAREE_DEVEL.
2022-09-06 16:08:19 +02:00
/// </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 ,
2024-04-09 12:53:23 +02:00
new RequestBuilderLoggedIn ( ShareeBikeApp . MerchantId , null /*UI language */ , SharedBusinessLogic . Tests . LoginSessionCopriInfo . JavaministerHardwareNr1 . AuthCookie ) . GetStations ( ) ,
2022-09-06 16:08:19 +02:00
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetStationsAllCall_LoggedIn)}" ) . Result ;
2024-04-09 12:53:23 +02:00
Assert . That ( stationsAll ? . stations , Is . Not . Null ) ;
2022-09-06 16:08:19 +02:00
Assert . That (
stationsAll . stations . Count ,
Is . GreaterThan ( 0 ) ,
$"There must be at least one station." ) ;
}
}
2021-07-12 21:31:46 +02:00
}