2022-08-30 15:42:25 +02:00
using System ;
2021-07-12 21:31:46 +02:00
using System.Collections.Generic ;
using System.Linq ;
2022-08-30 15:42:25 +02:00
using NUnit.Framework ;
2021-07-12 21:31:46 +02:00
using TINK.Repository ;
using TINK.Repository.Response ;
using static TINK . Repository . CopriCallsMemory ;
namespace TestTINKLib.Fixtures.Connector.Request
{
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestCopriCallsMemory
{
[Test]
public void TestConsistency ( )
{
foreach ( SampleSets l_oSampleSet in Enum . GetValues ( typeof ( SampleSets ) ) )
{
var l_oCopri = new CopriCallsMemory ( "MyMerchId" , l_oSampleSet , 1 , "4da3044c8657a04ba60e2eaa753bc51a" ) ;
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
for ( var l_iStageIndex = 1 ; l_iStageIndex < = l_oCopri . StagesCount ; l_iStageIndex + + )
{
Assert . That ( l_oCopri . GetBikesAvailableAsync ( ) . Result ? . bikes , Is . Not . Null , $"There must be at least one bike for sample set {l_oSampleSet}, stage {l_iStageIndex}." ) ;
VerifyBikeIdIsUnique ( l_oCopri ) ;
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert . IsNull (
l_oCopri . GetBikesAvailableAsync ( ) . Result . bikes . Values . FirstOrDefault ( x = > x . state ! = "available" ) ,
2023-04-05 15:02:10 +02:00
"Bikes available must end rentals which are all of state available." ) ;
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert . IsNull (
l_oCopri . GetBikesOccupiedAsync ( ) . Result . bikes_occupied . Values . FirstOrDefault ( x = > x . state = = "available" ) ,
2023-04-05 15:02:10 +02:00
"Bikes occupied must end rentals which are either reserved or booked." ) ;
2022-09-06 16:08:19 +02:00
}
}
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Test consistency for a single sample set,
/// </summary>
/// <param name="p_oMemory"></param>
private void VerifyBikeIdIsUnique ( CopriCallsMemory p_oMemory )
{
Dictionary < string , BikeInfoBase > l_oChecker = new Dictionary < string , BikeInfoBase > ( ) ;
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
var l_oBikesAvailable = p_oMemory . GetBikesAvailableAsync ( ) . Result ;
foreach ( var l_oBike in l_oBikesAvailable . bikes . Values )
{
Assert . IsFalse (
l_oChecker . Keys . Contains ( l_oBike . bike ) ,
string . Format (
"Bike form available bikes with id {0} already exist in dictionary. Sample set is {1}, stage index {2}." ,
l_oBike . bike ,
p_oMemory . ActiveSampleSet ,
p_oMemory . ActiveStageIndex ) ) ;
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
l_oChecker . Add ( l_oBike . bike , l_oBike ) ;
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
var l_oBikesOccupied = p_oMemory . GetBikesOccupiedAsync ( ) . Result ;
foreach ( var l_oBike in l_oBikesOccupied . bikes_occupied . Values )
{
Assert . IsFalse (
l_oChecker . Keys . Contains ( l_oBike . bike ) ,
string . Format (
"Bike from occupied bikes with id {0} already exist in dictionary. Sample set is {1}, stage index {2}." ,
l_oBike . bike ,
p_oMemory . ActiveSampleSet ,
p_oMemory . ActiveStageIndex ) ) ;
l_oChecker . Add ( l_oBike . bike , l_oBike ) ;
}
}
}
2021-07-12 21:31:46 +02:00
}