mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-20 03:56:29 +02:00
Code updated to 3.0.238
This commit is contained in:
parent
3302d80678
commit
9c6a1fa92b
257 changed files with 7763 additions and 2861 deletions
514
TestShareeLib/Model/Connector/TestCopriProviderHttps.cs
Normal file
514
TestShareeLib/Model/Connector/TestCopriProviderHttps.cs
Normal file
|
@ -0,0 +1,514 @@
|
|||
using MonkeyCache.FileStore;
|
||||
using Newtonsoft.Json;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCopriProviderHttps
|
||||
{
|
||||
private const string BIKESAVAILABLE = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""bikes"" : {},
|
||||
""response_state"" : ""OK"",
|
||||
""apiserver"" : ""https://app.tink-konstanz.de"",
|
||||
""authcookie"" : """",
|
||||
""response"" : ""bikes_available"",
|
||||
""bikes"" : {
|
||||
""2352"" : {
|
||||
""description"" : ""Cargo Long"",
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""1"",
|
||||
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
||||
""station"" : ""9""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
private const string BIKESOCCUPIED = @"{
|
||||
""authcookie"" : ""6103_f782a208d9399291ba8d086b5dcc2509_12345678"",
|
||||
""debuglevel"" : ""2"",
|
||||
""user_group"" : [ ""TINK"" ],
|
||||
""user_id"" : ""javaminister@gmail.com"",
|
||||
""response"" : ""user_bikes_occupied"",
|
||||
""response_state"" : ""OK"",
|
||||
""response_text"" : ""Die Liste der reservierten und gebuchten Fahrräder wurde erfolgreich geladen"",
|
||||
""apiserver"" : ""https://tinkwwp.copri-bike.de"",
|
||||
""bikes_occupied"" : {
|
||||
""89004"" : {
|
||||
""start_time"" : ""2018-01-27 17:33:00.989464+01"",
|
||||
""station"" : ""9"",
|
||||
""unit_price"" : ""2.00"",
|
||||
""tariff_description"": {
|
||||
""free_hours"" : ""0.5"",
|
||||
""name"" : ""TINK Tarif"",
|
||||
""max_eur_per_day"" : ""9.00""
|
||||
},
|
||||
""timeCode"" : ""2061"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""bike"" : ""4"",
|
||||
""total_price"" : ""20.00"",
|
||||
""state"" : ""requested"",
|
||||
""real_hours"" : ""66.05"",
|
||||
""bike_group"" : [ ""TINK"" ],
|
||||
""now_time"" : ""2018-01-30 11:36:45"",
|
||||
""request_time"" : ""2018-01-27 17:33:00.989464+01"",
|
||||
""computed_hours"" : ""10.0""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
private const string STATIONSALL = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""stations"" : {
|
||||
""5"" : {
|
||||
""station"" : ""5"",
|
||||
""bike_soll"" : ""0"",
|
||||
""bike_ist"" : ""7"",
|
||||
""station_group"" : [ ""TINK"" ],
|
||||
""gps"" : { ""latitude"": ""47.66756"", ""longitude"": ""9.16477"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : """"
|
||||
},
|
||||
""13"" : {
|
||||
""station"" : ""13"",
|
||||
""bike_soll"" : ""4"",
|
||||
""bike_ist"" : ""1"",
|
||||
""station_group"" : [ ""TINK"" ],
|
||||
""gps"" : { ""latitude"": ""47.657756"", ""longitude"": ""9.176084"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : """"
|
||||
},
|
||||
""30"" : {
|
||||
""station"" : ""30"",
|
||||
""bike_soll"" : ""5"",
|
||||
""bike_ist"" : ""0"",
|
||||
""station_group"" : [ ""TINK"", ""Konrad"" ],
|
||||
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
||||
""state"" : ""available"",
|
||||
""description"" : ""Test für Stadtradstation""
|
||||
}
|
||||
},
|
||||
""user_group"" : [ ""Konrad"", ""TINK"" ],
|
||||
""response_state"" : ""OK"",
|
||||
""authcookie"" : ""6103_f782a208d9399291ba8d086b5dcc2509_12345678"",
|
||||
""debuglevel"" : ""2"",
|
||||
""response"" : ""stations_all"",
|
||||
""user_id"" : ""javaminister@gmail.com"",
|
||||
""apiserver"" : ""https://tinkwwp.copri-bike.de""
|
||||
}";
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesAvailable_NotExpired()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer >();
|
||||
|
||||
cache.IsBikesAvailableExpired.Returns(false);
|
||||
cache.GetBikesAvailableAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123", // Merchant id
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"456", // cookie
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesAvailable();
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, bikes.Source.Name);
|
||||
Assert.IsNull(bikes.Exception);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesAvailable_ExpiredForceCache()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesAvailableExpired.Returns(true);
|
||||
cache.GetBikesAvailableAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesAvailable(true);
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, bikes.Source.Name);
|
||||
Assert.IsNull(bikes.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesAvailable_Expired()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesAvailableExpired.Returns(true);
|
||||
https.GetBikesAvailableAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesAvailable();
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps).Name, bikes.Source.Name);
|
||||
Assert.IsNull(bikes.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesAvailable_Exception()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesAvailableExpired.Returns(true);
|
||||
cache.GetBikesAvailableAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
https.GetBikesAvailableAsync().Returns<BikesAvailableResponse>(x => { throw new WebConnectFailureException("Bang...", new Exception()); });
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesAvailable();
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, bikes.Source.Name);
|
||||
Assert.AreEqual("Bang...", bikes.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied_NotExpired()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesOccupiedExpired.Returns(false);
|
||||
cache.GetBikesOccupiedAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"12345678", // Merchant id
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"f782a208d9399291ba8d086b5dcc2509", // Auth cookie
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesOccupied();
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes_occupied.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, bikes.Source.Name);
|
||||
Assert.IsNull(bikes.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied_ExpiredForceCache()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesOccupiedExpired.Returns(true);
|
||||
cache.GetBikesOccupiedAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"12345678", // Merchant id
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"f782a208d9399291ba8d086b5dcc2509", // Auth cookie
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesOccupied(true);
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes_occupied.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, bikes.Source.Name);
|
||||
Assert.IsNull(bikes.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied_Expired()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesOccupiedExpired.Returns(true);
|
||||
https.GetBikesOccupiedAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"12345678", // Merchant id
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"f782a208d9399291ba8d086b5dcc2509", // Auth cookie
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesOccupied();
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes_occupied.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps).Name, bikes.Source.Name);
|
||||
Assert.IsNull(bikes.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied_Exception()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsBikesOccupiedExpired.Returns(true);
|
||||
cache.GetBikesOccupiedAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
https.GetBikesOccupiedAsync().Returns<BikesReservedOccupiedResponse>(x => { throw new WebConnectFailureException("Bang...", new Exception()); });
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"12345678", // Merchant id
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"f782a208d9399291ba8d086b5dcc2509", // Auth cookie
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var bikes = await provider.GetBikesOccupied();
|
||||
|
||||
Assert.AreEqual(1, bikes.Response.bikes_occupied.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, bikes.Source.Name);
|
||||
Assert.AreEqual("Bang...", bikes.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_NotExpired()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsStationsExpired.Returns(false);
|
||||
cache.GetStationsAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123", // Merchant id
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"456", // cookie
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var stations = await provider.GetStations();
|
||||
|
||||
Assert.AreEqual(3, stations.Response.stations.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, stations.Source.Name);
|
||||
Assert.IsNull(stations.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_ExpiredForceCache()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsStationsExpired.Returns(true);
|
||||
cache.GetStationsAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var stations = await provider.GetStations(true);
|
||||
|
||||
Assert.AreEqual(3, stations.Response.stations.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, stations.Source.Name);
|
||||
Assert.IsNull(stations.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_Expired()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsStationsExpired.Returns(true);
|
||||
https.GetStationsAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var stations = await provider.GetStations();
|
||||
|
||||
Assert.AreEqual(3, stations.Response.stations.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps).Name, stations.Source.Name);
|
||||
Assert.IsNull(stations.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_Exception()
|
||||
{
|
||||
var cache = Substitute.For<ICopriCache>();
|
||||
var https = Substitute.For<ICopriServer>();
|
||||
|
||||
cache.IsStationsExpired.Returns(true);
|
||||
cache.GetStationsAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
https.GetStationsAsync().Returns<StationsAllResponse>(x => { throw new WebConnectFailureException("Bang...", new Exception()); });
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default",
|
||||
cacheServer: cache,
|
||||
httpsServer: https);
|
||||
|
||||
var stations = await provider.GetStations();
|
||||
|
||||
Assert.AreEqual(3, stations.Response.stations.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore).Name, stations.Source.Name);
|
||||
Assert.AreEqual("Bang...", stations.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Test_AddToCache_Stations()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Barrel.ApplicationId))
|
||||
{
|
||||
Barrel.ApplicationId = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
||||
}
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123456789",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default");
|
||||
|
||||
var stations = await provider.GetStations(true);
|
||||
Assert.AreEqual(0, stations.Response.stations.Count);
|
||||
|
||||
try
|
||||
{
|
||||
// Do not add if an excption occurred
|
||||
provider.AddToCache(new Result<StationsAllResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL), new System.Exception("Bang...")));
|
||||
stations = await provider.GetStations(true);
|
||||
Assert.AreEqual(0, stations.Response.stations.Count);
|
||||
|
||||
// Do not add if results from cache
|
||||
provider.AddToCache(new Result<StationsAllResponse>(typeof(CopriCallsMonkeyStore), JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
stations = await provider.GetStations(true);
|
||||
Assert.AreEqual(0, stations.Response.stations.Count);
|
||||
|
||||
// Add result
|
||||
provider.AddToCache(new Result<StationsAllResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
stations = await provider.GetStations(true);
|
||||
Assert.AreEqual(3, stations.Response.stations.Count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Barrel.Current.EmptyAll();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Test_AddToCache_BikesAvailable()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Barrel.ApplicationId))
|
||||
{
|
||||
Barrel.ApplicationId = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
||||
}
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123456789",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default");
|
||||
|
||||
var bikes = await provider.GetBikesAvailable(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes.Count);
|
||||
|
||||
try
|
||||
{
|
||||
// Do not add if an excption occurred
|
||||
provider.AddToCache(new Result<BikesAvailableResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE), new System.Exception("Bang...")));
|
||||
bikes = await provider.GetBikesAvailable(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes.Count);
|
||||
|
||||
// Do not add if results from cache
|
||||
provider.AddToCache(new Result<BikesAvailableResponse>(typeof(CopriCallsMonkeyStore), JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
bikes = await provider.GetBikesAvailable(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes.Count);
|
||||
|
||||
// Add result
|
||||
provider.AddToCache(new Result<BikesAvailableResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
bikes = await provider.GetBikesAvailable(true);
|
||||
Assert.AreEqual(1, bikes.Response.bikes.Count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Barrel.Current.EmptyAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task Test_AddToCache_BikesOccupied()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Barrel.ApplicationId))
|
||||
{
|
||||
Barrel.ApplicationId = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
||||
}
|
||||
|
||||
var provider = new CopriProviderHttps(
|
||||
new Uri("http://1.2.3.4"),
|
||||
"123456789",
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", // User agent
|
||||
"876");
|
||||
|
||||
var bikes = await provider.GetBikesOccupied(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes_occupied.Count);
|
||||
|
||||
try
|
||||
{
|
||||
// Do not add if an excption occurred
|
||||
provider.AddToCache(new Result<BikesReservedOccupiedResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED), new System.Exception("Bang...")));
|
||||
bikes = await provider.GetBikesOccupied(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes_occupied.Count);
|
||||
|
||||
// Do not add if results from cache
|
||||
provider.AddToCache(new Result<BikesReservedOccupiedResponse>(typeof(CopriCallsMonkeyStore), JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
bikes = await provider.GetBikesOccupied(true);
|
||||
Assert.AreEqual(0, bikes.Response.bikes_occupied.Count);
|
||||
|
||||
// Add result
|
||||
provider.AddToCache(new Result<BikesReservedOccupiedResponse>(typeof(CopriCallsHttps), JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
bikes = await provider.GetBikesOccupied(true);
|
||||
Assert.AreEqual(1, bikes.Response.bikes_occupied.Count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Barrel.Current.EmptyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue