2023-02-22 14:03:35 +01:00
using System ;
2022-08-30 15:42:25 +02:00
using MonkeyCache.FileStore ;
2021-06-26 20:57:55 +02:00
using NUnit.Framework ;
using Serilog ;
2024-04-09 12:53:23 +02:00
using ShareeBike.Model.Connector ;
using ShareeBike.Model.Services.CopriApi.ServerUris ;
using ShareeBike.Repository ;
2021-06-26 20:57:55 +02:00
using UITest.Fixtures.Connector ;
2024-04-09 12:53:23 +02:00
namespace SharedBusinessLogic.Tests.Fixtures.Misc
2021-06-26 20:57:55 +02:00
{
2022-09-06 16:08:19 +02:00
[TestFixture]
[Category(TestCopriCallsHttps.CATEGORY_REQUIRESCOPRI)]
public class TestCachetimings
{
[Test]
#if ! NOLIVESERVER
[Explicit("Run with care because this stress impact live system.")]
//[Category(TestCopriCallsHttps.CATEGORY_USESLIVESERVER)]
2021-06-26 20:57:55 +02:00
#elif ! NODEVELSERVER
[Category(TestCopriCallsHttps.CATEGORY_USESDEVELSERVER)]
#endif
2022-09-06 16:08:19 +02:00
public void TestCachedQuery_GetStationsAll (
2021-06-26 20:57:55 +02:00
#if NOLIVESERVER
[Values(CopriServerUriList.SHAREE_DEVEL)] string url ,
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)] string url ,
#else
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url ,
2021-06-26 20:57:55 +02:00
#endif
2022-09-06 16:08:19 +02:00
[Values(";", "6103_4da3044c8657a04ba60e2eaa753bc51a_;javaminister@gmail.com")] string cookieAndMail )
{
Barrel . ApplicationId = GetType ( ) . Name + nameof ( TestCachedQuery_GetStationsAll ) ;
Log . Logger = new LoggerConfiguration ( )
. MinimumLevel . ControlledBy ( new Serilog . Core . LoggingLevelSwitch ( Serilog . Events . LogEventLevel . Error ) )
. WriteTo . Debug ( )
. CreateLogger ( ) ;
var connector = ConnectorFactory . Create (
true , // Is connected
new Uri ( url ) ,
new AppContextInfo ( "oiF2kahH" + nameof ( TestCachedQuery_GetStationsAll ) , "sharee.bike.test" , new Version ( 3 , 0 , 267 ) ) ,
null /*UI language */ ,
cookieAndMail . Split ( ';' ) [ 0 ] ,
cookieAndMail . Split ( ';' ) [ 1 ] ,
2023-02-22 14:03:35 +01:00
expiresAfter : TimeSpan . FromSeconds ( 3 ) ) ; // See task #97 for need of custom expiresAfter value.
2022-09-06 16:08:19 +02:00
var start = DateTime . Now ;
var queryIndex = 1 ;
while ( DateTime . Now . Subtract ( start ) . TotalSeconds < 60 )
{
Log . ForContext < TestCachetimings > ( ) . Information ( $"Query #{queryIndex}" ) ;
var result = connector . Query . GetBikesAndStationsAsync ( ) . Result ;
2024-04-09 12:53:23 +02:00
Assert . That ( result . Exception , Is . Null , $"Exception message: {result.Exception?.Message}" ) ;
2022-09-06 16:08:19 +02:00
queryIndex + + ;
}
}
/// <remarks>
2024-04-09 12:53:23 +02:00
/// From COPRI version v4.1 switched from ShareeBike devel https://tinkwwp.copri-bike.de/APIjsonserver to sharee devel https://shareeapp-primary.copri-bike.de/APIjsonserver
2022-09-06 16:08:19 +02:00
/// </summary>
/// <param name="uri"></param>
/// <param name="cookieAndMail"></param>
[Test]
#if ! NOLIVESERVER
[Explicit("Run with care because this stress impact live system.")]
//[Category(TestCopriCallsHttps.CATEGORY_USESLIVESERVER)]
2021-06-26 20:57:55 +02:00
#elif ! NODEVELSERVER
[Category(TestCopriCallsHttps.CATEGORY_USESDEVELSERVER)]
#endif
2022-09-06 16:08:19 +02:00
public void TestCachedQuery_GetBikes (
2021-06-26 20:57:55 +02:00
#if NOLIVESERVER
[Values(CopriServerUriList.SHAREE_DEVEL)] string url ,
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)] string url ,
#else
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url ,
2021-06-26 20:57:55 +02:00
#endif
2022-09-06 16:08:19 +02:00
[Values(";", "6103_4da3044c8657a04ba60e2eaa753bc51a_;javaminister@gmail.com")] string cookieAndMail )
{
Barrel . ApplicationId = GetType ( ) . Name + nameof ( TestCachedQuery_GetBikes ) ;
Log . Logger = new LoggerConfiguration ( )
. MinimumLevel . ControlledBy ( new Serilog . Core . LoggingLevelSwitch ( Serilog . Events . LogEventLevel . Error ) )
. WriteTo . Debug ( )
. CreateLogger ( ) ;
var connector = ConnectorFactory . Create (
true , // Is connected
new Uri ( url ) ,
new AppContextInfo ( "oiF2kahH" + nameof ( TestCachedQuery_GetBikes ) , "sharee.bike.test" , new Version ( 3 , 0 , 267 ) ) ,
null /*UI language */ ,
cookieAndMail . Split ( ';' ) [ 0 ] ,
cookieAndMail . Split ( ';' ) [ 1 ] ,
2023-02-22 14:03:35 +01:00
expiresAfter : TimeSpan . FromSeconds ( 3 ) ) ; // See task #97 for need of custom expiresAfter value.
2022-09-06 16:08:19 +02:00
var start = DateTime . Now ;
var queryIndex = 1 ;
while ( DateTime . Now . Subtract ( start ) . TotalSeconds < 60 )
{
Log . ForContext < TestCachetimings > ( ) . Information ( $"Query #{queryIndex}" ) ;
var result = connector . Query . GetBikesAsync ( ) . Result ;
2024-04-09 12:53:23 +02:00
Assert . That ( result . Exception , Is . Null , $"Exception message: {result.Exception?.Message}" ) ;
2022-09-06 16:08:19 +02:00
queryIndex + + ;
}
}
[Test]
#if ! NOLIVESERVER
[Explicit("Run with care because this stress impact live system.")]
//[Category(TestCopriCallsHttps.CATEGORY_USESLIVESERVER)]
2021-06-26 20:57:55 +02:00
#elif ! NODEVELSERVER
[Category(TestCopriCallsHttps.CATEGORY_USESDEVELSERVER)]
#endif
2022-09-06 16:08:19 +02:00
public void TestCachedQuery_GetBikesOccupied (
2021-06-26 20:57:55 +02:00
#if NOLIVESERVER
[Values(CopriServerUriList.SHAREE_DEVEL)] string url ,
#elif NODEVELSERVER
[Values(CopriServerUriList.SHAREE_LIVE)] string url ,
#else
2022-09-06 16:08:19 +02:00
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url ,
2021-06-26 20:57:55 +02:00
#endif
2022-09-06 16:08:19 +02:00
[Values("6103_4da3044c8657a04ba60e2eaa753bc51a_;javaminister@gmail.com")] string cookieAndMail )
{
Barrel . ApplicationId = GetType ( ) . Name + nameof ( TestCachedQuery_GetBikes ) ;
Log . Logger = new LoggerConfiguration ( )
. MinimumLevel . ControlledBy ( new Serilog . Core . LoggingLevelSwitch ( Serilog . Events . LogEventLevel . Verbose ) )
. WriteTo . Debug ( )
. WriteTo . File ( $"Log{nameof(TestCachedQuery_GetBikes)}.log" )
. CreateLogger ( ) ;
var connector = ConnectorFactory . Create (
true , // Is connected
new Uri ( url ) ,
new AppContextInfo ( "oiF2kahH" + nameof ( TestCachedQuery_GetBikesOccupied ) , "sharee.bike.test" , new Version ( 3 , 0 , 267 ) ) ,
null /*UI language */ ,
cookieAndMail . Split ( ';' ) [ 0 ] ,
cookieAndMail . Split ( ';' ) [ 1 ] ,
2023-02-22 14:03:35 +01:00
expiresAfter : TimeSpan . FromSeconds ( 3 ) ) ; // See task #97 for need of custom expiresAfter value.
2022-09-06 16:08:19 +02:00
var start = DateTime . Now ;
var queryIndex = 1 ;
while ( DateTime . Now . Subtract ( start ) . TotalSeconds < 60 )
{
Log . ForContext < TestCachetimings > ( ) . Information ( $"Query #{queryIndex}" ) ;
var result = connector . Query . GetBikesOccupiedAsync ( ) . Result ;
2024-04-09 12:53:23 +02:00
Assert . That ( result . Exception , Is . Null , $"Exception message: {result.Exception?.Message}" ) ;
2022-09-06 16:08:19 +02:00
queryIndex + + ;
}
}
}
2021-06-26 20:57:55 +02:00
}