mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 18:46:30 +01:00
128 lines
4.9 KiB
C#
128 lines
4.9 KiB
C#
using System.Threading.Tasks;
|
|
using Newtonsoft.Json;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using TINK.Repository;
|
|
using TINK.Repository.Response;
|
|
using TINK.Repository.Response.Stations;
|
|
|
|
namespace TestTINKLib.Fixtures.ObjectTests.Query
|
|
{
|
|
[TestFixture]
|
|
public class TestQuery
|
|
{
|
|
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""
|
|
}
|
|
}
|
|
}";
|
|
|
|
/// <summary>
|
|
/// Holds the response on stations_available request.
|
|
/// </summary>
|
|
/// <remarks> V1: Did not hold station_type entry.</remarks>
|
|
private const string STATIONSALLV2 = @"{
|
|
""copri_version"" : ""4.1.0.0"",
|
|
""stations"" : {
|
|
""9"" : {
|
|
""station"" : ""9"",
|
|
""bike_soll"" : ""0"",
|
|
""bike_ist"" : ""7"",
|
|
""station_group"" : [ ""TINK"" ],
|
|
""gps"" : { ""latitude"": ""47.66756"", ""longitude"": ""9.16477"" },
|
|
""state"" : ""available"",
|
|
""description"" : """",
|
|
""station_type"": {
|
|
""Cargobike"": {
|
|
""bike_count"": ""1"",
|
|
""bike_group"": ""TINK""
|
|
},
|
|
""Citybike"": {
|
|
""bike_count"": ""0"",
|
|
""bike_group"": ""FR300103""
|
|
}
|
|
}
|
|
},
|
|
""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 TestGetStations()
|
|
{
|
|
var server = Substitute.For<ICopriServer>();
|
|
|
|
server.GetStationsAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALLV2)));
|
|
|
|
var result = await new TINK.Model.Connector.Query(server).GetBikesAndStationsAsync();
|
|
|
|
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
|
Assert.AreEqual(1, result.Response.StationsAll["9"].BikeGroups.AvailableCount);
|
|
Assert.AreEqual(0, result.Response.BikesOccupied.Count);
|
|
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
|
Assert.IsNull(result.Exception);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestGetBikes()
|
|
{
|
|
var server = Substitute.For<ICopriServer>();
|
|
|
|
server.GetBikesAvailableAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
|
|
|
var result = await new TINK.Model.Connector.Query(server).GetBikesAsync();
|
|
|
|
Assert.AreEqual(1, result.Response.Count);
|
|
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
|
Assert.IsNull(result.Exception);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestGetBikesOccupied()
|
|
{
|
|
var server = Substitute.For<ICopriServer>();
|
|
|
|
var result = await new TINK.Model.Connector.Query(server).GetBikesOccupiedAsync();
|
|
|
|
Assert.AreEqual(0, result.Response.Count);
|
|
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
|
Assert.AreEqual(result.Exception.Message, "Abfrage der reservierten/ gebuchten Räder fehlgeschlagen. Kein Benutzer angemeldet.");
|
|
}
|
|
}
|
|
}
|