2023-04-05 15:02:10 +02:00
|
|
|
using System;
|
2022-08-30 15:42:25 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using NSubstitute;
|
2021-07-12 21:31:46 +02:00
|
|
|
using NUnit.Framework;
|
2024-04-09 12:53:23 +02:00
|
|
|
using ShareeBike.Model.Connector;
|
|
|
|
using ShareeBike.Repository;
|
|
|
|
using ShareeBike.Repository.Response;
|
|
|
|
using ShareeBike.Repository.Response.Stations;
|
2021-07-12 21:31:46 +02:00
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.Connector
|
2021-07-12 21:31:46 +02:00
|
|
|
{
|
2023-04-19 12:14:14 +02:00
|
|
|
[TestFixture]
|
2023-05-09 08:47:52 +02:00
|
|
|
public class TestQueryLoggedIn
|
|
|
|
{
|
|
|
|
private const string BIKESAVAILABLE = @"{
|
2021-07-12 21:31:46 +02:00
|
|
|
""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""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}";
|
|
|
|
|
2023-05-09 08:47:52 +02:00
|
|
|
private const string BIKESOCCUPIED = @"{
|
2022-01-04 18:54:03 +01:00
|
|
|
""copri_version"" : ""4.1.0.0"",
|
2021-07-12 21:31:46 +02:00
|
|
|
""authcookie"" : ""6103_f782a208d9399291ba8d086b5dcc2509_12345678"",
|
|
|
|
""debuglevel"" : ""2"",
|
2024-04-09 12:53:23 +02:00
|
|
|
""user_group"" : [ ""ShareeBike"" ],
|
2021-07-12 21:31:46 +02:00
|
|
|
""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"",
|
2024-04-09 12:53:23 +02:00
|
|
|
""name"" : ""ShareeBike Tarif"",
|
2021-07-12 21:31:46 +02:00
|
|
|
""max_eur_per_day"" : ""9.00""
|
|
|
|
},
|
|
|
|
""timeCode"" : ""2061"",
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
""bike"" : ""4"",
|
|
|
|
""total_price"" : ""20.00"",
|
|
|
|
""state"" : ""requested"",
|
|
|
|
""real_hours"" : ""66.05"",
|
2024-04-09 12:53:23 +02:00
|
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
2021-07-12 21:31:46 +02:00
|
|
|
""now_time"" : ""2018-01-30 11:36:45"",
|
|
|
|
""request_time"" : ""2018-01-27 17:33:00.989464+01"",
|
|
|
|
""computed_hours"" : ""10.0""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}";
|
|
|
|
|
2023-05-09 08:47:52 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Holds the response on stations_available request.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks> V1: Did not hold station_type entry.</remarks>
|
|
|
|
private const string STATIONSALLV2 = @"{
|
2021-07-12 21:31:46 +02:00
|
|
|
""copri_version"" : ""4.1.0.0"",
|
|
|
|
""stations"" : {
|
2023-05-09 08:47:52 +02:00
|
|
|
""9"" : {
|
|
|
|
""station"" : ""9"",
|
2021-07-12 21:31:46 +02:00
|
|
|
""bike_soll"" : ""0"",
|
|
|
|
""bike_ist"" : ""7"",
|
2024-04-09 12:53:23 +02:00
|
|
|
""station_group"" : [ ""ShareeBike"" ],
|
2021-07-12 21:31:46 +02:00
|
|
|
""gps"" : { ""latitude"": ""47.66756"", ""longitude"": ""9.16477"" },
|
|
|
|
""state"" : ""available"",
|
2023-05-09 08:47:52 +02:00
|
|
|
""description"" : """",
|
|
|
|
""station_type"": {
|
|
|
|
""Cargobike"": {
|
|
|
|
""bike_count"": ""1"",
|
2024-04-09 12:53:23 +02:00
|
|
|
""bike_group"": ""ShareeBike""
|
2023-05-09 08:47:52 +02:00
|
|
|
},
|
|
|
|
""Citybike"": {
|
|
|
|
""bike_count"": ""0"",
|
|
|
|
""bike_group"": ""FR300103""
|
|
|
|
}
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
},
|
|
|
|
""13"" : {
|
|
|
|
""station"" : ""13"",
|
|
|
|
""bike_soll"" : ""4"",
|
|
|
|
""bike_ist"" : ""1"",
|
2024-04-09 12:53:23 +02:00
|
|
|
""station_group"" : [ ""ShareeBike"" ],
|
2021-07-12 21:31:46 +02:00
|
|
|
""gps"" : { ""latitude"": ""47.657756"", ""longitude"": ""9.176084"" },
|
|
|
|
""state"" : ""available"",
|
|
|
|
""description"" : """"
|
|
|
|
},
|
|
|
|
""30"" : {
|
|
|
|
""station"" : ""30"",
|
|
|
|
""bike_soll"" : ""5"",
|
|
|
|
""bike_ist"" : ""0"",
|
2024-04-09 12:53:23 +02:00
|
|
|
""station_group"" : [ ""ShareeBike"", ""Citybike"" ],
|
2021-07-12 21:31:46 +02:00
|
|
|
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
|
|
|
""state"" : ""available"",
|
|
|
|
""description"" : ""Test für Stadtradstation""
|
|
|
|
}
|
2023-05-09 08:47:52 +02:00
|
|
|
},
|
|
|
|
""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"",
|
2024-04-09 12:53:23 +02:00
|
|
|
""name"" : ""ShareeBike Tarif"",
|
2023-05-09 08:47:52 +02:00
|
|
|
""max_eur_per_day"" : ""9.00""
|
|
|
|
},
|
|
|
|
""timeCode"" : ""2061"",
|
|
|
|
""description"" : ""Cargo Long"",
|
|
|
|
""bike"" : ""4"",
|
|
|
|
""total_price"" : ""20.00"",
|
|
|
|
""state"" : ""requested"",
|
|
|
|
""real_hours"" : ""66.05"",
|
2024-04-09 12:53:23 +02:00
|
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
2023-05-09 08:47:52 +02:00
|
|
|
""now_time"" : ""2018-01-30 11:36:45"",
|
|
|
|
""request_time"" : ""2018-01-27 17:33:00.989464+01"",
|
|
|
|
""computed_hours"" : ""10.0""
|
|
|
|
}
|
|
|
|
},
|
2024-04-09 12:53:23 +02:00
|
|
|
""user_group"" : [ ""Citybike"", ""ShareeBike"" ],
|
2021-07-12 21:31:46 +02:00
|
|
|
""response_state"" : ""OK"",
|
|
|
|
""authcookie"" : ""6103_f782a208d9399291ba8d086b5dcc2509_12345678"",
|
|
|
|
""debuglevel"" : ""2"",
|
|
|
|
""response"" : ""stations_all"",
|
|
|
|
""user_id"" : ""javaminister@gmail.com"",
|
|
|
|
""apiserver"" : ""https://tinkwwp.copri-bike.de""
|
|
|
|
}";
|
|
|
|
|
2023-05-09 08:47:52 +02:00
|
|
|
[Test]
|
|
|
|
public async Task TestGetStations()
|
|
|
|
{
|
|
|
|
var server = Substitute.For<ICopriServer>();
|
2021-07-12 21:31:46 +02:00
|
|
|
|
2023-05-09 08:47:52 +02:00
|
|
|
server.GetStationsAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<StationsAvailableResponse>(STATIONSALLV2)));
|
2021-07-12 21:31:46 +02:00
|
|
|
|
2023-05-09 08:47:52 +02:00
|
|
|
var result = await new QueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAndStationsAsync();
|
2021-07-12 21:31:46 +02:00
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(result.Response.StationsAll.Count, Is.EqualTo(3));
|
|
|
|
Assert.That(result.Response.StationsAll["9"].BikeGroups.AvailableCount, Is.EqualTo(1));
|
|
|
|
Assert.That(result.Response.BikesOccupied.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(result.Source, Is.EqualTo(typeof(CopriCallsMonkeyStore)));
|
|
|
|
Assert.That(result.Exception, Is.Null);
|
2023-05-09 08:47:52 +02:00
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
2023-05-09 08:47:52 +02:00
|
|
|
[Test]
|
2023-11-21 15:26:57 +01:00
|
|
|
public async Task TestGetBikesAsync()
|
2023-05-09 08:47:52 +02:00
|
|
|
{
|
|
|
|
var server = Substitute.For<ICopriServer>();
|
2021-07-12 21:31:46 +02:00
|
|
|
|
2023-11-21 15:26:57 +01:00
|
|
|
var bike = "MyBike";
|
|
|
|
|
|
|
|
server.GetBikesAvailableAsync(bikeId: bike).Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
2023-05-09 08:47:52 +02:00
|
|
|
server.GetBikesOccupiedAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
2021-07-12 21:31:46 +02:00
|
|
|
|
2023-11-21 15:26:57 +01:00
|
|
|
var result = await new QueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAsync(bikeId: bike);
|
2021-07-12 21:31:46 +02:00
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(result.Response.Count, Is.EqualTo(2));
|
|
|
|
Assert.That(result.Source, Is.EqualTo(typeof(CopriCallsMonkeyStore)));
|
|
|
|
Assert.That(result.Exception, Is.Null);
|
2023-11-21 15:26:57 +01:00
|
|
|
|
|
|
|
await server.Received().GetBikesAvailableAsync(bikeId: bike);
|
2023-05-09 08:47:52 +02:00
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
2023-05-09 08:47:52 +02:00
|
|
|
[Test]
|
2023-11-21 15:26:57 +01:00
|
|
|
public async Task TestGetBikesOccupiedAsync()
|
2023-05-09 08:47:52 +02:00
|
|
|
{
|
|
|
|
var server = Substitute.For<ICopriServer>();
|
2021-07-12 21:31:46 +02:00
|
|
|
|
2023-05-09 08:47:52 +02:00
|
|
|
server.GetBikesAvailableAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>("{}")));
|
2022-08-30 15:42:25 +02:00
|
|
|
|
2023-05-09 08:47:52 +02:00
|
|
|
server.GetBikesOccupiedAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
2021-07-12 21:31:46 +02:00
|
|
|
|
2023-05-09 08:47:52 +02:00
|
|
|
var result = await new QueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesOccupiedAsync();
|
2021-07-12 21:31:46 +02:00
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(result.Response.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(result.Source, Is.EqualTo(typeof(CopriCallsMonkeyStore)));
|
|
|
|
Assert.That(result.Exception, Is.Null);
|
2023-05-09 08:47:52 +02:00
|
|
|
}
|
2023-11-21 15:26:57 +01:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public async Task TestGetBikesAsyncOperatorUriNotNull()
|
|
|
|
{
|
|
|
|
var server = Substitute.For<ICopriServer>();
|
|
|
|
|
|
|
|
var responseBikesAvailable = JsonConvert.DeserializeObject<BikesAvailableResponse>(@"{
|
|
|
|
""bikes"" : {
|
|
|
|
""FR1011"" : {
|
|
|
|
""state"" : ""available"",
|
|
|
|
""bike"" : ""FR1011"",
|
|
|
|
""station"" : ""FR103"",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
""bikes_occupied"" : {
|
|
|
|
""160373"" : {
|
|
|
|
""bike"" : ""FR1012"",
|
|
|
|
""station"" : ""FR103"",
|
|
|
|
""state"" : ""occupied"",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}");
|
|
|
|
|
|
|
|
server.GetBikesAvailableAsync(Arg.Any<Uri>(), Arg.Any<string>()).Returns(responseBikesAvailable);
|
|
|
|
|
|
|
|
var uri = new Uri("https://shareeapp-fr01.copri.eu//");
|
|
|
|
var station = "FR101";
|
|
|
|
|
|
|
|
var result = await new QueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAsync(uri, station);
|
|
|
|
|
|
|
|
Assert.That(result.Response.Count, Is.EqualTo(2));
|
|
|
|
|
|
|
|
await server.Received().GetBikesAvailableAsync(
|
|
|
|
uri /* Uri is not null for use case show "bikes at station x" page */,
|
|
|
|
station);
|
|
|
|
await server.DidNotReceive().GetBikesOccupiedAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public async Task TestGetBikesAsyncOperatorUriNull()
|
|
|
|
{
|
|
|
|
var server = Substitute.For<ICopriServer>();
|
|
|
|
|
|
|
|
var responseBikesAvailable = JsonConvert.DeserializeObject<BikesAvailableResponse>(@"{
|
|
|
|
""bikes"" : {
|
|
|
|
""FR1011"" : {
|
|
|
|
""state"" : ""available"",
|
|
|
|
""bike"" : ""FR1011"",
|
|
|
|
""station"" : ""FR103"",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}");
|
|
|
|
|
|
|
|
var responseBikesOccupied = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(@"{
|
|
|
|
""bikes_occupied"" : {
|
|
|
|
""160373"" : {
|
|
|
|
""bike"" : ""FR1012"",
|
|
|
|
""station"" : ""FR103"",
|
|
|
|
""state"" : ""occupied"",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}");
|
|
|
|
|
|
|
|
server.GetBikesAvailableAsync().Returns(responseBikesAvailable);
|
|
|
|
server.GetBikesOccupiedAsync().Returns(responseBikesOccupied);
|
|
|
|
|
|
|
|
|
|
|
|
var result = await new QueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAsync();
|
|
|
|
|
|
|
|
Assert.That(result.Response.Count, Is.EqualTo(2));
|
|
|
|
|
|
|
|
await server.Received().GetBikesAvailableAsync();
|
|
|
|
await server.Received().GetBikesOccupiedAsync();
|
|
|
|
}
|
2023-05-09 08:47:52 +02:00
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
}
|