mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-06-26 08:36:36 +02:00
1252 lines
40 KiB
C#
1252 lines
40 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Newtonsoft.Json;
|
|
using NUnit.Framework;
|
|
using NUnit.Framework.Internal;
|
|
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
|
|
using ShareeBike.Model.Connector;
|
|
using ShareeBike.Repository.Exception;
|
|
using ShareeBike.Repository.Response;
|
|
using ShareeBike.Repository.Response.Stations.Station;
|
|
using JsonConvertRethrow = ShareeBike.Repository.Response.JsonConvertRethrow;
|
|
|
|
namespace SharedBusinessLogic.Tests.Fixtures.Connector
|
|
{
|
|
|
|
[TestFixture]
|
|
public class TestTextToTypeHelper
|
|
{
|
|
[Test]
|
|
public void TestGetWheelType_InvalidDescription()
|
|
{
|
|
var l_oInfo = new BikeInfoBase();
|
|
|
|
// Verify prerequisites
|
|
Assert.That(l_oInfo.description, Is.Null);
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(TextToTypeHelper.GetWheelType(l_oInfo), Is.Null);
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetWheelType()
|
|
{
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""bike"" : ""2"",
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
|
""description"" : ""Cargo Long"",
|
|
""bike_type"": {
|
|
""category"": ""cargo"",
|
|
""wheels"": ""2""
|
|
},
|
|
""gps"" : { ""latitude"": ""47.6612083333"", ""longitude"": ""9.16637533333"" },
|
|
""station"" : ""9"",
|
|
""state"" : ""available""
|
|
}");
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(TextToTypeHelper.GetWheelType(l_oInfo), Is.EqualTo(WheelType.Two));
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""bike"" : ""11"",
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
|
""description"" : ""Cargo Trike"",
|
|
""bike_type"": {
|
|
""category"": ""cargo"",
|
|
""wheels"": ""3""
|
|
},
|
|
""gps"" : { ""latitude"": ""47.665051"", ""longitude"": ""9.174096"" },
|
|
""station"" : ""1"",
|
|
""state"" : ""available""
|
|
}");
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(TextToTypeHelper.GetWheelType(l_oInfo), Is.EqualTo(WheelType.Trike));
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""bike"" : ""51"",
|
|
""bike_group"" : [ ""Citybike"" ],
|
|
""description"" : ""Demo Stadtrad"",
|
|
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
|
""station"" : ""8"",
|
|
""state"" : ""available""
|
|
}");
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(TextToTypeHelper.GetWheelType(l_oInfo), Is.Null); // Was WheelType.Two up to 3.0.322
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""bike"" : ""51"",
|
|
""bike_group"" : [ ""Citybike"" ],
|
|
""description"" : ""Stadtrad"",
|
|
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
|
""station"" : ""8"",
|
|
""state"" : ""available""
|
|
}");
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(TextToTypeHelper.GetWheelType(l_oInfo), Is.Null); // Was WheelType.Two up to 3.0.322
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetTypeOfBike_InvalidDescription()
|
|
{
|
|
var l_oInfo = new BikeInfoBase();
|
|
|
|
// Verify prerequisites
|
|
Assert.That(l_oInfo.description, Is.Null);
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(TextToTypeHelper.GetTypeOfBike(l_oInfo), Is.Null);
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetTypeOfBike()
|
|
{
|
|
var info = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""bike"" : ""2"",
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
|
""description"" : ""Cargo Long"",
|
|
""bike_type"": {
|
|
""category"": ""cargo"",
|
|
""wheels"": ""2""
|
|
},
|
|
""gps"" : { ""latitude"": ""47.6612083333"", ""longitude"": ""9.16637533333"" },
|
|
""station"" : ""9"",
|
|
""state"" : ""available""
|
|
}");
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(TextToTypeHelper.GetTypeOfBike(info), Is.EqualTo(TypeOfBike.Cargo));
|
|
|
|
info = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""bike"" : ""11"",
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
|
""description"" : ""Cargo Trike"",
|
|
""bike_type"": {
|
|
""category"": ""cargo"",
|
|
""wheels"": ""2""
|
|
},
|
|
""gps"" : { ""latitude"": ""47.665051"", ""longitude"": ""9.174096"" },
|
|
""station"" : ""1"",
|
|
""state"" : ""available""
|
|
}");
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(TextToTypeHelper.GetTypeOfBike(info), Is.EqualTo(TypeOfBike.Cargo));
|
|
|
|
info = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""bike"" : ""51"",
|
|
""bike_group"" : [ ""Citybike"" ],
|
|
""description"" : ""Demo Stadtrad"",
|
|
""bike_type"": {
|
|
""category"": ""city"",
|
|
""wheels"": ""2""
|
|
},
|
|
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
|
""station"" : ""8"",
|
|
""state"" : ""available""
|
|
}");
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(TextToTypeHelper.GetTypeOfBike(info), Is.EqualTo(TypeOfBike.City));
|
|
|
|
info = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""bike"" : ""51"",
|
|
""bike_group"" : [ ""Citybike"" ],
|
|
""description"" : ""Stadtrad"",
|
|
""bike_type"": {
|
|
},
|
|
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
|
""station"" : ""8"",
|
|
""state"" : ""available""
|
|
}");
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(
|
|
TextToTypeHelper.GetTypeOfBike(info),
|
|
Is.Null); // Version up to 3.0.322 considered this bike to be a city bike to to description "Stadtrad"
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetAaRideTypeNoAa() =>
|
|
Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""aa_ride"": ""0"",
|
|
}").GetAaRideType(),
|
|
Is.EqualTo(AaRideType.NoAaRide));
|
|
|
|
[Test]
|
|
public void TestGetAaRideTypeAa() =>
|
|
Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""aa_ride"": ""1"",
|
|
}").GetAaRideType(),
|
|
Is.EqualTo(AaRideType.AaRide));
|
|
|
|
[Test]
|
|
public void TestGetAaRideTypeNull() =>
|
|
Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
}").GetAaRideType(),
|
|
Is.Null);
|
|
|
|
[Test]
|
|
public void TestGetStateAvailable()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"available\" }").GetState(),
|
|
Is.EqualTo(ShareeBike.Model.State.InUseStateEnum.Disposable));
|
|
|
|
[Test]
|
|
public void TestGetStateAvailableCase()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"availablE \" }").GetState(),
|
|
Is.EqualTo(ShareeBike.Model.State.InUseStateEnum.Disposable));
|
|
|
|
[Test]
|
|
public void TestGetStateReserved()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"requested\" }").GetState(),
|
|
Is.EqualTo(ShareeBike.Model.State.InUseStateEnum.Reserved));
|
|
|
|
[Test]
|
|
public void TestGetStateReservedCase()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \" reQuested\" }").GetState(),
|
|
Is.EqualTo(ShareeBike.Model.State.InUseStateEnum.Reserved));
|
|
|
|
[Test]
|
|
public void TestGetStateOccupied()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"occupied\" }").GetState(),
|
|
Is.EqualTo(ShareeBike.Model.State.InUseStateEnum.Booked));
|
|
|
|
[Test]
|
|
public void TestGetStateOccupiedCase()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"occuPied\" }").GetState(),
|
|
Is.EqualTo(ShareeBike.Model.State.InUseStateEnum.Booked));
|
|
|
|
[Test]
|
|
public void TestGetStateBikeInfoAvailableDisposable()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ \"state\" : \"available\" }").GetState(),
|
|
Is.EqualTo(ShareeBike.Model.State.InUseStateEnum.Disposable));
|
|
[Test]
|
|
public void TestGetStateBikeInfoAvailableFeedbackPending()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ \"state\" : \"available\", \"co2saving\" : \"\" }").GetState(),
|
|
Is.EqualTo(ShareeBike.Model.State.InUseStateEnum.FeedbackPending));
|
|
|
|
[Test]
|
|
public void TestGetState_InvalidDescription()
|
|
{
|
|
var info = new BikeInfoBase();
|
|
|
|
// Verify prerequisites
|
|
Assert.That(info.state, Is.Null);
|
|
|
|
// Verify behavior of member.
|
|
Assert.Throws<InvalidResponseException<BikeInfoBase>>(() => TextToTypeHelper.GetState(info));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetIsDemo()
|
|
{
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""bike"" : ""2"",
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
|
""description"" : ""Cargo Long"",
|
|
""gps"" : { ""latitude"": ""47.6612083333"", ""longitude"": ""9.16637533333"" },
|
|
""station"" : ""9"",
|
|
""state"" : ""available""
|
|
}");
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(TextToTypeHelper.GetIsDemo(l_oInfo), Is.False);
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""bike"" : ""11"",
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
|
""description"" : ""Cargo Trike"",
|
|
""gps"" : { ""latitude"": ""47.665051"", ""longitude"": ""9.174096"" },
|
|
""station"" : ""1"",
|
|
""state"" : ""available""
|
|
}");
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(TextToTypeHelper.GetIsDemo(l_oInfo), Is.False);
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""bike"" : ""51"",
|
|
""bike_group"" : [ ""Citybike"" ],
|
|
""description"" : ""Demo Stadtrad"",
|
|
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
|
""station"" : ""8"",
|
|
""state"" : ""available""
|
|
}");
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(TextToTypeHelper.GetIsDemo(l_oInfo), Is.True);
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
|
{
|
|
""bike"" : ""51"",
|
|
""bike_group"" : [ ""Citybike"" ],
|
|
""description"" : ""Stadtrad"",
|
|
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
|
""station"" : ""8"",
|
|
""state"" : ""available""
|
|
}");
|
|
|
|
// Verify behavior of member.
|
|
Assert.That(TextToTypeHelper.GetIsDemo(l_oInfo), Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetPosition()
|
|
{
|
|
Assert.That(TextToTypeHelper.GetPosition(JsonConvert.DeserializeObject<Position>("{ \"latitude\" : \"1.234\", \"longitude\" : \"5.678\"}")).Latitude, Is.EqualTo(1.234d));
|
|
Assert.That(TextToTypeHelper.GetPosition(JsonConvert.DeserializeObject<Position>("{ \"latitude\" : \"1.234\", \"longitude\" : \"5.678\"}")).Longitude, Is.EqualTo(5.678d));
|
|
}
|
|
|
|
[Test]
|
|
public void TestMapSpan()
|
|
{
|
|
var response = JsonConvertRethrow.DeserializeObject<ResponseBase>(@"
|
|
{
|
|
""init_map"": {
|
|
""radius"": ""2.9"",
|
|
""center"": {
|
|
""longitude"": ""7.825490"",
|
|
""latitude"": ""47.976634""
|
|
}
|
|
}
|
|
}");
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetMapSpan(response.init_map).Radius,
|
|
Is.EqualTo(2.9));
|
|
}
|
|
|
|
[Test]
|
|
public void TestMapSpan_EmptyRadius()
|
|
{
|
|
var response = JsonConvertRethrow.DeserializeObject<ResponseBase>(@"
|
|
{
|
|
""init_map"": {
|
|
""radius"": """",
|
|
""center"": {
|
|
""longitude"": ""7.825490"",
|
|
""latitude"": ""47.976634""
|
|
}
|
|
}
|
|
}");
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetMapSpan(response.init_map).IsValid,
|
|
Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void TestMapSpan_EmptyPos()
|
|
{
|
|
var response = JsonConvertRethrow.DeserializeObject<ResponseBase>(@"
|
|
{
|
|
""init_map"": {
|
|
""radius"": """",
|
|
""center"": {
|
|
""longitude"": """",
|
|
""latitude"": ""47.976634""
|
|
}
|
|
}
|
|
}");
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetMapSpan(response.init_map).IsValid,
|
|
Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void TestMapSpan_Empty()
|
|
{
|
|
var response = JsonConvertRethrow.DeserializeObject<ResponseBase>(@"
|
|
{
|
|
}");
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetMapSpan(response.init_map).IsValid,
|
|
Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetStationGroup_Invalid()
|
|
{
|
|
var l_oStation = JsonConvertRethrow.DeserializeObject<StationInfo>(
|
|
@"{
|
|
""station"" : ""4"",
|
|
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" }
|
|
}");
|
|
|
|
// From COPRI version v4.1 no more exception thrown.
|
|
Assert.That(l_oStation.GetGroup().Count(), Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetStationGroup_ShareeBike()
|
|
{
|
|
var l_oStation = JsonConvertRethrow.DeserializeObject<StationInfo>(
|
|
@"{
|
|
""station"" : ""4"",
|
|
""station_group"" : [ ""ShareeBike"" ],
|
|
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" }
|
|
}");
|
|
|
|
Assert.That(string.Join(",", l_oStation.GetGroup().ToArray()), Is.EqualTo("ShareeBike"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetStationGroup_ShareeBikeAndCitybike()
|
|
{
|
|
var l_oStation = JsonConvertRethrow.DeserializeObject<StationInfo>(
|
|
@"{
|
|
""station"" : ""4"",
|
|
""station_group"": [ ""ShareeBike"", ""Citybike"" ],
|
|
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" }
|
|
}");
|
|
|
|
Assert.That(string.Join(",", l_oStation.GetGroup().ToArray()), Is.EqualTo("ShareeBike,Citybike"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetBikeGroup_ShareeBike()
|
|
{
|
|
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
|
@"{
|
|
""state"" : ""available"",
|
|
""bike"" : ""18"",
|
|
""description"" : ""Cargo Long"",
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
|
""station"" : ""13"",
|
|
}");
|
|
|
|
Assert.That(string.Join(",", l_oBike.GetGroup().ToArray()), Is.EqualTo("ShareeBike"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetBikeGroup_ShareeBikeCopri()
|
|
{
|
|
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
|
@"{
|
|
""state"" : ""available"",
|
|
""bike"" : ""18"",
|
|
""description"" : ""Cargo Long"",
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
|
""system"" : ""BC"",
|
|
""station"" : ""13"",
|
|
}");
|
|
|
|
Assert.That(string.Join(",", l_oBike.GetGroup().ToArray()), Is.EqualTo("ShareeBike"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetBikeGroup_ShareeBikeSMS()
|
|
{
|
|
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
|
@"{
|
|
""state"" : ""available"",
|
|
""bike"" : ""18"",
|
|
""description"" : ""Cargo Long"",
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
|
""system"" : ""Lock"",
|
|
""station"" : ""13"",
|
|
}");
|
|
|
|
Assert.That(string.Join(",", l_oBike.GetGroup().ToArray()), Is.EqualTo("ShareeBike"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetBikeGroup_Citybike()
|
|
{
|
|
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
|
@"{
|
|
""state"" : ""available"",
|
|
""bike"" : ""18"",
|
|
""description"" : ""Cargo Long"",
|
|
""bike_group"" : [ ""Citybike"" ],
|
|
""station"" : ""13"",
|
|
}");
|
|
|
|
Assert.That(string.Join(",", l_oBike.GetGroup().ToArray()), Is.EqualTo("Citybike"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetBikeGroup_Null()
|
|
{
|
|
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
|
@"{
|
|
""state"" : ""available"",
|
|
""bike"" : ""18"",
|
|
""description"" : ""Cargo Long"",
|
|
""station"" : ""13"",
|
|
}");
|
|
|
|
Assert.That(l_oBike.GetGroup().ToArray().Length, Is.EqualTo(0));
|
|
}
|
|
[Test]
|
|
public void TestGetAuthGroup()
|
|
{
|
|
// User group was of format [ ""ShareeBike"", ""Citybike"" ] in early day...
|
|
// Since COPRI 4.1 use group is no more used.
|
|
// Groups are of format <OperatorId>_<BikeType> for this user group would be like below if it would be used.
|
|
var response = JsonConvertRethrow.DeserializeObject<AuthorizationResponse>(@"
|
|
{
|
|
""response"" : ""authorization"",
|
|
""authcookie"" : ""4da3044c8657a04ba60e2eaa753bc51a"",
|
|
""user_group"" : [ ""KN_300102"", ""KN_300101"" ],
|
|
""response_state"" : ""OK"",
|
|
""apiserver"" : ""https://tinkwwp.copri-bike.de""
|
|
}");
|
|
|
|
Assert.That(response.GetGroup().ToList().Count, Is.EqualTo(2));
|
|
Assert.That(response.GetGroup().ToList()[0], Is.EqualTo($"KN_300102"));
|
|
Assert.That(response.GetGroup().ToList()[1], Is.EqualTo($"KN_300101"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetGroupString()
|
|
{
|
|
// From COPRI version v4.1 no more exception thrown.
|
|
Assert.That(TextToTypeHelper.GetGroup(new string[0]).Count(), Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetGroupString_Null()
|
|
{
|
|
// From COPRI version v4.1 no more exception thrown.
|
|
Assert.That(TextToTypeHelper.GetGroup((string[])null).Count(), Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetGroupString_Roundtrip()
|
|
{
|
|
Assert.That(TextToTypeHelper.GetGroup(TextToTypeHelper.GetGroup(new[] { "Tunk", "Unk" })), Is.EqualTo("Tunk,Unk"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetUserKey()
|
|
{
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
|
{
|
|
""total_price"": ""0.00"",
|
|
""gps"" : { ""latitude"": ""47.6586133"", ""longitude"": ""9.16864"" },
|
|
""unit_price"": ""3.00"",
|
|
""K_u"": ""[99, 104, 120, 121, 63, 99, -10, -110, 94, 70, 15, -112, -6, 101, 117, -90, -113, -54, -90, -95, 0, 0, 0, 0]"",
|
|
""tariff_description"": {""name"" : ""ShareeBike Basic""},
|
|
""end_time"": ""2020-04-07 16:55:18"",
|
|
""K_seed"": ""[-18, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
|
""system"": ""Ilockit"",
|
|
""bike"": ""16"",
|
|
""computed_hours"": ""0"",
|
|
""request_time"": ""2020-04-07 16:55:06.823436+02"",
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
|
""K_a"": ""[-19, 29, -60, 29, 35, -121, -69, 93, 27, -122, 107, -127, -30, 74, 82, 12, 4, -20, 40, 16, 0, 0, 0, 0]"",
|
|
""state"": ""occupied"",
|
|
""real_hours"": ""0"",
|
|
""station"" : ""7"",
|
|
""start_time"": ""2020-04-07 16:55:17.786551+02"",
|
|
""description"": ""Cargo Long""
|
|
}");
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetUserKey(l_oInfo)[0], Is.EqualTo(99));
|
|
Assert.That(
|
|
TextToTypeHelper.GetUserKey(l_oInfo)[1], Is.EqualTo(104));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetAdminKey()
|
|
{
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
|
{
|
|
""total_price"": ""0.00"",
|
|
""gps"" : { ""latitude"": ""47.6586133"", ""longitude"": ""9.16864"" },
|
|
""unit_price"": ""3.00"",
|
|
""K_u"": ""[99, 104, 120, 121, 63, 99, -10, -110, 94, 70, 15, -112, -6, 101, 117, -90, -113, -54, -90, -95, 0, 0, 0, 0]"",
|
|
""tariff_description"": {""name"" : ""ShareeBike Basic""},
|
|
""end_time"": ""2020-04-07 16:55:18"",
|
|
""K_seed"": ""[-18, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
|
""system"": ""Ilockit"",
|
|
""bike"": ""16"",
|
|
""computed_hours"": ""0"",
|
|
""request_time"": ""2020-04-07 16:55:06.823436+02"",
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
|
""K_a"": ""[-19, 29, -60, 29, 35, -121, -69, 93, 27, -122, 107, -127, -30, 74, 82, 12, 4, -20, 40, 16, 0, 0, 0, 0]"",
|
|
""state"": ""occupied"",
|
|
""real_hours"": ""0"",
|
|
""station"" : ""7"",
|
|
""start_time"": ""2020-04-07 16:55:17.786551+02"",
|
|
""description"": ""Cargo Long""
|
|
}");
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetAdminKey(l_oInfo)[0], Is.EqualTo(237));
|
|
Assert.That(
|
|
TextToTypeHelper.GetAdminKey(l_oInfo)[1], Is.EqualTo(29));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetSeed()
|
|
{
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
|
{
|
|
""total_price"": ""0.00"",
|
|
""gps"" : { ""latitude"": ""47.6586133"", ""longitude"": ""9.16864"" },
|
|
""unit_price"": ""3.00"",
|
|
""K_u"": ""[99, 104, 120, 121, 63, 99, -10, -110, 94, 70, 15, -112, -6, 101, 117, -90, -113, -54, -90, -95, 0, 0, 0, 0]"",
|
|
""tariff_description"": {""name"" : ""ShareeBike Basic""},
|
|
""end_time"": ""2020-04-07 16:55:18"",
|
|
""K_seed"": ""[-18, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
|
""system"": ""Ilockit"",
|
|
""bike"": ""16"",
|
|
""computed_hours"": ""0"",
|
|
""request_time"": ""2020-04-07 16:55:06.823436+02"",
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
|
""K_a"": ""[-19, 29, -60, 29, 35, -121, -69, 93, 27, -122, 107, -127, -30, 74, 82, 12, 4, -20, 40, 16, 0, 0, 0, 0]"",
|
|
""state"": ""occupied"",
|
|
""real_hours"": ""0"",
|
|
""station"" : ""7"",
|
|
""start_time"": ""2020-04-07 16:55:17.786551+02"",
|
|
""description"": ""Cargo Long""
|
|
}");
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetSeed(l_oInfo)[0], Is.EqualTo(238));
|
|
Assert.That(
|
|
TextToTypeHelper.GetSeed(l_oInfo)[1], Is.EqualTo(176));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetSeedUserKeyAdminKey_Invalid()
|
|
{
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
|
{
|
|
""total_price"": ""0.00"",
|
|
""gps"" : { ""latitude"": ""47.6586133"", ""longitude"": ""9.16864"" },
|
|
""unit_price"": ""3.00"",
|
|
""K_u"": ""[]"",
|
|
""tariff_description"": {""name"" : ""ShareeBike Basic""},
|
|
""end_time"": ""2020-04-07 16:55:18"",
|
|
""K_seed"": ""[-18a, -80, 20, -90, 3, 69, 96, 4, -35, 75, -95, 102, 7, 121, -122, 15]"",
|
|
""system"": ""Ilockit"",
|
|
""bike"": ""16"",
|
|
""computed_hours"": ""0"",
|
|
""request_time"": ""2020-04-07 16:55:06.823436+02"",
|
|
""bike_group"" : [ ""ShareeBike"" ],
|
|
""K_a"": ""{-19, 29, -60, 29, 35, -121, -69, 93, 27, -122, 107, -127, -30, 74, 82, 12, 4, -20, 40, 16, 0, 0, 0, 0}"",
|
|
""state"": ""occupied"",
|
|
""real_hours"": ""0"",
|
|
""station"" : ""7"",
|
|
""start_time"": ""2020-04-07 16:55:17.786551+02"",
|
|
""description"": ""Cargo Long""
|
|
}");
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetSeed(l_oInfo).Length, Is.EqualTo(0));
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetUserKey(l_oInfo).Length, Is.EqualTo(0));
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetAdminKey(l_oInfo).Length, Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetBluetoothLockId_FromBikeInfo_Invalid()
|
|
{
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
|
{
|
|
}");
|
|
|
|
Assert.That(TextToTypeHelper.GetBluetoothLockId(l_oInfo), Is.EqualTo(0));
|
|
|
|
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
|
{
|
|
""Ilockit_ID"": """"
|
|
}");
|
|
|
|
Assert.That(TextToTypeHelper.GetBluetoothLockId(l_oInfo), Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetBluetoothLockId_FromBikeInfo()
|
|
{
|
|
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
|
{
|
|
""Ilockit_ID"": ""ISHAREIT-132""
|
|
}");
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetBluetoothLockId(l_oInfo), Is.EqualTo(132));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetBluetoothLockId_FromString_Invalid()
|
|
{
|
|
Assert.That(TextToLockItTypeHelper.GetBluetoothLockId((string)null), Is.EqualTo(0));
|
|
Assert.That(TextToLockItTypeHelper.GetBluetoothLockId(""), Is.EqualTo(0));
|
|
|
|
Assert.That(TextToLockItTypeHelper.GetBluetoothLockId("HubbaBubba"), Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetBluetoothLockId_FromString()
|
|
{
|
|
Assert.That(
|
|
TextToLockItTypeHelper.GetBluetoothLockId("ISHAREIT-132"), Is.EqualTo(132));
|
|
|
|
Assert.That(
|
|
TextToLockItTypeHelper.GetBluetoothLockId("ISHAREIT+132"), Is.EqualTo(132));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetCopriVersion()
|
|
{
|
|
var version = JsonConvertRethrow.DeserializeObject<CopriVersion>(@"
|
|
{
|
|
""copri_version"": ""4.3.2.1""
|
|
}");
|
|
|
|
Assert.That(
|
|
version.GetCopriVersion(),
|
|
Is.EqualTo(new Version(4, 3, 2, 1)));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetCopriVersion_Invald()
|
|
{
|
|
var version = JsonConvertRethrow.DeserializeObject<CopriVersion>(@"
|
|
{
|
|
""copri_version"": ""hellO""
|
|
}");
|
|
|
|
Assert.That(
|
|
() => version.GetCopriVersion(),
|
|
Throws.InstanceOf<InvalidResponseException>());
|
|
}
|
|
|
|
|
|
[Test]
|
|
public void TestGetCopriVersion_Null()
|
|
{
|
|
|
|
Assert.That(
|
|
() => TextToTypeHelper.GetCopriVersion(null),
|
|
Throws.InstanceOf<InvalidResponseException>());
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetCopriVersion_NotContained()
|
|
{
|
|
var version = JsonConvertRethrow.DeserializeObject<CopriVersion>(@"
|
|
{
|
|
}");
|
|
|
|
Assert.That(
|
|
() => version.GetCopriVersion(),
|
|
Throws.InstanceOf<InvalidResponseException>());
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetIsAgbAcknowledged()
|
|
{
|
|
var response = JsonConvertRethrow.DeserializeObject<AuthorizationResponse>(@"
|
|
{
|
|
""agb_checked"" : ""1""
|
|
}");
|
|
|
|
Assert.That(
|
|
() => response.GetIsAgbAcknowledged(),
|
|
Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetIsAgbAcknowledged_No()
|
|
{
|
|
var response = JsonConvertRethrow.DeserializeObject<AuthorizationResponse>(@"
|
|
{
|
|
""agb_checked"" : ""0""
|
|
}");
|
|
|
|
Assert.That(
|
|
() => response.GetIsAgbAcknowledged(),
|
|
Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetIsAgbAcknowledged_Invalid()
|
|
{
|
|
var response = JsonConvertRethrow.DeserializeObject<AuthorizationResponse>(@"
|
|
{
|
|
""agb_checked"" : ""ä""
|
|
}");
|
|
|
|
Assert.That(
|
|
() => response.GetIsAgbAcknowledged(),
|
|
Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetIsAgbAcknowledged_Empty()
|
|
{
|
|
var response = JsonConvertRethrow.DeserializeObject<AuthorizationResponse>(@"
|
|
{
|
|
}");
|
|
|
|
Assert.That(
|
|
() => response.GetIsAgbAcknowledged(),
|
|
Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetLockModelBluetooth()
|
|
{
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
@"{
|
|
""description"" : ""Cargo Long"",
|
|
""state"" : ""available"",
|
|
""bike"" : ""1"",
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
""station"" : ""9"",
|
|
""system"" : ""Ilockit""
|
|
}");
|
|
Assert.That(
|
|
response.GetLockModel(),
|
|
Is.EqualTo(LockModel.ILockIt));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetLockModelSigo()
|
|
{
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
@"{
|
|
""description"" : ""Cargo Long"",
|
|
""state"" : ""available"",
|
|
""bike"" : ""1"",
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
""station"" : ""9"",
|
|
""system"" : ""SIGO""
|
|
}");
|
|
Assert.That(
|
|
response.GetLockModel(),
|
|
Is.EqualTo(LockModel.Sigo));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetLockModelBordComputer()
|
|
{
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
@"{
|
|
""description"" : ""Cargo Long"",
|
|
""state"" : ""available"",
|
|
""bike"" : ""1"",
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
""station"" : ""9"",
|
|
""system"" : ""LOCK""
|
|
}");
|
|
Assert.That(
|
|
response.GetLockModel(),
|
|
Is.EqualTo(LockModel.BordComputer));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetLockModelUnknown()
|
|
{
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
@"{
|
|
""description"" : ""Cargo Long"",
|
|
""state"" : ""available"",
|
|
""bike"" : ""1"",
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
""station"" : ""9"",
|
|
""system"" : """"
|
|
}");
|
|
Assert.That(
|
|
response.GetLockModel(),
|
|
Is.Null);
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetCopriLockingStateClosed()
|
|
{
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
@"{
|
|
""description"" : ""Cargo Long"",
|
|
""state"" : ""available"",
|
|
""bike"" : ""1"",
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
""station"" : ""9"",
|
|
""system"" : """",
|
|
""lock_state"" : ""locked""
|
|
}");
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetCopriLockingState(response),
|
|
Is.EqualTo(ShareeBike.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Closed));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetCopriLockingStateClosing()
|
|
{
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
@"{
|
|
""description"" : ""Cargo Long"",
|
|
""state"" : ""available"",
|
|
""bike"" : ""1"",
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
""station"" : ""9"",
|
|
""system"" : """",
|
|
""lock_state"" : ""locking""
|
|
}");
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetCopriLockingState(response),
|
|
Is.EqualTo(ShareeBike.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Closing));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetCopriLockingStateOpen()
|
|
{
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
@"{
|
|
""description"" : ""Cargo Long"",
|
|
""state"" : ""available"",
|
|
""bike"" : ""1"",
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
""station"" : ""9"",
|
|
""system"" : """",
|
|
""lock_state"" : ""unlocked""
|
|
}");
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetCopriLockingState(response),
|
|
Is.EqualTo(ShareeBike.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Open));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetCopriLockingStateOpening()
|
|
{
|
|
var response = JsonConvert.DeserializeObject<BikeInfoBase>(
|
|
@"{
|
|
""description"" : ""Cargo Long"",
|
|
""state"" : ""available"",
|
|
""bike"" : ""1"",
|
|
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
|
|
""station"" : ""9"",
|
|
""system"" : """",
|
|
""lock_state"" : ""unlocking""
|
|
}");
|
|
|
|
Assert.That(
|
|
TextToTypeHelper.GetCopriLockingState(response),
|
|
Is.EqualTo(ShareeBike.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Opening));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetIsFeedbackPendingIsPendingValue()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ \"co2saving\" : \"Tonns\" }").GetIsFeedbackPending(),
|
|
Is.True);
|
|
|
|
[Test]
|
|
public void TestGetIsFeedbackPendingIsPending()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ \"co2saving\" : \"\" }").GetIsFeedbackPending(),
|
|
Is.True);
|
|
|
|
[Test]
|
|
public void TestGetIsFeedbackPendingNot()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ }").GetIsFeedbackPending(),
|
|
Is.False);
|
|
|
|
[Test]
|
|
public void TestGetTypeOfBikeCity()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"category\" : \"city\" } }").GetTypeOfBike(),
|
|
Is.EqualTo(TypeOfBike.City));
|
|
|
|
[Test]
|
|
public void TestGetTypeOfBikeCargo()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"category\" : \"cargo\" } }").GetTypeOfBike(),
|
|
Is.EqualTo(TypeOfBike.Cargo));
|
|
|
|
[Test]
|
|
public void TestGetTypeOfBikeNull()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { } }").GetTypeOfBike(),
|
|
Is.Null);
|
|
|
|
[Test]
|
|
public void TestGetWheelTypeTrike()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"wheels\" : \"3\" } }").GetWheelType(),
|
|
Is.EqualTo(WheelType.Trike));
|
|
|
|
[Test]
|
|
public void TestGetWheelTypeQuad()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"wheels\" : \"4\" } }").GetWheelType(),
|
|
Is.EqualTo(WheelType.Quad));
|
|
|
|
[Test]
|
|
public void TestGetWheelTypeTow()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"wheels\" : \"2\" } }").GetWheelType(),
|
|
Is.EqualTo(WheelType.Two));
|
|
|
|
[Test]
|
|
public void TestGetWheelTypeNull()
|
|
=> Assert.That(
|
|
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { } }").GetWheelType(),
|
|
Is.Null);
|
|
|
|
[Test]
|
|
public void TestGetFrom()
|
|
=> Assert.That(
|
|
JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
|
{
|
|
""start_time"" : ""2022-7-16"",
|
|
}").GetFrom(),
|
|
Is.EqualTo(new DateTime(2022, 7, 16)));
|
|
|
|
[Test]
|
|
public void TestGetFromInvalid()
|
|
=> Assert.That(
|
|
JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
|
{
|
|
}").GetFrom(),
|
|
Is.EqualTo(DateTime.MinValue));
|
|
|
|
[Test]
|
|
public void TestGetReservationTimeSpan()
|
|
{
|
|
var response = JsonConvertRethrow.DeserializeObject<RentalDescription>(SharedBusinessLogic.Tests.Repository.Response.TestRentalDescription.RENTALDESCRIPTIONRESPONSE_A_V4_1_23_03);
|
|
Assert.That(response.GetMaxReservationTimeSpan().TotalMinutes, Is.EqualTo(30));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetReservationTimeSpanInvalid()
|
|
=> Assert.That(
|
|
JsonConvertRethrow.DeserializeObject<RentalDescription>(@"
|
|
{
|
|
""reserve_timerange"": ""abc"",
|
|
}").GetMaxReservationTimeSpan().TotalMinutes,
|
|
Is.EqualTo(15));
|
|
|
|
[Test]
|
|
public void TestGetReservationTimeSpanEmpty()
|
|
=> Assert.That(
|
|
JsonConvertRethrow.DeserializeObject<RentalDescription>(@"
|
|
{
|
|
}").GetMaxReservationTimeSpan().TotalMinutes,
|
|
Is.EqualTo(15));
|
|
|
|
[Test]
|
|
public void TestGetOperatorUriNull()
|
|
=> Assert.That(
|
|
TextToTypeHelper.GetOperatorUri(stationInfo: null),
|
|
Is.Null);
|
|
|
|
[Test]
|
|
public void TestGetOperatorUriEmpty()
|
|
=> Assert.That(
|
|
JsonConvertRethrow.DeserializeObject<StationInfo>(@"").GetOperatorUri(),
|
|
Is.Null);
|
|
|
|
|
|
[Test]
|
|
public void TestGetOperatorUriNoUri()
|
|
=> Assert.That(
|
|
JsonConvertRethrow.DeserializeObject<StationInfo>(@"
|
|
{
|
|
""station"": ""FR101""
|
|
}").GetOperatorUri(),
|
|
Is.Null);
|
|
|
|
[Test]
|
|
public void TestGetOperatorUriInvalidUrl()
|
|
=> Assert.That(
|
|
JsonConvertRethrow.DeserializeObject<StationInfo>(@"
|
|
{
|
|
""station"": ""FR101"",
|
|
""uri_operator"": ""ThisIsNoUrl""
|
|
}").GetOperatorUri(),
|
|
Is.Null);
|
|
|
|
[Test]
|
|
public void TestGetOperatorUri()
|
|
=> Assert.That(
|
|
JsonConvertRethrow.DeserializeObject<StationInfo>(@"
|
|
{
|
|
""station"": ""FR101"",
|
|
""uri_operator"": ""https://shareedms-tr.copri.eu""
|
|
}").GetOperatorUri().AbsoluteUri,
|
|
Is.EqualTo("https://shareedms-tr.copri.eu//APIjsonserver"));
|
|
|
|
|
|
[Test]
|
|
public void TestGetStation()
|
|
{
|
|
var stationInfo = JsonConvertRethrow.DeserializeObject<StationInfo>(@"{
|
|
""station"": ""FR104"",
|
|
""withpub"": ""1"",
|
|
""cached"": ""1"",
|
|
""authed"": ""1"",
|
|
""state"": ""available"",
|
|
""operator_data"": {
|
|
""operator_email"": ""hotline@sharee.bike"",
|
|
""operator_hours"": ""Bürozeiten: Montag, Mittwoch, Freitag 9-12 Uhr"",
|
|
""operator_phone"": ""+49 761 45370097"",
|
|
""operator_name"": ""TeilRad GmbH""
|
|
},
|
|
""station_type"": {
|
|
""city"": {
|
|
""bike_group"": ""FR300103"",
|
|
""bike_count"": ""0""
|
|
},
|
|
""cargo"": {
|
|
""bike_group"": ""FR300101"",
|
|
""bike_count"": ""0""
|
|
}
|
|
},
|
|
""uri_operator"": ""https://shareeapp-fr01.copri.eu"",
|
|
""gps_radius"": ""50"",
|
|
""capacity"": ""1"",
|
|
""description"": ""fahrradspezialitäten"",
|
|
""gps"": {
|
|
""longitude"": ""7.837621"",
|
|
""latitude"": ""47.989807""
|
|
},
|
|
""station_group"": [
|
|
""FR300101"",
|
|
""FR300103""
|
|
],
|
|
""bike_count"": ""0""
|
|
}");
|
|
|
|
var station = stationInfo.GetStation();
|
|
Assert.That(
|
|
station.OperatorUri.AbsoluteUri,
|
|
Is.EqualTo("https://shareeapp-fr01.copri.eu//APIjsonserver"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestTryGetBikesAvailableCount()
|
|
{
|
|
var station = JsonConvertRethrow.DeserializeObject<StationInfo>(
|
|
@"{
|
|
""bike_count"" : ""17"",
|
|
}");
|
|
|
|
Assert.That(station.TryGetBikesAvailableCount(out var count), Is.EqualTo(true));
|
|
Assert.That(count, Is.EqualTo(17));
|
|
}
|
|
|
|
[Test]
|
|
public void TestTryGetBikesAvailableCountInvalid()
|
|
{
|
|
var station = JsonConvertRethrow.DeserializeObject<StationInfo>(
|
|
@"{
|
|
""bike_count"" : ""a"",
|
|
}");
|
|
|
|
Assert.That(station.TryGetBikesAvailableCount(out var count), Is.EqualTo(false));
|
|
Assert.That(count, Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void TestTryGetBikesAvailableCountEmpty()
|
|
{
|
|
var station = JsonConvertRethrow.DeserializeObject<StationInfo>(
|
|
@"{
|
|
}");
|
|
|
|
Assert.That(station.TryGetBikesAvailableCount(out var count), Is.EqualTo(false));
|
|
Assert.That(count, Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void TestTryGetBikesAvailableCountNull()
|
|
{
|
|
Assert.That(TextToTypeHelper.TryGetBikesAvailableCount(null, out var count), Is.EqualTo(false));
|
|
Assert.That(count, Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetBikesAvailableCount()
|
|
{
|
|
var station = JsonConvertRethrow.DeserializeObject<StationInfo>(
|
|
@"{
|
|
""bike_count"" : ""17"",
|
|
}");
|
|
|
|
Assert.That(station.GetBikesAvailableCount(), Is.EqualTo(17));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetBikesAvailableCountInvalid()
|
|
{
|
|
var station = JsonConvertRethrow.DeserializeObject<StationInfo>(
|
|
@"{
|
|
""bike_count"" : ""a"",
|
|
}");
|
|
|
|
Assert.That(station.GetBikesAvailableCount(), Is.EqualTo(null));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetBikesAvailableCountEmpty()
|
|
{
|
|
var station = JsonConvertRethrow.DeserializeObject<StationInfo>(
|
|
@"{
|
|
}");
|
|
|
|
Assert.That(station.GetBikesAvailableCount(), Is.EqualTo(null));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetBikesAvailableCountNull()
|
|
{
|
|
Assert.That(TextToTypeHelper.GetBikesAvailableCount(null), Is.EqualTo(null));
|
|
}
|
|
|
|
[Test]
|
|
public void TestSetBikesAvailableCountEmpty()
|
|
{
|
|
var station = JsonConvertRethrow.DeserializeObject<StationInfo>(
|
|
@"{
|
|
}");
|
|
|
|
station.SetBikesAvailableCount(7);
|
|
|
|
Assert.That(station.bike_count, Is.EqualTo("7"));
|
|
}
|
|
}
|
|
}
|