sharee.bike-App/TestShareeLib/Model/Connector/TestCachetimings.cs

164 lines
5.7 KiB
C#
Raw Normal View History

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;
using TINK.Model.Connector;
using TINK.Model.Services.CopriApi.ServerUris;
2022-01-04 18:54:03 +01:00
using TINK.Repository;
2021-06-26 20:57:55 +02:00
using UITest.Fixtures.Connector;
namespace TestTINKLib.Fixtures.Misc
{
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;
Assert.IsNull(result.Exception, $"Exception message: {result.Exception?.Message}");
queryIndex++;
}
}
/// <remarks>
/// From COPRI version v4.1 switched from TINK devel https://tinkwwp.copri-bike.de/APIjsonserver to sharee devel https://shareeapp-primary.copri-bike.de/APIjsonserver
/// </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;
Assert.IsNull(result.Exception, $"Exception message: {result.Exception?.Message}");
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;
Assert.IsNull(result.Exception, $"Exception message: {result.Exception?.Message}");
queryIndex++;
}
}
}
2021-06-26 20:57:55 +02:00
}