Version 3.0.361

This commit is contained in:
Anja 2023-03-08 13:18:54 +01:00
parent faf68061f4
commit cba4da9357
88 changed files with 1119 additions and 1502 deletions

View file

@ -1,49 +0,0 @@
using Newtonsoft.Json;
using NUnit.Framework;
using TINK.Repository.Exception;
using TINK.Repository.Response;
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Exception
{
[TestFixture]
public class TestAuthcookieNotDefinedException
{
[Test]
public void TestConstruct()
{
Assert.AreEqual(
"Can not test.\r\nDie Sitzung ist abgelaufen. Bitte neu anmelden.",
(new AuthcookieNotDefinedException(
"Can not test.",
JsonConvert.DeserializeObject<ResponseBase>(@"{ ""response_state"" : ""Some inner error description""}"))).Message);
}
[Test]
public void TestTestIsAuthcookieNotDefined_False()
{
var response = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(@"{ ""response_state"" : ""OK"" }");
Assert.That(AuthcookieNotDefinedException.IsAuthcookieNotDefined(response, "Test context", out AuthcookieNotDefinedException exception),
Is.EqualTo(false));
}
[Test]
public void TestIsAuthcookieNotDefined_TrueLegacy()
{
var response = JsonConvert.DeserializeObject<ResponseBase>($"{{ \"response_state\" : \"Failure 1003: authcookie not defined\" }}");
Assert.That(AuthcookieNotDefinedException.IsAuthcookieNotDefined(response, "Test context", out AuthcookieNotDefinedException exception),
Is.EqualTo(true));
Assert.That(exception, !Is.Null);
}
[Test]
public void TestIsAuthcookieNotDefined_False()
{
var response = JsonConvert.DeserializeObject<ResponseBase>($"{{ \"response_state\" : \"Failure 1001: authcookie not defined\" }}");
Assert.That(AuthcookieNotDefinedException.IsAuthcookieNotDefined(response, "Test context", out AuthcookieNotDefinedException exception),
Is.EqualTo(true));
Assert.That(exception, !Is.Null);
}
}
}

View file

@ -1,40 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using TINK.Model.Connector.Filter;
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Filter
{
[TestFixture]
public class TestIntersectFilter
{
[Test]
public void TestDoFilter_Null()
{
var filter = new IntersectGroupFilter(new List<string> { "Tonk" });
Assert.AreEqual(1, filter.DoFilter(null).Count());
Assert.AreEqual(
"Tonk",
filter.DoFilter(null).ToArray()[0],
"Do not apply filtering when null is passed as argement (null-filter).");
}
[Test]
public void TestDoFilter_Empty()
{
var filter = new IntersectGroupFilter(new List<string> { "Tonk" });
Assert.AreEqual(0, filter.DoFilter(new List<string>()).Count());
}
[Test]
public void TestDoFilter()
{
var filter = new IntersectGroupFilter(new List<string> { "FR_001", "FR_009" });
Assert.AreEqual(1, filter.DoFilter(new List<string> { "FR_001", "FR_007" }).Count());
Assert.AreEqual("FR_001", filter.DoFilter(new List<string> { "FR_001", "FR_007" }).ToArray()[0]);
}
}
}

View file

@ -1,20 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using TINK.Model.Connector.Filter;
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Filter
{
[TestFixture]
public class TestNullFilter
{
[Test]
public void TestDoFilter()
{
var filter = new NullGroupFilter();
Assert.IsNull(filter.DoFilter(null));
Assert.AreEqual(0, filter.DoFilter(new List<string>()).Count());
Assert.AreEqual(1, filter.DoFilter(new List<string> { "Hello" }).Count());
}
}
}

View file

@ -1,28 +0,0 @@
using NUnit.Framework;
using TINK.Model;
using static TINK.Repository.CopriCallsMemory;
namespace TestTINKLib.Fixtures.Connector
{
[TestFixture]
public class TestBikesAvailableResponse
{
[Test]
public void TestDeserialize_StateAvailable()
{
// Deserialize object and verify.
var l_oContainer = GetBikesAvailable(TinkApp.MerchantId, sampleSet: SampleSets.Set2, stageIndex: 1);
Assert.AreEqual(12, l_oContainer.bikes.Count);
// Check first entry.
Assert.AreEqual("Cargo Trike", l_oContainer.bikes["3399"].description);
Assert.AreEqual("26", l_oContainer.bikes["3399"].bike);
Assert.AreEqual("available", l_oContainer.bikes["3399"].state);
Assert.AreEqual("47.6586936667", l_oContainer.bikes["3399"].gps.latitude);
Assert.AreEqual("9.16863116667", l_oContainer.bikes["3399"].gps.longitude);
Assert.AreEqual("4", l_oContainer.bikes["3399"].station);
}
}
}

View file

@ -1,51 +0,0 @@
using NUnit.Framework;
using TINK.Repository;
using static TINK.Repository.CopriCallsMemory;
namespace TestTINKLib.Fixtures.Connector.Response
{
[TestFixture]
public class TestBikesOccupiedResponse
{
[Test]
public void TestDeserialize()
{
// Deserialize object and verify.
var l_oContainer = GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 1);
Assert.AreEqual(2, l_oContainer.bikes_occupied.Count);
// Check first entry.
Assert.AreEqual("3630", l_oContainer.bikes_occupied["87781"].timeCode);
Assert.AreEqual("occupied", l_oContainer.bikes_occupied["87781"].state);
Assert.AreEqual("5", l_oContainer.bikes_occupied["87781"].station);
Assert.AreEqual("Cargo Long", l_oContainer.bikes_occupied["87781"].description);
Assert.AreEqual("2017-11-28 11:01:51.637747+01", l_oContainer.bikes_occupied["87781"].start_time);
Assert.AreEqual("8", l_oContainer.bikes_occupied["87781"].bike);
// Check first entry.
Assert.AreEqual("2931", l_oContainer.bikes_occupied["87782"].timeCode);
Assert.AreEqual("occupied", l_oContainer.bikes_occupied["87782"].state);
Assert.AreEqual("4", l_oContainer.bikes_occupied["87782"].station);
Assert.AreEqual("Cargo Long", l_oContainer.bikes_occupied["87782"].description);
Assert.AreEqual("2017-11-28 13:06:55.147368+01", l_oContainer.bikes_occupied["87782"].start_time);
Assert.AreEqual("7", l_oContainer.bikes_occupied["87782"].bike);
}
[Test]
public void TestDeserialize_StateReserved()
{
// Deserialize object and verify.
var l_oContainer = CopriCallsMemory.GetBikesOccupied("4da3044c8657a04ba60e2eaa753bc51a", SampleSets.Set2, 2);
Assert.AreEqual(3, l_oContainer.bikes_occupied.Count);
// Check first entry.
Assert.AreEqual("Cargo Long", l_oContainer.bikes_occupied["2360"].description);
Assert.AreEqual("5", l_oContainer.bikes_occupied["2360"].bike);
Assert.AreEqual("reserved", l_oContainer.bikes_occupied["2360"].state);
Assert.AreEqual("4", l_oContainer.bikes_occupied["2360"].station);
}
}
}

View file

@ -1,54 +0,0 @@
using NUnit.Framework;
using TINK.Repository;
using TINK.Repository.Response;
using static TINK.Repository.CopriCallsMemory;
namespace TestTINKLib.Fixtures.Connector.Response
{
[TestFixture]
public class TestBookingResponse
{
[Test]
public void TestDeserialize()
{
// Deserialize object and verify.
var l_oContainer = CopriCallsMemory.DoReserve("8", "b76b97e43a2d76b8499f32e6dd597af8", SampleSets.Set2, 1);
Assert.AreEqual(2, l_oContainer.bikes_occupied.Count);
Assert.AreEqual("3630", l_oContainer.timeCode);
Assert.AreEqual("OK: requested bike 8", l_oContainer.response_state);
// Check first entry which is bike #8
Assert.AreEqual("3630", l_oContainer.bikes_occupied["87781"].timeCode);
Assert.AreEqual("occupied", l_oContainer.bikes_occupied["87781"].state);
Assert.AreEqual("5", l_oContainer.bikes_occupied["87781"].station);
Assert.AreEqual("Cargo Long", l_oContainer.bikes_occupied["87781"].description);
Assert.AreEqual("2017-11-28 11:01:51.637747+01", l_oContainer.bikes_occupied["87781"].start_time);
Assert.AreEqual("8", l_oContainer.bikes_occupied["87781"].bike);
}
[Test]
public void TestGetIsBookingResponseSucceeded()
{
// Create response to check
var l_oResponse = DoReserve(
"8",
"4da3044c8657a04ba60e2eaa753bc51a",
SampleSets.Set2,
1);
Assert.AreEqual(
"4da3044c8657a04ba60e2eaa753bc51aoiF2kahH",
l_oResponse.authcookie);
Assert.AreEqual(
"OK: requested bike 8",
l_oResponse.response_state);
Assert.NotNull(
l_oResponse.GetIsReserveResponseOk("8"),
"Booking did succeed, response must not be null.");
}
}
}

View file

@ -1,43 +0,0 @@
using Newtonsoft.Json;
using NUnit.Framework;
namespace TINK.Repository.Response
{
[TestFixture]
public class TestResponseBase
{
[Test]
public void TestDeserialize()
{
// Deserialize object and verify.
var l_oContainer = CopriCallsMemory.DoAuthorize("javaminister@gmail.com", "javaminister", "HwId1000000000000");
// Check first entry.
Assert.AreEqual("authorization", l_oContainer.response);
Assert.AreEqual("4da3044c8657a04ba60e2eaa753bc51a", l_oContainer.authcookie);
Assert.AreEqual("OK", l_oContainer.response_state);
}
[Test]
public void TestToString()
{
var l_oResponse = JsonConvert.DeserializeObject<ResponseBase>(@"
{
""response_state"": ""OhMyState"",
""response"": ""HabGsagt"",
""response_text"": ""die Antwort"",
""authcookie"": ""lecker1"",
""copri_version"":""123""
}");
Assert.AreEqual(
"Response state is \"OhMyState\", " +
$"auth cookie is \"lecker1\" and response is \"die Antwort\", " +
$"code \"HabGsagt\"" +
$"response text \"die Antwort\".",
l_oResponse.ToString());
}
}
}

View file

@ -1,86 +0,0 @@
using Newtonsoft.Json;
using NUnit.Framework;
using TINK.Repository.Exception;
using TINK.Repository.Response;
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Response
{
[TestFixture]
public class TestResponseHelper
{
[Test]
public void TestGetIsResponseOk_BikesOccupied_Ok()
{
var l_oResponse = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(@"{ ""response_state"" : ""OK"" }");
Assert.NotNull(l_oResponse.GetIsResponseOk(ResponseHelper.BIKES_OCCUPIED_ACTIONTEXT));
}
[Test]
public void TestGetIsResponseOk_BikesOccupied_AuthcookieNotDefined()
{
var l_oResponseBase = JsonConvert.DeserializeObject<ResponseBase>($"{{ \"response_state\" : \"Failure 1003: authcookie not defined\" }}");
Assert.Throws<AuthcookieNotDefinedException>(() => l_oResponseBase.GetIsResponseOk("Get not succeed"));
}
[Test]
public void TestGetIsResponseOk_NoBikes()
{
var l_oResponse = JsonConvert.DeserializeObject<ReservationBookingResponse>(
@"{ ""response_state"" : ""OK"", " +
@"""authcookie"" : ""KeksoiF2kahH"" }");
Assert.That(() => l_oResponse.GetIsReserveResponseOk("8"), Throws.Exception.TypeOf<System.Exception>());
}
[Test]
public void TestGetIsResposeOk_Booking_Declined()
{
var l_oResponse = JsonConvert.DeserializeObject<ReservationBookingResponse>(@"{ ""response_state"" : ""OK: booking_request declined. max count of 8 occupied bikes has been reached"", ""authcookie"" : ""KeksoiF2kahH"" }");
Assert.AreEqual(
8,
Assert.Throws<BookingDeclinedException>(() => l_oResponse.GetIsReserveResponseOk("8")).MaxBikesCount);
}
[Test]
public void TestGetIsResposeOk_Logout_AutcookieUnknown()
{
var l_oResponse = JsonConvert.DeserializeObject<AuthorizationoutResponse>($"{{ \"response_state\" : \"Failure 1004: authcookie not defined\"}}");
Assert.Throws<AuthcookieNotDefinedException>(() => l_oResponse.GetIsResponseOk());
}
[Test]
public void TestGetIsReturnBikeResponseOk_Error()
{
var l_oResponse = JsonConvert.DeserializeObject<DoReturnResponse>(
@"{ ""response_state"" : ""Failure 1234"", " +
@"""authcookie"" : ""KeksoiF2kahH"" }");
Assert.That(
() => l_oResponse.GetIsReturnBikeResponseOk("8"),
Throws.Exception.TypeOf<InvalidResponseException<ResponseBase>>());
}
[Test]
public void TestGetIsReturnBikeResponseOk_ErrorNotAtStation()
{
var l_oResponse = JsonConvert.DeserializeObject<DoReturnResponse>(
@"{ ""response_state"" : ""Failure 2178: bike 1545 out of GEO fencing. 15986 meter distance to next station 66. OK: bike 1545 locked confirmed"", " +
@"""authcookie"" : ""KeksoiF2kahH"" }");
Assert.That(() => l_oResponse.GetIsReturnBikeResponseOk("8"), Throws.Exception.TypeOf<NotAtStationException>());
}
[Test]
public void TestGetIsReturnBikeResponseOk_ErrorNoGPSData()
{
var l_oResponse = JsonConvert.DeserializeObject<DoReturnResponse>(
@"{ ""response_state"" : ""Failure 2245: No GPS data, state change forbidden."", " +
@"""authcookie"" : ""KeksoiF2kahH"" }");
Assert.That(() => l_oResponse.GetIsReturnBikeResponseOk("8"), Throws.Exception.TypeOf<NoGPSDataException>());
}
}
}

View file

@ -1,41 +0,0 @@
using NUnit.Framework;
using TINK.Model;
using static TINK.Repository.CopriCallsMemory;
namespace TestTINKLib.Fixtures.Connector
{
[TestFixture]
public class TestStationsAllResponse
{
[Test]
public void TestDeserialize()
{
// Deserialize object and verify.
var l_oContainer = GetStationsAll(TinkApp.MerchantId, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 1);
Assert.AreEqual(9, l_oContainer.stations.Count);
// Check first entry (type TINK).
Assert.AreEqual("4", l_oContainer.stations["5786"].station);
Assert.AreEqual("TINK", string.Join(",", l_oContainer.stations["5786"].station_group));
Assert.IsNull(l_oContainer.stations["5786"].description);
Assert.AreEqual("47.6586936667", l_oContainer.stations["5786"].gps.latitude);
Assert.AreEqual("9.16863116667", l_oContainer.stations["5786"].gps.longitude);
// Check Konrad entry.
Assert.AreEqual("14", l_oContainer.stations["14"].station);
Assert.AreEqual("Konrad", string.Join(",", l_oContainer.stations["14"].station_group));
Assert.AreEqual(string.Empty, l_oContainer.stations["14"].description);
Assert.AreEqual("47.66698054007847", l_oContainer.stations["14"].gps.latitude);
Assert.AreEqual("9.169303178787231", l_oContainer.stations["14"].gps.longitude);
// Check TINK/ Konrad entry.
Assert.AreEqual("31", l_oContainer.stations["31"].station);
Assert.AreEqual("TINK,Konrad", string.Join(",", l_oContainer.stations["31"].station_group));
Assert.AreEqual("Südstadt Station", l_oContainer.stations["31"].description);
Assert.AreEqual("47.69489", l_oContainer.stations["31"].gps.latitude);
Assert.AreEqual("9.19", l_oContainer.stations["31"].gps.longitude);
}
}
}

View file

@ -1,74 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using TINK.Repository;
using TINK.Repository.Response;
using static TINK.Repository.CopriCallsMemory;
namespace TestTINKLib.Fixtures.Connector.Request
{
[TestFixture]
public class TestCopriCallsMemory
{
[Test]
public void TestConsistency()
{
foreach (SampleSets l_oSampleSet in Enum.GetValues(typeof(SampleSets)))
{
var l_oCopri = new CopriCallsMemory("MyMerchId", l_oSampleSet, 1, "4da3044c8657a04ba60e2eaa753bc51a");
for (var l_iStageIndex = 1; l_iStageIndex <= l_oCopri.StagesCount; l_iStageIndex++)
{
Assert.That(l_oCopri.GetBikesAvailableAsync().Result?.bikes, Is.Not.Null, $"There must be at least one bike for sample set {l_oSampleSet}, stage {l_iStageIndex}.");
VerifyBikeIdIsUnique(l_oCopri);
Assert.IsNull(
l_oCopri.GetBikesAvailableAsync().Result.bikes.Values.FirstOrDefault(x => x.state != "available"),
"Bikes available must return bikes which are all of state available.");
Assert.IsNull(
l_oCopri.GetBikesOccupiedAsync().Result.bikes_occupied.Values.FirstOrDefault(x => x.state == "available"),
"Bikes occupied must return bikes which are either reserved or booked.");
}
}
}
/// <summary>
/// Test consistency for a single sample set,
/// </summary>
/// <param name="p_oMemory"></param>
private void VerifyBikeIdIsUnique(CopriCallsMemory p_oMemory)
{
Dictionary<string, BikeInfoBase> l_oChecker = new Dictionary<string, BikeInfoBase>();
var l_oBikesAvailable = p_oMemory.GetBikesAvailableAsync().Result;
foreach (var l_oBike in l_oBikesAvailable.bikes.Values)
{
Assert.IsFalse(
l_oChecker.Keys.Contains(l_oBike.bike),
string.Format(
"Bike form available bikes with id {0} already exist in dictionary. Sample set is {1}, stage index {2}.",
l_oBike.bike,
p_oMemory.ActiveSampleSet,
p_oMemory.ActiveStageIndex));
l_oChecker.Add(l_oBike.bike, l_oBike);
}
var l_oBikesOccupied = p_oMemory.GetBikesOccupiedAsync().Result;
foreach (var l_oBike in l_oBikesOccupied.bikes_occupied.Values)
{
Assert.IsFalse(
l_oChecker.Keys.Contains(l_oBike.bike),
string.Format(
"Bike from occupied bikes with id {0} already exist in dictionary. Sample set is {1}, stage index {2}.",
l_oBike.bike,
p_oMemory.ActiveSampleSet,
p_oMemory.ActiveStageIndex));
l_oChecker.Add(l_oBike.bike, l_oBike);
}
}
}
}

View file

@ -1,65 +0,0 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using TINK.Model.Services.CopriApi.ServerUris;
namespace TestTINKLib.Fixtures.ObjectTests.Connector
{
[TestFixture]
public class TestCopriServerUriList
{
[Test]
public void TestConstruct()
{
var l_oUri = new CopriServerUriList();
Assert.Greater(l_oUri.Uris.Count, 0, "There must be at least one uri");
Assert.NotNull(l_oUri.ActiveUri);
}
[Test]
public void TestConstruct_AryStringString()
{
var l_oUri = new CopriServerUriList(
(new List<Uri> { new Uri("http://1.2.3.4"), new Uri("http://2.3.4.5"), new Uri("http://3.4.5.6") }).ToArray(),
new Uri("http://2.3.4.5"));
Assert.AreEqual(3, l_oUri.Uris.Count);
Assert.AreEqual(new Uri("http://2.3.4.5"), l_oUri.ActiveUri);
}
[Test]
public void TestConstruct_AryStringString_NullList()
{
Assert.Throws<ArgumentException>(() => new CopriServerUriList(
null,
new Uri("http://2.3.4.5")));
}
[Test]
public void TestConstruct_AryStringString_InvalidList()
{
Assert.Throws<ArgumentException>(() => new CopriServerUriList(
(new List<Uri>()).ToArray(),
new Uri("http://2.3.4.5")));
}
[Test]
public void TestConstruct_AryStringString_InvalidActiveUri()
{
Assert.Throws<ArgumentException>(() => new CopriServerUriList(
(new List<Uri> { new Uri("http://1.2.3.4"), new Uri("http://2.3.4.5"), new Uri("http://3.4.5.6") }).ToArray(),
new Uri("http://9.9.9.9")));
}
[Test]
public void TestDefaultActiveUri()
{
Assert.AreEqual(
"https://shareeapp-primary.copri.eu/APIjsonserver",
CopriServerUriList.DefaultActiveUri.AbsoluteUri,
"In production environment, server address must always be app.tink-konstanz.de/APIjsonserver.");
}
}
}