using ShareeBike.Repository.Response;
using ShareeBike.Repository;
using System.Linq;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
namespace SharedBusinessLogic.Tests.Framework.Repository
{
public static class CopriCallsHelper
{
///
/// Filters bikes available response by station.
///
///
///
///
public static BikesAvailableResponse FilterByStation(this BikesAvailableResponse bikes, string stationId)
{
if (string.IsNullOrEmpty(stationId))
{
// If filter is off there is nothing to filter.
return bikes;
}
var response = CopriCallsStatic.DeserializeResponse(
$"{{ \"{nameof(VersionindependentResponse.shareejson)}\" : {JsonConvert.SerializeObject(bikes)} }}");
response.bikes.Clear();
var allBikes = bikes.bikes.Values.Where(x => x.station == stationId).ToList();
foreach (var bike in allBikes)
{
response.bikes.Add(bike.bike, bike);
}
return response;
}
///
/// Filters bikes available response by station.
///
///
///
///
public static BikesAvailableResponse FilterByBike(this BikesAvailableResponse bikes, string bikeId)
{
if (string.IsNullOrEmpty(bikeId))
{
// If filter is off there is nothing to filter.
return bikes;
}
var response = CopriCallsStatic.DeserializeResponse(
$"{{ \"{nameof(VersionindependentResponse.shareejson)}\" : {JsonConvert.SerializeObject(bikes)} }}");
response.bikes.Clear();
var allBikes = bikes.bikes.Values.Where(x => Regex.IsMatch(x.bike, bikeId)).ToList();
foreach (var bike in allBikes)
{
response.bikes.Add(bike.bike, bike);
}
return response;
}
}
}