mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-22 22:07:28 +02:00
Legacy testing lib added..
This commit is contained in:
parent
0167fc321f
commit
47ed05837e
118 changed files with 17505 additions and 0 deletions
|
@ -0,0 +1,290 @@
|
|||
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace UITest.Fixtures.Connector
|
||||
{
|
||||
/// <summary>
|
||||
/// Object which manages calls to copri.
|
||||
/// </summary>
|
||||
public class CopriCallsHttpsReference
|
||||
{
|
||||
/// <summary> Logs user in. </summary>
|
||||
/// <param name="copriHost">Host to connect to. </param>
|
||||
/// <param name="merchantId">Id of the merchant.</param>
|
||||
/// <param name="mailAddress">Mailaddress of user to log in.</param>
|
||||
/// <param name="password">Password to log in.</param>
|
||||
/// <param name="deviceId">Id specifying user and hardware.</param>
|
||||
/// <remarks>Response which holds auth cookie <see cref="ResponseBase.authcookie"/></remarks>
|
||||
public static AuthorizationResponse DoAuthorizeCall(
|
||||
string copriHost,
|
||||
string merchantId,
|
||||
string mailAddress,
|
||||
string password,
|
||||
string deviceId)
|
||||
{
|
||||
#if !WINDOWS_UWP
|
||||
|
||||
var l_oCommand = string.Format(
|
||||
"request=authorization&merchant_id={0}&user_id={1}&user_pw={2}&hw_id={3}",
|
||||
merchantId,
|
||||
mailAddress,
|
||||
password,
|
||||
deviceId);
|
||||
|
||||
/// Extract session cookie from response.
|
||||
|
||||
string response = string.Empty;
|
||||
|
||||
response = Post(l_oCommand, copriHost);
|
||||
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<AuthorizationResponse>>(response)?.shareejson;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary> Logs user out. </summary>
|
||||
/// <param name="copriHost">Host to connect to. </param>
|
||||
/// <param name="merchantId">Id of the merchant.</param>
|
||||
/// <param name="sessionCookie"> Cookie which identifies user.</param>
|
||||
public static AuthorizationoutResponse DoAuthoutCall(
|
||||
string copriHost,
|
||||
string merchantId,
|
||||
string sessionCookie)
|
||||
{
|
||||
#if !WINDOWS_UWP
|
||||
|
||||
var l_oCommand = string.Format(
|
||||
"request=authout&authcookie={0}{1}",
|
||||
sessionCookie,
|
||||
merchantId);
|
||||
|
||||
string l_oLogoutResponse;
|
||||
|
||||
l_oLogoutResponse = Post(l_oCommand, copriHost);
|
||||
|
||||
/// Extract session cookie from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<AuthorizationoutResponse>>(l_oLogoutResponse)?.shareejson;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get list of stations from file.
|
||||
/// </summary>
|
||||
/// <param name="p_strCopriHost">URL of the copri host to connect to.</param>
|
||||
/// <param name="p_strMerchantId">Id of the merchant.</param>
|
||||
/// <param name="p_strCookie">Auto cookie of user if user is logged in.</param>
|
||||
/// <returns>List of files.</returns>
|
||||
public static StationsAllResponse GetStationsAllCall(
|
||||
string p_strCopriHost,
|
||||
string p_strMerchantId,
|
||||
string p_strCookie = null)
|
||||
{
|
||||
var l_oCommand = string.Format(
|
||||
"request=stations_all&authcookie={0}{1}",
|
||||
p_strCookie,
|
||||
p_strMerchantId);
|
||||
|
||||
#if !WINDOWS_UWP
|
||||
string l_oStationsAllResponse;
|
||||
|
||||
l_oStationsAllResponse = Post(l_oCommand, p_strCopriHost);
|
||||
|
||||
// Extract bikes from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<StationsAllResponse>>(l_oStationsAllResponse)?.shareejson;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of bikes from Copri.
|
||||
/// </summary>
|
||||
/// <param name="copriHost">URL of the copri host to connect to.</param>
|
||||
/// <param name="p_strMerchantId">Id of the merchant.</param>
|
||||
/// <param name="p_strSessionCookie">Cookie to authenticate user.</param>
|
||||
/// <returns>Response holding list of bikes.</returns>
|
||||
public static BikesAvailableResponse GetBikesAvailableCall(
|
||||
string copriHost,
|
||||
string merchantId,
|
||||
string sessionCookie = null)
|
||||
{
|
||||
#if !WINDOWS_UWP
|
||||
string l_oCommand =
|
||||
$"request=bikes_available&system=all&authcookie={sessionCookie ?? string.Empty}{merchantId}";
|
||||
|
||||
string response;
|
||||
|
||||
response = Post(l_oCommand, copriHost);
|
||||
|
||||
// Extract bikes from response.
|
||||
return CopriCallsStatic.DeserializeResponse<BikesAvailableResponse>(response);
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of bikes reserved/ booked by acctive user from Copri.
|
||||
/// </summary>
|
||||
/// <param name="p_strMerchantId">Id of the merchant.</param>
|
||||
/// <param name="p_strSessionCookie">Cookie to authenticate user.</param>
|
||||
/// <returns>Response holding list of bikes.</returns>
|
||||
public static BikesReservedOccupiedResponse GetBikesOccupiedCall(
|
||||
string copriHost,
|
||||
string merchantId,
|
||||
string sessionCookie)
|
||||
{
|
||||
#if !WINDOWS_UWP
|
||||
string l_oCommand = !string.IsNullOrEmpty(sessionCookie)
|
||||
? $"request=user_bikes_occupied&system=all&authcookie={sessionCookie}{merchantId}"
|
||||
: "request=bikes_available";
|
||||
|
||||
string l_oBikesOccupiedResponse;
|
||||
|
||||
l_oBikesOccupiedResponse = Post(l_oCommand, copriHost);
|
||||
|
||||
// Extract bikes from response.
|
||||
return CopriCallsStatic.DeserializeResponse<BikesReservedOccupiedResponse>(l_oBikesOccupiedResponse);
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets booking request response.
|
||||
/// </summary>
|
||||
/// <param name="p_strMerchantId">Id of the merchant.</param>
|
||||
/// <param name="p_iBikeId">Id of the bike to book.</param>
|
||||
/// <param name="p_strSessionCookie">Cookie identifying the user.</param>
|
||||
/// <returns>Response on booking request.</returns>
|
||||
public static ReservationBookingResponse DoReserveCall(
|
||||
string copriHost,
|
||||
string p_strMerchantId,
|
||||
string p_iBikeId,
|
||||
string p_strSessionCookie)
|
||||
{
|
||||
#if !WINDOWS_UWP
|
||||
string l_oCommand = string.Format(
|
||||
"request=booking_request&bike={0}&authcookie={1}{2}",
|
||||
p_iBikeId,
|
||||
p_strSessionCookie,
|
||||
p_strMerchantId);
|
||||
|
||||
string l_oBikesAvaialbeResponse = Post(l_oCommand, copriHost);
|
||||
|
||||
// Extract bikes from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<ReservationBookingResponse>>(l_oBikesAvaialbeResponse)?.shareejson;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets canel booking request response.
|
||||
/// </summary>
|
||||
/// <param name="p_strMerchantId">Id of the merchant.</param>
|
||||
/// <param name="p_iBikeId">Id of the bike to book.</param>
|
||||
/// <param name="p_strSessionCookie">Cookie of the logged in user.</param>
|
||||
/// <returns>Response on cancel booking request.</returns>
|
||||
public static ReservationCancelReturnResponse DoCancelReservationCall(
|
||||
string copriHost,
|
||||
string p_strMerchantId,
|
||||
string p_iBikeId,
|
||||
string p_strSessionCookie)
|
||||
{
|
||||
#if !WINDOWS_UWP
|
||||
string l_oCommand = string.Format(
|
||||
"request=booking_cancel&bike={0}&authcookie={1}{2}",
|
||||
p_iBikeId,
|
||||
p_strSessionCookie,
|
||||
p_strMerchantId);
|
||||
string l_oBikesAvaialbeResponse;
|
||||
|
||||
l_oBikesAvaialbeResponse = Post(l_oCommand, copriHost);
|
||||
|
||||
// Extract bikes from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<ReservationCancelReturnResponse>>(l_oBikesAvaialbeResponse)?.shareejson;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of bikes from Copri.
|
||||
/// </summary>
|
||||
/// <param name="p_strSessionCookie">Cookie to authenticate user.</param>
|
||||
/// <returns></returns>
|
||||
private static string Post(
|
||||
string p_strCommand,
|
||||
string p_strURL)
|
||||
{
|
||||
#if !WINDOWS_UWP
|
||||
var l_strHost = p_strURL;
|
||||
|
||||
// Returns a http request.
|
||||
var l_oRequest = WebRequest.Create(l_strHost);
|
||||
|
||||
l_oRequest.Method = "POST";
|
||||
l_oRequest.ContentType = "application/x-www-form-urlencoded";
|
||||
|
||||
byte[] l_oPostData = Encoding.UTF8.GetBytes(p_strCommand);
|
||||
|
||||
l_oRequest.ContentLength = l_oPostData.Length;
|
||||
|
||||
// Get the request stream.
|
||||
using (Stream l_oDataStream = l_oRequest.GetRequestStream())
|
||||
{
|
||||
// Write the data to the request stream.
|
||||
l_oDataStream.Write(l_oPostData, 0, l_oPostData.Length);
|
||||
}
|
||||
|
||||
// Get the response.
|
||||
var l_oResponse = l_oRequest.GetResponse() as HttpWebResponse;
|
||||
|
||||
if (l_oResponse == null)
|
||||
{
|
||||
throw new Exception(string.Format("Reserve request failed. Response form from server was not of expected type."));
|
||||
}
|
||||
|
||||
if (l_oResponse.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
throw new CommunicationException(string.Format(
|
||||
"Posting request {0} failed. Expected status code is {1} but was {2}.",
|
||||
p_strCommand,
|
||||
HttpStatusCode.OK,
|
||||
l_oResponse.StatusCode));
|
||||
}
|
||||
|
||||
string responseFromServer = string.Empty;
|
||||
|
||||
// Get the request stream.
|
||||
using (Stream l_oDataStream = l_oResponse.GetResponseStream())
|
||||
using (StreamReader l_oReader = new StreamReader(l_oDataStream))
|
||||
{
|
||||
// Read the content.
|
||||
responseFromServer = l_oReader.ReadToEnd();
|
||||
|
||||
// Display the content.
|
||||
Console.WriteLine(responseFromServer);
|
||||
|
||||
// Clean up the streams.
|
||||
l_oResponse.Close();
|
||||
}
|
||||
|
||||
return responseFromServer;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
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> { "Tonk", "Honk" });
|
||||
|
||||
Assert.AreEqual(1, filter.DoFilter(new List<string> { "Tonk", "Klonk" }).Count());
|
||||
Assert.AreEqual("Tonk", filter.DoFilter(new List<string> { "Tonk", "Klonk" }).ToArray()[0]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,189 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Query
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCachedQuery
|
||||
{
|
||||
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 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""
|
||||
}";
|
||||
|
||||
private const string STATIONSALLEMPTY = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""stations"" : {
|
||||
},
|
||||
""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_StationsFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAllResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL),
|
||||
new System.Exception("Bang when getting stations..."))));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE))));
|
||||
|
||||
var result = await new CachedQuery(server).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(1, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang when getting stations...", result.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_BikesAvailableFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAllResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALLEMPTY))));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new System.Exception("Bang when getting bikes..."))));
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<StationsAllResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL))));
|
||||
|
||||
var result = await new CachedQuery(server).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(1, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang when getting bikes...", result.Exception.Message);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAllResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL))));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE))));
|
||||
|
||||
server.Stub(x => x.AddToCache(Arg<Result<StationsAllResponse>>.Is.Anything));
|
||||
server.Stub(x => x.AddToCache(Arg<Result<BikesAvailableResponse>>.Is.Anything));
|
||||
|
||||
var result = await new CachedQuery(server).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(1, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikes()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable()).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE))));
|
||||
|
||||
server.Stub(x => x.AddToCache(Arg<Result<BikesAvailableResponse>>.Is.Anything));
|
||||
|
||||
var result = await new CachedQuery(server).GetBikesAsync();
|
||||
|
||||
Assert.AreEqual(1, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
var result = await new CachedQuery(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 nicht möglich. Kein Benutzer angemeldet.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,338 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Query
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestCachedQueryLoggedIn
|
||||
{
|
||||
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 BIKESAVAILABLEEMPTY = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""bikes"" : {},
|
||||
""response_state"" : ""OK"",
|
||||
""apiserver"" : ""https://app.tink-konstanz.de"",
|
||||
""authcookie"" : """",
|
||||
""response"" : ""bikes_available"",
|
||||
""bikes"" : {
|
||||
}
|
||||
}";
|
||||
|
||||
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""
|
||||
}";
|
||||
|
||||
private const string STATIONSALLEMPTY = @"{
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""stations"" : {
|
||||
},
|
||||
""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_StationsFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAllResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL),
|
||||
new System.Exception("Bang when getting stations..."))));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE))));
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED))));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(2, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang when getting stations...", result.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_BikesAvailableFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAllResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALLEMPTY))));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new System.Exception("Bang when getting bikes..."))));
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED))));
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<StationsAllResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL))));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(2, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang when getting bikes...", result.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations_BikesOccupiedFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAllResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALLEMPTY))));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLEEMPTY))));
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED),
|
||||
new System.Exception("Bang when getting bikes occupied..."))));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE))));
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<StationsAllResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL))));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(2, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang when getting bikes occupied...", result.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetStations()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStations(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<StationsAllResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL))));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE))));
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED))));
|
||||
|
||||
server.Stub(x => x.AddToCache(Arg<Result<StationsAllResponse>>.Is.Anything));
|
||||
server.Stub(x => x.AddToCache(Arg<Result<BikesAvailableResponse>>.Is.Anything));
|
||||
server.Stub(x => x.AddToCache(Arg<Result<BikesReservedOccupiedResponse>>.Is.Anything));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(2, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikes_BikesAvailableFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable()).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE),
|
||||
new System.Exception("Bang, bikes avail..."))));
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED))));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAsync();
|
||||
|
||||
Assert.AreEqual(2, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang, bikes avail...", result.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikes_BikesOccupiedFromCache()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLEEMPTY))));
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied(Arg<bool>.Matches(fromCache => fromCache == false))).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED),
|
||||
new System.Exception("Bang, error bikes occupied"))));
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable(Arg<bool>.Matches(fromCache => fromCache == true))).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsMonkeyStore),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE))));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAsync();
|
||||
|
||||
Assert.AreEqual(2, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.AreEqual("Bang, error bikes occupied", result.Exception.Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikes()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetBikesAvailable()).Return(Task.Run(() => new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE))));
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied()).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED))));
|
||||
|
||||
server.Stub(x => x.AddToCache(Arg<Result<BikesAvailableResponse>>.Is.Anything));
|
||||
server.Stub(x => x.AddToCache(Arg<Result<BikesReservedOccupiedResponse>>.Is.Anything));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAsync();
|
||||
|
||||
Assert.AreEqual(2, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICachedCopriServer>();
|
||||
|
||||
server.Stub(x => x.GetBikesOccupied()).Return(Task.Run(() => new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED))));
|
||||
|
||||
server.Stub(x => x.AddToCache(Arg<Result<BikesReservedOccupiedResponse>>.Is.Anything));
|
||||
|
||||
var result = await new CachedQueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesOccupiedAsync();
|
||||
|
||||
Assert.AreEqual(1, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsHttps), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
}
|
||||
}
|
113
TestTINKLib/Fixtures/ObjectTests/Connector/Query/TestQuery.cs
Normal file
113
TestTINKLib/Fixtures/ObjectTests/Connector/Query/TestQuery.cs
Normal file
|
@ -0,0 +1,113 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
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""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
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 TestGetStations()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStationsAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
server.Stub(x => x.GetBikesAvailableAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
|
||||
var result = await new TINK.Model.Connector.Query(server).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(1, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikes()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICopriServer>();
|
||||
|
||||
server.Stub(x => x.GetBikesAvailableAsync()).Return(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 = MockRepository.GenerateMock<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.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Repository.Response;
|
||||
using TINK.Repository;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestQueryLoggedIn
|
||||
{
|
||||
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 TestGetStations()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICopriServer>();
|
||||
|
||||
server.Stub(x => x.GetStationsAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<StationsAllResponse>(STATIONSALL)));
|
||||
server.Stub(x => x.GetBikesAvailableAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
server.Stub(x => x.GetBikesOccupiedAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
|
||||
var result = await new QueryLoggedIn(server, "123", "a@b", ()=> DateTime.Now).GetBikesAndStationsAsync();
|
||||
|
||||
Assert.AreEqual(3, result.Response.StationsAll.Count);
|
||||
Assert.AreEqual(2, result.Response.Bikes.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikes()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICopriServer>();
|
||||
|
||||
server.Stub(x => x.GetBikesAvailableAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
|
||||
server.Stub(x => x.GetBikesOccupiedAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
|
||||
var result = await new QueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesAsync();
|
||||
|
||||
Assert.AreEqual(2, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetBikesOccupied()
|
||||
{
|
||||
var server = MockRepository.GenerateMock<ICopriServer>();
|
||||
|
||||
server.Stub(x => x.GetBikesOccupiedAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED)));
|
||||
|
||||
var result = await new QueryLoggedIn(server, "123", "a@b", () => DateTime.Now).GetBikesOccupiedAsync();
|
||||
|
||||
Assert.AreEqual(1, result.Response.Count);
|
||||
Assert.AreEqual(typeof(CopriCallsMonkeyStore), result.Source);
|
||||
Assert.IsNull(result.Exception);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Request;
|
||||
|
||||
namespace UITest.Fixtures.ObjectTests.Connector.Request
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestRequestBuilder
|
||||
{
|
||||
[Test]
|
||||
public void TestDoAuthorize()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"request=authorization&merchant_id=123&user_id=abc%40cde&user_pw=%2B%3F&hw_id=789",
|
||||
new RequestBuilder("123").DoAuthorization("abc@cde", "+?", "789"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoAuthout()
|
||||
{
|
||||
Assert.Throws<CallNotRequiredException>(() =>
|
||||
new RequestBuilder("123").DoAuthout());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAvailable()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"request=bikes_available&system=all&authcookie=123",
|
||||
new RequestBuilder("123").GetBikesAvailable());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesOccupied()
|
||||
{
|
||||
Assert.Throws< NotSupportedException>(() =>
|
||||
new RequestBuilder("123").GetBikesOccupied());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetStations()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"request=stations_available&authcookie=123",
|
||||
new RequestBuilder("123").GetStations());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoReserve()
|
||||
{
|
||||
Assert.Throws<NotSupportedException>(() =>
|
||||
new RequestBuilder("123").DoReserve("42"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoCancelReservation()
|
||||
{
|
||||
Assert.Throws<NotSupportedException>(() =>
|
||||
new RequestBuilder("123").DoCancelReservation("42"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoSubmitFeedback()
|
||||
{
|
||||
Assert.Throws<NotSupportedException>(() =>
|
||||
new RequestBuilder("123").DoSubmitFeedback("bike3", "Hi", false));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Request;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Request
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestRequestBuilderLoggedIn
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void TestDoAuthorize()
|
||||
{
|
||||
Assert.Throws <CallNotRequiredException>(() =>new RequestBuilderLoggedIn("123", "456").DoAuthorization("abc@cde", "+?", "789"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoAuthout()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"request=authout&authcookie=456123",
|
||||
new RequestBuilderLoggedIn ("123", "456").DoAuthout());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAvailable()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"request=bikes_available&system=all&authcookie=456123",
|
||||
new RequestBuilderLoggedIn("123", "456").GetBikesAvailable());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesAvailable_Null()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
new RequestBuilderLoggedIn("123", null).GetBikesAvailable());
|
||||
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
new RequestBuilderLoggedIn("123", string.Empty).GetBikesAvailable());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesOccupied()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"request=user_bikes_occupied&system=all&genkey=1&authcookie=456123",
|
||||
new RequestBuilderLoggedIn("123", "456").GetBikesOccupied());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikesOccupied_Null()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
new RequestBuilderLoggedIn("123", null).GetBikesOccupied());
|
||||
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
new RequestBuilderLoggedIn("123", "").GetBikesOccupied());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetStations()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"request=stations_available&authcookie=456123",
|
||||
new RequestBuilderLoggedIn("123", "456").GetStations());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetStations_Null()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
new RequestBuilderLoggedIn("123", string.Empty).GetStations());
|
||||
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
new RequestBuilderLoggedIn("123", null).GetStations());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoReserve()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"request=booking_request&bike=42&authcookie=456123",
|
||||
new RequestBuilderLoggedIn("123", "456").DoReserve("42"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoCancelReservation()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"request=booking_cancel&bike=42&authcookie=456123",
|
||||
new RequestBuilderLoggedIn("123", "456").DoCancelReservation("42"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoBook()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"request=booking_update&bike=42&authcookie=456123&Ilockit_GUID=0000f00d-1212-efde-1523-785fef13d123&state=occupied&lock_state=unlocked&voltage=33.21",
|
||||
new RequestBuilderLoggedIn("123", "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"),33.21));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDoBookNoBatery()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"request=booking_update&bike=42&authcookie=456123&Ilockit_GUID=0000f00d-1212-efde-1523-785fef13d123&state=occupied&lock_state=unlocked",
|
||||
new RequestBuilderLoggedIn("123", "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"), double.NaN));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
using NUnit.Framework;
|
||||
using TINK.Model;
|
||||
using TINK.Repository;
|
||||
|
||||
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, p_eSampleSet: SampleSets.Set2, p_lStageIndex: 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
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.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
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<ReservationCancelReturnResponse>(
|
||||
@"{ ""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<ReservationCancelReturnResponse>(
|
||||
@"{ ""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<ReservationCancelReturnResponse>(
|
||||
@"{ ""response_state"" : ""Failure 2245: No GPS data, state change forbidden."", " +
|
||||
@"""authcookie"" : ""KeksoiF2kahH"" }");
|
||||
|
||||
Assert.That(() => l_oResponse.GetIsReturnBikeResponseOk("8"), Throws.Exception.TypeOf<NoGPSDataException>());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
using NUnit.Framework;
|
||||
using System.Linq;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCommandLoggedIn
|
||||
{
|
||||
/// <summary> Verifies, that logout leads to expected call on copri server. </summary>
|
||||
[Test]
|
||||
public void TestDoLogout()
|
||||
{
|
||||
var l_oServer = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
l_oServer.Stub(x => x.DoAuthoutAsync()).Return(Task.Run(() => JsonConvert.DeserializeObject<AuthorizationoutResponse>("{ \"response_state\" : \"OK\", \"authcookie\" : \"1\"}")));
|
||||
|
||||
var l_oCmd = new CommandLoggedIn(l_oServer, "MeinKeks", "EMehl", () => DateTime.Now);
|
||||
|
||||
LoginStateChangedEventArgs l_oEventArgs = null;
|
||||
l_oCmd.LoginStateChanged += (sender, eventargs) => l_oEventArgs = eventargs;
|
||||
|
||||
l_oCmd.DoLogout().Wait();
|
||||
|
||||
l_oServer.AssertWasCalled(x => x.DoAuthoutAsync());
|
||||
Assert.IsNotNull(l_oEventArgs);
|
||||
}
|
||||
|
||||
/// <summary> Verifies, that logout leads to expected call on copri server. </summary>
|
||||
[Test]
|
||||
public void TestDoLogout_AuthcookieNotDefined()
|
||||
{
|
||||
var l_oServer = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
l_oServer.Stub(x => x.DoAuthoutAsync()).Throw(new AuthcookieNotDefinedException("Testing action", JsonConvert.DeserializeObject<ResponseBase>(@"{ ""response_state"" : ""Some inner error description""}")));
|
||||
|
||||
var l_oCmd = new CommandLoggedIn(l_oServer, "MeinKeks", "EMehl", () => DateTime.Now);
|
||||
|
||||
LoginStateChangedEventArgs l_oEventArgs = null;
|
||||
l_oCmd.LoginStateChanged += (sender, eventargs) => l_oEventArgs = eventargs;
|
||||
|
||||
l_oCmd.DoLogout().Wait();
|
||||
|
||||
l_oServer.AssertWasCalled(x => x.DoAuthoutAsync());
|
||||
Assert.IsNotNull(l_oEventArgs);
|
||||
}
|
||||
|
||||
/// <summary> Verifies, that logout leads to expected call on copri server. </summary>
|
||||
[Test]
|
||||
public void TestDoLogout_Exception()
|
||||
{
|
||||
var l_oServer = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
l_oServer.Stub(x => x.DoAuthoutAsync()).Throw(new System.Exception("Sometheing went wrong."));
|
||||
|
||||
var l_oCmd = new CommandLoggedIn(l_oServer, "MeinKeks", "EMehl", () => DateTime.Now);
|
||||
|
||||
LoginStateChangedEventArgs l_oEventArgs = null;
|
||||
l_oCmd.LoginStateChanged += (sender, eventargs) => l_oEventArgs = eventargs;
|
||||
|
||||
Assert.Throws<AggregateException>(() => l_oCmd.DoLogout().Wait());
|
||||
|
||||
l_oServer.AssertWasCalled(x => x.DoAuthoutAsync());
|
||||
Assert.IsNull(l_oEventArgs);
|
||||
}
|
||||
}
|
||||
}
|
84
TestTINKLib/Fixtures/ObjectTests/Connector/TestConnector.cs
Normal file
84
TestTINKLib/Fixtures/ObjectTests/Connector/TestConnector.cs
Normal file
|
@ -0,0 +1,84 @@
|
|||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestConnector
|
||||
{
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCommandFactory()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICachedCopriServer>();
|
||||
|
||||
// Construct not logged in version of connector.
|
||||
var l_oCommand = new TINK.Model.Connector.Connector(
|
||||
new System.Uri("http://1.2.3.4"),
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default automated test envirnoment",
|
||||
"", // Not logged in
|
||||
"",
|
||||
server: l_oCopri).Command;
|
||||
|
||||
Assert.AreEqual(typeof(Command), l_oCommand.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCommandFactory_LoggedIn()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICachedCopriServer>();
|
||||
|
||||
var l_oCommand = new TINK.Model.Connector.Connector(
|
||||
new System.Uri("http://1.2.3.4"),
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default automated test envirnoment",
|
||||
"123", // Logged in
|
||||
"a@b",
|
||||
server: l_oCopri).Command;
|
||||
|
||||
Assert.AreEqual(typeof(CommandLoggedIn), l_oCommand.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestQueryFactory_CachedServer()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICachedCopriServer>();
|
||||
|
||||
var l_oQuery = new TINK.Model.Connector.Connector(
|
||||
new System.Uri("http://1.2.3.4"),
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default automated test envirnoment",
|
||||
"",
|
||||
"",
|
||||
server: l_oCopri).Query;
|
||||
|
||||
Assert.AreEqual(typeof(CachedQuery), l_oQuery.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestQueryFactory_LoggedIn()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICachedCopriServer>();
|
||||
|
||||
var l_oQuery = new TINK.Model.Connector.Connector(
|
||||
new System.Uri("http://1.2.3.4"),
|
||||
"TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default automated test envirnoment",
|
||||
"123",
|
||||
"a@b",
|
||||
server: l_oCopri).Query;
|
||||
|
||||
Assert.AreEqual(typeof(CachedQueryLoggedIn), l_oQuery.GetType());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Repository;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestConnectorCache
|
||||
{
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCommandFactory()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
// Construct not logged in version of connector.
|
||||
var l_oCommand = new ConnectorCache(
|
||||
"", // Not logged in
|
||||
"",
|
||||
l_oCopri).Command;
|
||||
|
||||
Assert.AreEqual(typeof(Command), l_oCommand.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestCommandFactory_LoggedIn()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
var l_oCommand = new ConnectorCache(
|
||||
"123", // Logged in
|
||||
"a@b",
|
||||
l_oCopri).Command;
|
||||
|
||||
Assert.AreEqual(typeof(CommandLoggedIn), l_oCommand.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestQueryFactory_CachedServer()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
var l_oQuery = new ConnectorCache(
|
||||
"",
|
||||
"",
|
||||
l_oCopri).Query;
|
||||
|
||||
Assert.AreEqual(typeof(TINK.Model.Connector.Query), l_oQuery.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that factory method returns correcty type depending on session cookie.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestQueryFactory_LoggedIn()
|
||||
{
|
||||
var l_oCopri = MockRepository.GenerateStub<ICopriServer>();
|
||||
|
||||
var l_oQuery = new ConnectorCache(
|
||||
"123",
|
||||
"a@b",
|
||||
l_oCopri).Query;
|
||||
|
||||
Assert.AreEqual(typeof(QueryLoggedIn), l_oQuery.GetType());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,688 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using TINK.Model;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Response;
|
||||
using TINK.Repository.Request;
|
||||
|
||||
using static TINK.Repository.CopriCallsHttps;
|
||||
using TINK.Model.Services.CopriApi.ServerUris;
|
||||
using System.Reflection;
|
||||
|
||||
namespace UITest.Fixtures.Connector
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCopriCallsHttps
|
||||
{
|
||||
public const string CATEGORY_REQUIRESCOPRI = "RequiresCOPRI";
|
||||
|
||||
public const string CATEGORY_USESLIVESERVER = "RequiresCOPRI.Live";
|
||||
|
||||
public const string CATEGORY_USESDEVELSERVER = "RequiresCOPRI.Devel";
|
||||
|
||||
public const string TESTAGENT = "TestShareeLib";
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Thread.Sleep(2000); // Sleep, otherwise copri will block requested calls.
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIsConnected()
|
||||
{
|
||||
Assert.IsTrue(new CopriCallsHttps(new Uri("http://127.0.0.0/api"), "TestTINKApp/3.0.127 AutomatedTestEnvirnoment/Default", "123").IsConnected);
|
||||
}
|
||||
|
||||
[Test]
|
||||
#if !NOLIVESERVER
|
||||
[Category(CATEGORY_USESLIVESERVER)]
|
||||
#elif !NODEVELSERVER
|
||||
[Category(CATEGORY_USESDEVELSERVER)]
|
||||
#endif
|
||||
public void TestLogin(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url)
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)]
|
||||
string url)
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#endif
|
||||
{
|
||||
Func<string, string> command = (password) => new RequestBuilder(TinkApp.MerchantId).DoAuthorization(
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
password,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
||||
|
||||
var l_oSessionCookieJM_Dev1 = DoAuthorizationAsync(
|
||||
url,
|
||||
command(TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd),
|
||||
() => command("*******"),
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogin)}").Result;
|
||||
|
||||
Assert.AreEqual(
|
||||
string.Format("{0}{1}", "6103_4da3044c8657a04ba60e2eaa753bc51a_", "oiF2kahH"),
|
||||
l_oSessionCookieJM_Dev1.authcookie,
|
||||
"Session cookie must never change if user and hardware id does not change.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
#if !NOLIVESERVER
|
||||
[Category(CATEGORY_USESLIVESERVER)]
|
||||
#elif !NODEVELSERVER
|
||||
[Category(CATEGORY_USESDEVELSERVER)]
|
||||
#endif
|
||||
public void TestLogin_UserUnknown(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url)
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)]
|
||||
string url)
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#endif
|
||||
{
|
||||
Func<string, string> command = (password) => new RequestBuilder(TinkApp.MerchantId).DoAuthorization(
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerGibtsNet.Mail,
|
||||
password,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerGibtsNet.DeviceId);
|
||||
|
||||
var l_oSessionCookieJM_Dev1 = DoAuthorizationAsync(
|
||||
url,
|
||||
command(TestTINKLib.LoginSessionCopriInfo.JavaministerGibtsNet.Pwd),
|
||||
() => command("***********"),
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogin_UserUnknown)}").Result;
|
||||
|
||||
Assert.That(
|
||||
l_oSessionCookieJM_Dev1,
|
||||
Is.Not.Null);
|
||||
|
||||
// From COPRI 4.1 cookie is empty, was null before
|
||||
Assert.IsEmpty(l_oSessionCookieJM_Dev1.authcookie);
|
||||
|
||||
Assert.AreEqual(
|
||||
"authorization",
|
||||
l_oSessionCookieJM_Dev1.response);
|
||||
|
||||
Assert.AreEqual(
|
||||
"Failure: cannot generate authcookie",
|
||||
l_oSessionCookieJM_Dev1.response_state);
|
||||
}
|
||||
|
||||
/// <summary> Log out functionality is only for test purposes. </summary>
|
||||
[Test]
|
||||
#if !NOLIVESERVER
|
||||
[Category(CATEGORY_USESLIVESERVER)]
|
||||
#elif !NODEVELSERVER
|
||||
[Category(CATEGORY_USESDEVELSERVER)]
|
||||
#endif
|
||||
public void TestLogout(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url)
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)]
|
||||
string url)
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#endif
|
||||
{
|
||||
// Prerequisite: Login must be performed before logging out.
|
||||
var l_oSessionCookie = CopriCallsHttpsReference.DoAuthorizeCall(
|
||||
url,
|
||||
TinkApp.MerchantId,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
||||
|
||||
Assert.IsFalse(
|
||||
string.IsNullOrEmpty(l_oSessionCookie?.authcookie),
|
||||
"Prerequisites not matched: User must be logged on before beeing able to log out.");
|
||||
|
||||
// Verify logout
|
||||
try
|
||||
{
|
||||
Assert.NotNull(DoAuthoutAsync(
|
||||
url,
|
||||
new RequestBuilderLoggedIn(
|
||||
TinkApp.MerchantId,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).DoAuthout(),
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogout)}"
|
||||
).Result.GetIsResponseOk());
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Log in again to ensure that tests do not change state of database (assumtion: user is always logged in).
|
||||
CopriCallsHttpsReference.DoAuthorizeCall(
|
||||
url,
|
||||
TinkApp.MerchantId,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log out functionality is only for test purposes.
|
||||
/// </summary>
|
||||
[Test]
|
||||
#if !NOLIVESERVER
|
||||
[Category(CATEGORY_USESLIVESERVER)]
|
||||
#elif !NODEVELSERVER
|
||||
[Category(CATEGORY_USESDEVELSERVER)]
|
||||
#endif
|
||||
public void TestLogout_NotLoggedIn(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url)
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)]
|
||||
string url)
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#endif
|
||||
{
|
||||
// Prerequisite:
|
||||
// Ensure that user is really logged out and get valid session cookie before verifying logout behavior.
|
||||
var l_oLoginResponse = CopriCallsHttpsReference.DoAuthorizeCall(
|
||||
url,
|
||||
TinkApp.MerchantId,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
||||
|
||||
Assert.IsFalse(
|
||||
string.IsNullOrEmpty(l_oLoginResponse?.authcookie),
|
||||
"Prerequisites not matched: User must be logged out before beeing able to log out.");
|
||||
|
||||
CopriCallsHttpsReference.DoAuthoutCall(url, TinkApp.MerchantId, l_oLoginResponse.authcookie);
|
||||
|
||||
try
|
||||
{
|
||||
// Verify logout
|
||||
Assert.Throws<AuthcookieNotDefinedException>(
|
||||
() => DoAuthoutAsync(
|
||||
url,
|
||||
new RequestBuilderLoggedIn(TinkApp.MerchantId, l_oLoginResponse.authcookie).DoAuthout(),
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogout_NotLoggedIn)}").Result.GetIsResponseOk());
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Log in again. Otherwise subsequent tests might fail.
|
||||
l_oLoginResponse = CopriCallsHttpsReference.DoAuthorizeCall(
|
||||
new CopriServerUriList().ActiveUri.AbsoluteUri,
|
||||
TinkApp.MerchantId,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log out is performed by app programmatically if authcookie is no more valid.
|
||||
/// Must work even if authcookie is no more valid, otherwise login would not be avalable.
|
||||
/// </summary>
|
||||
[Test]
|
||||
#if !NOLIVESERVER
|
||||
[Category(CATEGORY_USESLIVESERVER)]
|
||||
#elif !NODEVELSERVER
|
||||
[Category(CATEGORY_USESDEVELSERVER)]
|
||||
#endif
|
||||
public void TestLogout_AuthcookieUnknown(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url)
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)]
|
||||
string url)
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#endif
|
||||
{
|
||||
// Prerequisite: Login must be formormed before logging out.
|
||||
var l_oSessionCookie = CopriCallsHttpsReference.DoAuthorizeCall(
|
||||
url,
|
||||
TinkApp.MerchantId,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
||||
|
||||
Assert.IsFalse(
|
||||
string.IsNullOrEmpty(l_oSessionCookie?.authcookie),
|
||||
"Prerequisites not matched: User must be logged on before beeing able to log out.");
|
||||
|
||||
// Verify logout that expected excepton is thrown.
|
||||
try
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"Failure 1001: authcookie not defined", // Up to 2020-12-05 COPRI returned: "Failure 1004: authcookie not defined"
|
||||
DoAuthoutAsync(
|
||||
url,
|
||||
new RequestBuilderLoggedIn(
|
||||
TinkApp.MerchantId,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerKeksGibtsNet.AuthCookie).DoAuthout(),
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogout_AuthcookieUnknown)}"
|
||||
).Result.response_state);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Log in again to ensure that tests do not change state of database (assumtion: user is always logged in).
|
||||
CopriCallsHttpsReference.DoAuthorizeCall(
|
||||
url,
|
||||
TinkApp.MerchantId,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// From COPRI version v4.1 switched from TINK devel CopriServerUriList.TINK_DEVEL and CopriServerUriList.TINK_LIVE to CopriServerUriList.SHAREE_DEVEL.
|
||||
/// </remarks>
|
||||
[Test]
|
||||
#if !NOLIVESERVER
|
||||
[Category(CATEGORY_USESLIVESERVER)]
|
||||
#elif !NODEVELSERVER
|
||||
[Category(CATEGORY_USESDEVELSERVER)]
|
||||
#endif
|
||||
public void TestGetBikesAvailalbleCall_LoggedId(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url)
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#endif
|
||||
{
|
||||
// Check prerequisites: At least one bike must be available.
|
||||
var bikesReference = CopriCallsHttpsReference.GetBikesAvailableCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes;
|
||||
Assert.NotNull(bikesReference);
|
||||
var bikeReference = bikesReference.FirstOrDefault().Value;
|
||||
Assert.That(
|
||||
bikeReference,
|
||||
Is.Not.Null,
|
||||
$"Prerequisites are not matched: No bikes available from server {url} returned but at least one bike for verification required.");
|
||||
|
||||
// Verify list of bikes returned from first device
|
||||
var request = new RequestBuilderLoggedIn(
|
||||
TinkApp.MerchantId,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).GetBikesAvailable();
|
||||
|
||||
var bikes = GetBikesAvailableAsync(
|
||||
url,
|
||||
request).Result.bikes;
|
||||
|
||||
Assert.That(
|
||||
bikes,
|
||||
Is.Not.Null,
|
||||
"Response is null.");
|
||||
|
||||
var bike = bikes.FirstOrDefault().Value;
|
||||
Assert.That(
|
||||
bike,
|
||||
Is.Not.Null,
|
||||
"Response on GetBikesAvailableCall must contain at leas one bike.");
|
||||
|
||||
// Check if entries are valid.
|
||||
Assert.Greater(
|
||||
bike.description.Length,
|
||||
0,
|
||||
"Bike despcription must never be empty.");
|
||||
|
||||
Assert.That(
|
||||
bike.bike,
|
||||
Is.Not.Null,
|
||||
"Bike index must never be null");
|
||||
|
||||
Assert.AreEqual(
|
||||
"available",
|
||||
bike.state,
|
||||
"Bike state must be available");
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// From COPRI version v4.1 switched from TINK devel CopriServerUriList.TINK_DEVEL and CopriServerUriList.TINK_LIVE to CopriServerUriList.SHAREE_DEVEL.
|
||||
/// </remarks>
|
||||
[Test]
|
||||
#if !NOLIVESERVER
|
||||
[Category(CATEGORY_USESLIVESERVER)]
|
||||
#elif !NODEVELSERVER
|
||||
[Category(CATEGORY_USESDEVELSERVER)]
|
||||
#endif
|
||||
public void TestGetBikesAvailalbleCall_NotLoggedId(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url)
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#endif
|
||||
{
|
||||
// Check prerequisites: At least one bike must be available.
|
||||
var bikeReference = CopriCallsHttpsReference.GetBikesAvailableCall(url, TinkApp.MerchantId)?.bikes?.FirstOrDefault().Value;
|
||||
Assert.That(
|
||||
bikeReference,
|
||||
Is.Not.Null,
|
||||
$"Prerequisites are not matched: No bikes available from server {url} returned but at least one bike for verification required.");
|
||||
|
||||
// Verify list of bikes returned from first device
|
||||
var request = new RequestBuilder(TinkApp.MerchantId).GetBikesAvailable();
|
||||
|
||||
var bikes = GetBikesAvailableAsync(
|
||||
url,
|
||||
request,
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetBikesAvailalbleCall_NotLoggedId)}").Result.bikes;
|
||||
|
||||
Assert.That(
|
||||
bikes,
|
||||
Is.Not.Null,
|
||||
"Response is null.");
|
||||
|
||||
var bike = bikes.FirstOrDefault().Value;
|
||||
Assert.That(
|
||||
bike,
|
||||
Is.Not.Null,
|
||||
"Response on GetBikesAvailableCall must contain at leas one bike.");
|
||||
|
||||
// Check if entries are valid.
|
||||
Assert.Greater(
|
||||
bike.description.Length,
|
||||
0,
|
||||
"Bike despcription must never be empty.");
|
||||
|
||||
Assert.That(
|
||||
bike.bike,
|
||||
Is.Not.Null,
|
||||
"Bike index must never be null");
|
||||
|
||||
Assert.AreEqual(
|
||||
"available",
|
||||
bike.state,
|
||||
"Bike state must be available");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attention: Behaves different if called with a period smaller 15minutes because bike will alreay be reserved.
|
||||
/// </summary>
|
||||
[Test, Explicit, Ignore("Avoid testrunner running explicit tests.")]
|
||||
public void TestDoReserveCall(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url)
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)]
|
||||
string url)
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#endif
|
||||
{
|
||||
Assert.Less(
|
||||
CopriCallsHttpsReference.GetBikesOccupiedCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes_occupied.Count,
|
||||
3,
|
||||
"Too many bikes requested/ booked.");
|
||||
|
||||
var l_oBikesAvailable = CopriCallsHttpsReference.GetBikesAvailableCall(CopriServerUriList.DevelopUri.AbsoluteUri, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes;
|
||||
|
||||
Assert.Greater(
|
||||
l_oBikesAvailable.Count,
|
||||
0,
|
||||
"There must be at least one bike available.");
|
||||
|
||||
// Id of bike to book
|
||||
string l_oBikeId = l_oBikesAvailable.ToArray()[0].Value.bike;
|
||||
|
||||
// Check prerequisites.
|
||||
// State of bike for which to cancel booking must be available.
|
||||
Assert.NotNull(
|
||||
CopriCallsHttpsReference.GetBikesAvailableCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes?.FirstOrDefault(x => x.Value.bike == l_oBikeId).Value,
|
||||
"Prerequities check failed: Bike with given id must be available;");
|
||||
|
||||
var l_oBookingResponse = DoReserveAsync(
|
||||
CopriServerUriList.DevelopUri.AbsoluteUri,
|
||||
new RequestBuilderLoggedIn(
|
||||
TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).DoReserve(l_oBikeId)).Result;
|
||||
|
||||
try
|
||||
{
|
||||
// If response_state is "Failure 2001: booking bike 20 . maybe not available" probale test was run already and bike got reserved.
|
||||
Assert.AreEqual(string.Format("OK: requested bike {0}", l_oBikeId), l_oBookingResponse.response_state);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Clean up to ensure that running tests does not modify data base.
|
||||
CopriCallsHttpsReference.DoCancelReservationCall(url, TinkApp.MerchantId, l_oBikeId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attention: Behaves different if called with a period smaller 15minutes because bike will alreay be reserved.
|
||||
/// </summary>
|
||||
[Test, Explicit, Ignore("Avoid testrunner running explicit tests.")]
|
||||
public void TestDoCancelReservationCall(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url)
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)]
|
||||
string url)
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#endif
|
||||
|
||||
{
|
||||
Assert.Less(
|
||||
CopriCallsHttpsReference.GetBikesOccupiedCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes_occupied.Count,
|
||||
3,
|
||||
"Too many bikes requested/ booked.");
|
||||
|
||||
var l_oBikesAvailable = CopriCallsHttpsReference.GetBikesAvailableCall(CopriServerUriList.DevelopUri.AbsoluteUri, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes;
|
||||
|
||||
Assert.Greater(
|
||||
l_oBikesAvailable.Count,
|
||||
0,
|
||||
"There must be at least one bike available.");
|
||||
|
||||
// Id of bike to book
|
||||
string l_oBikeId = l_oBikesAvailable.ToArray()[0].Value.bike;
|
||||
|
||||
// Check prerequisites.
|
||||
var l_oBikeToCancel = CopriCallsHttpsReference.GetBikesAvailableCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes?.FirstOrDefault(x => x.Value.bike == l_oBikeId).Value;
|
||||
if (l_oBikeToCancel != null)
|
||||
{
|
||||
// Bike is avilable. Do request before unning test.
|
||||
CopriCallsHttpsReference.DoReserveCall(url, TinkApp.MerchantId, l_oBikeId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie);
|
||||
}
|
||||
|
||||
// State of bike for which to cancel booking must be reserved.
|
||||
var l_oReservedBike = CopriCallsHttpsReference.GetBikesOccupiedCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).bikes_occupied.FirstOrDefault(x => x.Value.bike == l_oBikeId).Value;
|
||||
Assert.NotNull(l_oReservedBike, string.Format("Setup test failed. Bike with id {0} must be booked before verifying cancel of booking.", l_oReservedBike));
|
||||
Assert.AreEqual("requested", l_oReservedBike.state, string.Format("Setup test failed. Bike with id {0} must be booked before verifying cancel of booking.", l_oReservedBike));
|
||||
|
||||
// Test cancel booking
|
||||
var l_oBookingResponse = DoCancelReservationAsync(
|
||||
CopriServerUriList.DevelopUri.AbsoluteUri,
|
||||
new RequestBuilderLoggedIn(
|
||||
TinkApp.MerchantId,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).DoReserve(l_oBikeId)).Result;
|
||||
|
||||
try
|
||||
{
|
||||
Assert.AreEqual(string.Format("OK: canceled bike {0}", l_oBikeId), l_oBookingResponse.response_state);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Clean up to ensure that running tests does not modify data base.
|
||||
CopriCallsHttpsReference.DoCancelReservationCall(url, TinkApp.MerchantId, l_oBikeId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Tests the member.</summary>
|
||||
/// <remarks>Timecode is no more verified since COPRI 4.1.</remarks>
|
||||
[Test]
|
||||
#if !NOLIVESERVER
|
||||
[Category(CATEGORY_USESLIVESERVER)]
|
||||
#elif !NODEVELSERVER
|
||||
[Category(CATEGORY_USESDEVELSERVER)]
|
||||
#endif
|
||||
public void TestGetBikesOccupiedCall_SomeRequestedBooked(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url)
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)]
|
||||
string url)
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#endif
|
||||
{
|
||||
BikesReservedOccupiedResponse l_oBookingResponse;
|
||||
var bikesOccupied = CopriCallsHttpsReference.GetBikesOccupiedCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes_occupied;
|
||||
if (bikesOccupied == null || bikesOccupied.Count < 1)
|
||||
{
|
||||
// There must be at least one bike booked.
|
||||
var bikesAvailable = CopriCallsHttpsReference.GetBikesAvailableCall(
|
||||
url,
|
||||
TinkApp.MerchantId,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes;
|
||||
|
||||
Assert.Greater(
|
||||
bikesAvailable.Count,
|
||||
0,
|
||||
"Prerequisites are not matched: There must be at least one bike available.");
|
||||
|
||||
// Id of bike to book
|
||||
var bike = bikesAvailable.ToArray()[0].Value;
|
||||
|
||||
l_oBookingResponse = CopriCallsHttpsReference.DoReserveCall(
|
||||
bike.uri_operator + "/APIjsonserver",
|
||||
TinkApp.MerchantId,
|
||||
bike.bike,
|
||||
TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie);
|
||||
|
||||
Assert.That(l_oBookingResponse.GetIsResponseOk("Testing cotext"),
|
||||
!Is.Null,
|
||||
$"Booking must succeed. {l_oBookingResponse.response_text}");
|
||||
}
|
||||
|
||||
// Verify GetBikesOccupied call.
|
||||
var l_oBike = CopriCallsHttpsReference.GetBikesOccupiedCall(url, TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes_occupied?.FirstOrDefault().Value;
|
||||
Assert.NotNull(l_oBike, "Response on GetBikesOccupiedCall of must contain at least one bike.");
|
||||
|
||||
l_oBookingResponse = GetBikesOccupiedAsync(
|
||||
url,
|
||||
new RequestBuilderLoggedIn(TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).GetBikesOccupied(),
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetBikesOccupiedCall_SomeRequestedBooked)}").Result;
|
||||
|
||||
// Check first entry.
|
||||
Assert.AreEqual(
|
||||
string.Format("{0}{1}", TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie, TinkApp.MerchantId),
|
||||
l_oBookingResponse.authcookie);
|
||||
|
||||
Assert.Greater(l_oBike.description.Length, 0, "Bike despcription must never be empty.");
|
||||
Assert.That(l_oBike.bike, Is.Not.Null, "Bike index must not be null.");
|
||||
Assert.That(
|
||||
l_oBike.station,
|
||||
Is.Not.Null,
|
||||
"Station index must never be null");
|
||||
Assert.Greater(l_oBike.state.Length, 0, "State info must never be null or empty.");
|
||||
// Todo: Requested bikes do not have a gps position. What is about booked bikes?
|
||||
// Assert.Greater(l_oBike.gps.Length, 0, "Gps position must never be empty.");
|
||||
Assert.Greater(l_oBike.start_time.Length, 0, "Time when request/ booking was performed must never be null or empty.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the member.
|
||||
/// Call GetBikesOccupiedCall is first call of app which fails (throws AuthcookieNotDefinedException) if auth cookie is invalid.
|
||||
/// If app detects AuthcookieNotDefinedException exception user is logged out.
|
||||
/// </summary>
|
||||
[Test]
|
||||
#if !NOLIVESERVER
|
||||
[Category(CATEGORY_USESLIVESERVER)]
|
||||
#elif !NODEVELSERVER
|
||||
[Category(CATEGORY_USESDEVELSERVER)]
|
||||
#endif
|
||||
public void TestGetBikesOccupiedCall_KeksGibtsNet(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url)
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#endif
|
||||
{
|
||||
var request = new RequestBuilderLoggedIn(TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerKeksGibtsNet.AuthCookie).GetBikesOccupied();
|
||||
|
||||
var l_oBookingResponse = GetBikesOccupiedAsync(
|
||||
url,
|
||||
request,
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetBikesOccupiedCall_KeksGibtsNet)}").Result;
|
||||
|
||||
Assert.AreEqual(
|
||||
"Failure 1001: authcookie on primary not defined",
|
||||
l_oBookingResponse.response_state); // Up to 2020-12-05 COPRI returned: "Failure 1003: authcookie not defined"
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the member.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// From COPRI version v4.1 switched from TINK devel CopriServerUriList.TINK_DEVEL and CopriServerUriList.TINK_LIVE to CopriServerUriList.SHAREE_DEVEL.
|
||||
/// </remarks>
|
||||
[Test]
|
||||
[Category(CATEGORY_REQUIRESCOPRI)]
|
||||
#if !NOLIVESERVER
|
||||
[Category(CATEGORY_USESLIVESERVER)]
|
||||
#endif
|
||||
public void TestGetStationsAllCall_NotLoggedIn(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url)
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#endif
|
||||
{
|
||||
// Check prerequisites: At least one bike must be available.
|
||||
var l_oStationsReference = CopriCallsHttpsReference.GetStationsAllCall(url, TinkApp.MerchantId)?.stations;
|
||||
Assert.IsTrue(
|
||||
l_oStationsReference != null && l_oStationsReference.Count > 0,
|
||||
"Prerequisites are not matched: There are no stations.");
|
||||
|
||||
// Verify implementation
|
||||
var l_oStationsAll = GetStationsAsync(url, new RequestBuilder(TinkApp.MerchantId).GetStations()).Result;
|
||||
Assert.NotNull(l_oStationsAll?.stations);
|
||||
Assert.Greater(l_oStationsAll.stations.Count, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the member.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// From COPRI version v4.1 switched from TINK devel CopriServerUriList.TINK_DEVEL and CopriServerUriList.TINK_LIVE to CopriServerUriList.SHAREE_DEVEL.
|
||||
/// </remarks>
|
||||
[Test]
|
||||
#if !NOLIVESERVER
|
||||
[Category(CATEGORY_USESLIVESERVER)]
|
||||
#elif !NODEVELSERVER
|
||||
[Category(CATEGORY_USESDEVELSERVER)]
|
||||
#endif
|
||||
public void TestGetStationsAllCall_LoggedIn(
|
||||
#if NOLIVESERVER
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL)] string url)
|
||||
#elif NODEVELSERVER
|
||||
[Values(CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#else
|
||||
[Values(CopriServerUriList.SHAREE_DEVEL, CopriServerUriList.SHAREE_LIVE)] string url)
|
||||
#endif
|
||||
{
|
||||
var stationsAll = GetStationsAsync(
|
||||
url,
|
||||
new RequestBuilderLoggedIn(TinkApp.MerchantId, TestTINKLib.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).GetStations(),
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetStationsAllCall_LoggedIn)}").Result;
|
||||
|
||||
Assert.NotNull(stationsAll?.stations);
|
||||
Assert.That(
|
||||
stationsAll.stations.Count,
|
||||
Is.GreaterThan(0),
|
||||
$"There must be at least one station.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
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(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Request
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCopriCallsStatic
|
||||
{
|
||||
[Test]
|
||||
public void TestDeserializeObjectBikesAvailableValidResponse()
|
||||
{
|
||||
const string VALID_RESPONSE = @"
|
||||
{
|
||||
""shareejson"": {
|
||||
|
||||
""authcookie"": 0,
|
||||
""apiserver"": ""https://tinkwwp.copri-bike.de"",
|
||||
""response"": ""bikes_available"",
|
||||
""bikes"": {
|
||||
""3399"": {
|
||||
""description"": ""Cargo Trike"",
|
||||
""bike"": ""26"",
|
||||
""state"": ""available"",
|
||||
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" },
|
||||
""station"" : ""4""
|
||||
|
||||
},
|
||||
},
|
||||
""response_state"": ""OK"",
|
||||
""copri_version"" : ""4.1.0.0""
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
// Ensure that answer holds a valid bike.
|
||||
var l_oBike = CopriCallsStatic.DeserializeResponse<BikesAvailableResponse>(VALID_RESPONSE).bikes.FirstOrDefault().Value;
|
||||
Assert.NotNull(l_oBike, "Response must contain at leas one bike.");
|
||||
Assert.Greater(l_oBike.description.Length, 0, "Bike despcription must never be empty.");
|
||||
Assert.AreEqual(l_oBike.bike, "26");
|
||||
Assert.That(
|
||||
l_oBike.station,
|
||||
Is.EqualTo("4"),
|
||||
"Station index must never be negative");
|
||||
Assert.AreEqual("available", l_oBike.state);
|
||||
Assert.That(l_oBike.gps, Is.Not.Null, "Gps position must never be empty.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeserializeObjectBikesAvailableValidResponse_NoDescription()
|
||||
{
|
||||
const string INVALID_RESPONSE = @"
|
||||
{
|
||||
""shareejson"": {
|
||||
|
||||
""authcookie"": 0,
|
||||
""apiserver"": ""https://tinkwwp.copri-bike.de"",
|
||||
""response"": ""bikes_available"",
|
||||
""bikes"": {
|
||||
""3399"": {
|
||||
""bike"": 26,
|
||||
""state"": ""available"",
|
||||
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" },
|
||||
""station"" : 4
|
||||
|
||||
},
|
||||
},
|
||||
""response_state"": ""OK"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
// Ensure that answer holds a valid bike.
|
||||
var l_oBike = CopriCallsStatic.DeserializeResponse<BikesAvailableResponse>(INVALID_RESPONSE).bikes.FirstOrDefault().Value;
|
||||
Assert.NotNull(l_oBike, "Response must contain at leas one bike.");
|
||||
Assert.IsNull(l_oBike.description);
|
||||
Assert.That(l_oBike.bike, Is.Not.Null);
|
||||
Assert.That(l_oBike.station, Is.Not.Null);
|
||||
Assert.AreEqual("available", l_oBike.state);
|
||||
Assert.That(l_oBike.gps, Is.Not.Null, "Gps position must never be empty.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeserializeObjectBikesAvailableValidResponse_NoBikeId()
|
||||
{
|
||||
const string VALID_RESPONSE = @"
|
||||
{
|
||||
""shareejson"": {
|
||||
|
||||
""authcookie"": 0,
|
||||
""apiserver"": ""https://tinkwwp.copri-bike.de"",
|
||||
""response"": ""bikes_available"",
|
||||
""bikes"": {
|
||||
""3399"": {
|
||||
""description"": ""Cargo Trike"",
|
||||
""state"": ""available"",
|
||||
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" },
|
||||
""station"" : ""4""
|
||||
},
|
||||
},
|
||||
""response_state"": ""OK"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
}
|
||||
}";
|
||||
|
||||
// Ensure that answer holds a valid bike.
|
||||
var l_oBike = CopriCallsStatic.DeserializeResponse<BikesAvailableResponse>(VALID_RESPONSE).bikes.FirstOrDefault().Value;
|
||||
Assert.NotNull(l_oBike, "Response must contain at leas one bike.");
|
||||
Assert.Greater(l_oBike.description.Length, 0, "Bike despcription must never be empty.");
|
||||
Assert.That(l_oBike.bike, Is.Null);
|
||||
Assert.That(l_oBike.station, Is.Not.Null);
|
||||
Assert.AreEqual("available", l_oBike.state);
|
||||
Assert.That(l_oBike.gps, Is.Not.Null, "Gps position must never be empty.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeserializeObjectBikesOccupiedValidResponse()
|
||||
{
|
||||
const string VALID_RESPONSE = @"
|
||||
{
|
||||
""shareejson"": {
|
||||
""response_state"": ""OK"",
|
||||
""bikes_occupied"": {
|
||||
""87781"": {
|
||||
""timeCode"": ""3630"",
|
||||
""state"": ""occupied"",
|
||||
""station"" : ""5"",
|
||||
""description"": ""Cargo Long"",
|
||||
""start_time"": ""2017-11-28 11:01:51.637747+01"",
|
||||
""bike"": ""8""
|
||||
},
|
||||
""87782"": {
|
||||
""timeCode"": ""2931"",
|
||||
""state"": ""occupied"",
|
||||
""station"" : ""4"",
|
||||
""description"": ""Cargo Long"",
|
||||
""start_time"": ""2017-11-28 13:06:55.147368+01"",
|
||||
""bike"": ""7""
|
||||
}
|
||||
},
|
||||
""authcookie"": ""b76b97e43a2d76b8499f32e6dd597af8"",
|
||||
""response"": ""user_bikes_occupied"",
|
||||
""apiserver"": ""https://tinkwwp.copri-bike.de"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
}
|
||||
}";
|
||||
|
||||
// Ensure that answer holds a valid bike.
|
||||
var l_oBike = CopriCallsStatic.DeserializeResponse<BikesReservedOccupiedResponse>(VALID_RESPONSE).bikes_occupied.FirstOrDefault().Value;
|
||||
Assert.NotNull(l_oBike, "Response must contain at leas one bike.");
|
||||
Assert.Greater(l_oBike.description.Length, 0, "Bike despcription must never be empty.");
|
||||
Assert.That(l_oBike.bike, Is.Not.Null);
|
||||
Assert.That(l_oBike.station, Is.Not.Null);
|
||||
Assert.Greater(l_oBike.state.Length, 0, "State info must never be null or empty.");
|
||||
// Todo: Requested bikes do not have a gps position. What is about booked bikes?
|
||||
// Assert.Greater(l_oBike.gps.Length, 0, "Gps position must never be empty.");
|
||||
Assert.Greater(l_oBike.start_time.Length, 0, "Time when request/ booking was performed must never be null or empty.");
|
||||
Assert.Greater(l_oBike.timeCode.Length, 0, "Booking code must never be null or empty.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Connector;
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
94
TestTINKLib/Fixtures/ObjectTests/Connector/TestFilter.cs
Normal file
94
TestTINKLib/Fixtures/ObjectTests/Connector/TestFilter.cs
Normal file
|
@ -0,0 +1,94 @@
|
|||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using System.Collections.Generic;
|
||||
using TINK.Model.Connector;
|
||||
using System.Linq;
|
||||
using TINK.Repository;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
/// <summary> Tests filter object. </summary>
|
||||
[TestFixture]
|
||||
public class TestFilter
|
||||
{
|
||||
/// <summary> Tests all stations. </summary>
|
||||
[Test]
|
||||
public void TestGetStationsAll()
|
||||
{
|
||||
var l_oConnector = new ConnectorCache(
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
new CopriCallsMemory(CopriCallsMemory.SampleSets.Set2, 1));
|
||||
|
||||
var l_oFilter = new FilteredConnector(new List<string> { "TINK", "Konrad" }, l_oConnector);
|
||||
var l_oStations = l_oFilter.Query.GetBikesAndStationsAsync().Result.Response;
|
||||
Assert.AreEqual(9, l_oStations.StationsAll.Count());
|
||||
|
||||
l_oFilter = new FilteredConnector(new List<string> { "TINK" }, l_oConnector);
|
||||
l_oStations = l_oFilter.Query.GetBikesAndStationsAsync().Result.Response;
|
||||
Assert.AreEqual(8, l_oStations.StationsAll.Count());
|
||||
|
||||
l_oFilter = new FilteredConnector(new List<string> { "Konrad" }, l_oConnector);
|
||||
l_oStations = l_oFilter.Query.GetBikesAndStationsAsync().Result.Response;
|
||||
Assert.AreEqual(2, l_oStations.StationsAll.Count());
|
||||
|
||||
l_oFilter = new FilteredConnector(new List<string> { "AGroupNamedNonsensDoesNotExist" }, l_oConnector);
|
||||
l_oStations = l_oFilter.Query.GetBikesAndStationsAsync().Result.Response;
|
||||
Assert.AreEqual(0, l_oStations.StationsAll.Count());
|
||||
|
||||
l_oFilter = new FilteredConnector(new List<string>(), l_oConnector);
|
||||
l_oStations = l_oFilter.Query.GetBikesAndStationsAsync().Result.Response;
|
||||
Assert.AreEqual(9, l_oStations.StationsAll.Count());
|
||||
|
||||
l_oFilter = new FilteredConnector(null, l_oConnector);
|
||||
l_oStations = l_oFilter.Query.GetBikesAndStationsAsync().Result.Response;
|
||||
Assert.AreEqual(9, l_oStations.StationsAll.Count(), "Null means filter none.");
|
||||
}
|
||||
|
||||
/// <summary> Tests all stations. </summary>
|
||||
[Test]
|
||||
public void TestGetBikesAll()
|
||||
{
|
||||
var l_oConnector = new ConnectorCache(
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
new CopriCallsMemory(CopriCallsMemory.SampleSets.Set2, 1));
|
||||
|
||||
var l_oFilter = new FilteredConnector(new List<string> { "TINK", "Konrad" }, l_oConnector);
|
||||
var l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
|
||||
Assert.AreEqual(12, l_oBikes.Count());
|
||||
|
||||
l_oFilter = new FilteredConnector(new List<string> { "TINK" }, l_oConnector);
|
||||
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
|
||||
Assert.AreEqual(11, l_oBikes.Count());
|
||||
|
||||
l_oFilter = new FilteredConnector(new List<string> { "Konrad" }, l_oConnector);
|
||||
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
|
||||
Assert.AreEqual(1, l_oBikes.Count());
|
||||
|
||||
l_oFilter = new FilteredConnector(new List<string> { "AGroupNamedNonsensDoesNotExist" }, l_oConnector);
|
||||
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
|
||||
Assert.AreEqual(0, l_oBikes.Count());
|
||||
|
||||
l_oFilter = new FilteredConnector(new List<string>(), l_oConnector);
|
||||
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
|
||||
Assert.AreEqual(12, l_oBikes.Count(), "List with zero element means filter all.");
|
||||
|
||||
l_oFilter = new FilteredConnector(null, l_oConnector);
|
||||
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
|
||||
Assert.AreEqual(12, l_oBikes.Count(), "Null means filter none.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIsConnected()
|
||||
{
|
||||
var l_oMock = MockRepository.GenerateMock<IConnector>();
|
||||
l_oMock.Expect(x => x.IsConnected).Return(true) ;
|
||||
Assert.IsTrue(new FilteredConnector(new List<string>(), l_oMock).IsConnected);
|
||||
|
||||
l_oMock = MockRepository.GenerateMock<IConnector>();
|
||||
l_oMock.Expect(x => x.IsConnected).Return(false);
|
||||
Assert.IsFalse(new FilteredConnector(new List<string>(), l_oMock).IsConnected);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,615 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using TINK.Model.Bike;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Response;
|
||||
using JsonConvertRethrow = TINK.Repository.Response.JsonConvertRethrow;
|
||||
|
||||
namespace TestTINKLib.Fixtures.Connector
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestTextToTypeHelper
|
||||
{
|
||||
[Test]
|
||||
public void TestGetWheelType_InvalidDescription()
|
||||
{
|
||||
var l_oInfo = new BikeInfoBase();
|
||||
|
||||
// Verify prerequisites
|
||||
Assert.IsNull(l_oInfo.description);
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.IsNull(TextToTypeHelper.GetWheelType(l_oInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetWheelType()
|
||||
{
|
||||
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
||||
{
|
||||
""bike"" : ""2"",
|
||||
""bike_group"" : [ ""TINK"" ],
|
||||
""description"" : ""Cargo Long"",
|
||||
""gps"" : { ""latitude"": ""47.6612083333"", ""longitude"": ""9.16637533333"" },
|
||||
""station"" : ""9"",
|
||||
""state"" : ""available""
|
||||
}");
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.AreEqual(WheelType.Two, TextToTypeHelper.GetWheelType(l_oInfo));
|
||||
|
||||
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
||||
{
|
||||
""bike"" : ""11"",
|
||||
""bike_group"" : [ ""TINK"" ],
|
||||
""description"" : ""Cargo Trike"",
|
||||
""gps"" : { ""latitude"": ""47.665051"", ""longitude"": ""9.174096"" },
|
||||
""station"" : ""1"",
|
||||
""state"" : ""available""
|
||||
}");
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.AreEqual(WheelType.Trike, TextToTypeHelper.GetWheelType(l_oInfo));
|
||||
|
||||
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
||||
{
|
||||
""bike"" : ""51"",
|
||||
""bike_group"" : [ ""Konrad"" ],
|
||||
""description"" : ""Demo Stadtrad"",
|
||||
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
||||
""station"" : ""8"",
|
||||
""state"" : ""available""
|
||||
}");
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.AreEqual(WheelType.Two, TextToTypeHelper.GetWheelType(l_oInfo));
|
||||
|
||||
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
||||
{
|
||||
""bike"" : ""51"",
|
||||
""bike_group"" : [ ""Konrad"" ],
|
||||
""description"" : ""Stadtrad"",
|
||||
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
||||
""station"" : ""8"",
|
||||
""state"" : ""available""
|
||||
}");
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.AreEqual(WheelType.Two, TextToTypeHelper.GetWheelType(l_oInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetTypeOfBike_InvalidDescription()
|
||||
{
|
||||
var l_oInfo = new BikeInfoBase();
|
||||
|
||||
// Verify prerequisites
|
||||
Assert.IsNull(l_oInfo.description);
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.IsNull(TextToTypeHelper.GetTypeOfBike(l_oInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetTypeOfBike()
|
||||
{
|
||||
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
||||
{
|
||||
""bike"" : ""2"",
|
||||
""bike_group"" : [ ""TINK"" ],
|
||||
""description"" : ""Cargo Long"",
|
||||
""gps"" : { ""latitude"": ""47.6612083333"", ""longitude"": ""9.16637533333"" },
|
||||
""station"" : ""9"",
|
||||
""state"" : ""available""
|
||||
}");
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.AreEqual(TypeOfBike.Cargo, TextToTypeHelper.GetTypeOfBike(l_oInfo));
|
||||
|
||||
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
||||
{
|
||||
""bike"" : ""11"",
|
||||
""bike_group"" : [ ""TINK"" ],
|
||||
""description"" : ""Cargo Trike"",
|
||||
""gps"" : { ""latitude"": ""47.665051"", ""longitude"": ""9.174096"" },
|
||||
""station"" : ""1"",
|
||||
""state"" : ""available""
|
||||
}");
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.AreEqual(TypeOfBike.Cargo, TextToTypeHelper.GetTypeOfBike(l_oInfo));
|
||||
|
||||
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
||||
{
|
||||
""bike"" : ""51"",
|
||||
""bike_group"" : [ ""Konrad"" ],
|
||||
""description"" : ""Demo Stadtrad"",
|
||||
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
||||
""station"" : ""8"",
|
||||
""state"" : ""available""
|
||||
}");
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.AreEqual(TypeOfBike.Citybike, TextToTypeHelper.GetTypeOfBike(l_oInfo));
|
||||
|
||||
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
||||
{
|
||||
""bike"" : ""51"",
|
||||
""bike_group"" : [ ""Konrad"" ],
|
||||
""description"" : ""Stadtrad"",
|
||||
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
||||
""station"" : ""8"",
|
||||
""state"" : ""available""
|
||||
}");
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.AreEqual(TypeOfBike.Citybike, TextToTypeHelper.GetTypeOfBike(l_oInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetState_InvalidDescription()
|
||||
{
|
||||
var l_oInfo = new BikeInfoBase();
|
||||
|
||||
// Verify prerequisites
|
||||
Assert.IsNull(l_oInfo.state);
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.Throws<InvalidResponseException<BikeInfoBase>>(() => TextToTypeHelper.GetState(l_oInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetIsDemo()
|
||||
{
|
||||
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
||||
{
|
||||
""bike"" : ""2"",
|
||||
""bike_group"" : [ ""TINK"" ],
|
||||
""description"" : ""Cargo Long"",
|
||||
""gps"" : { ""latitude"": ""47.6612083333"", ""longitude"": ""9.16637533333"" },
|
||||
""station"" : ""9"",
|
||||
""state"" : ""available""
|
||||
}");
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.IsFalse(TextToTypeHelper.GetIsDemo(l_oInfo));
|
||||
|
||||
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
||||
{
|
||||
""bike"" : ""11"",
|
||||
""bike_group"" : [ ""TINK"" ],
|
||||
""description"" : ""Cargo Trike"",
|
||||
""gps"" : { ""latitude"": ""47.665051"", ""longitude"": ""9.174096"" },
|
||||
""station"" : ""1"",
|
||||
""state"" : ""available""
|
||||
}");
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.IsFalse(TextToTypeHelper.GetIsDemo(l_oInfo));
|
||||
|
||||
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
||||
{
|
||||
""bike"" : ""51"",
|
||||
""bike_group"" : [ ""Konrad"" ],
|
||||
""description"" : ""Demo Stadtrad"",
|
||||
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
||||
""station"" : ""8"",
|
||||
""state"" : ""available""
|
||||
}");
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.IsTrue(TextToTypeHelper.GetIsDemo(l_oInfo));
|
||||
|
||||
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
|
||||
{
|
||||
""bike"" : ""51"",
|
||||
""bike_group"" : [ ""Konrad"" ],
|
||||
""description"" : ""Stadtrad"",
|
||||
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
|
||||
""station"" : ""8"",
|
||||
""state"" : ""available""
|
||||
}");
|
||||
|
||||
// Verify behaviour of member.
|
||||
Assert.IsFalse(TextToTypeHelper.GetIsDemo(l_oInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetPosition()
|
||||
{
|
||||
Assert.AreEqual(1.234d, TextToTypeHelper.GetPosition(JsonConvert.DeserializeObject<GpsInfo>("{ \"latitude\" : \"1.234\", \"longitude\" : \"5.678\"}")).Latitude);
|
||||
Assert.AreEqual(5.678d, TextToTypeHelper.GetPosition(JsonConvert.DeserializeObject<GpsInfo>("{ \"latitude\" : \"1.234\", \"longitude\" : \"5.678\"}")).Longitude);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetStationGroup_Invalid()
|
||||
{
|
||||
var l_oStation = JsonConvertRethrow.DeserializeObject<StationsAllResponse.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_TINK()
|
||||
{
|
||||
var l_oStation = JsonConvertRethrow.DeserializeObject<StationsAllResponse.StationInfo>(
|
||||
@"{
|
||||
""station"" : ""4"",
|
||||
""station_group"" : [ ""TINK"" ],
|
||||
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" }
|
||||
}");
|
||||
|
||||
Assert.AreEqual("TINK", string.Join(",", l_oStation.GetGroup().ToArray()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetStationGroup_TINKAndKonrad()
|
||||
{
|
||||
var l_oStation = JsonConvertRethrow.DeserializeObject<StationsAllResponse.StationInfo>(
|
||||
@"{
|
||||
""station"" : ""4"",
|
||||
""station_group"": [ ""TINK"", ""Konrad"" ],
|
||||
""gps"" : { ""latitude"": ""47.6586936667"", ""longitude"": ""9.16863116667"" }
|
||||
}");
|
||||
|
||||
Assert.AreEqual("TINK,Konrad", string.Join(",", l_oStation.GetGroup().ToArray()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikeGroup_TINK()
|
||||
{
|
||||
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
||||
@"{
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""18"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""bike_group"" : [ ""TINK"" ],
|
||||
""station"" : ""13"",
|
||||
}");
|
||||
|
||||
Assert.AreEqual("TINK", string.Join(",", l_oBike.GetGroup().ToArray()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikeGroup_TINKCopri()
|
||||
{
|
||||
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
||||
@"{
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""18"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""bike_group"" : [ ""TINK"" ],
|
||||
""system"" : ""BC"",
|
||||
""station"" : ""13"",
|
||||
}");
|
||||
|
||||
Assert.AreEqual("TINK", string.Join(",", l_oBike.GetGroup().ToArray()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikeGroup_TINKSMS()
|
||||
{
|
||||
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
||||
@"{
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""18"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""bike_group"" : [ ""TINK"" ],
|
||||
""system"" : ""Lock"",
|
||||
""station"" : ""13"",
|
||||
}");
|
||||
|
||||
Assert.AreEqual("TINK", string.Join(",", l_oBike.GetGroup().ToArray()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikeGroup_Konrad()
|
||||
{
|
||||
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
||||
@"{
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""18"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""bike_group"" : [ ""Konrad"" ],
|
||||
""station"" : ""13"",
|
||||
}");
|
||||
|
||||
Assert.AreEqual("Konrad", string.Join(",", l_oBike.GetGroup().ToArray()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBikeGroup_Null()
|
||||
{
|
||||
var l_oBike = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(
|
||||
@"{
|
||||
""state"" : ""available"",
|
||||
""bike"" : ""18"",
|
||||
""description"" : ""Cargo Long"",
|
||||
""station"" : ""13"",
|
||||
}");
|
||||
|
||||
Assert.AreEqual(0, l_oBike.GetGroup().ToArray().Length);
|
||||
}
|
||||
[Test]
|
||||
public void TestGetAuthGroup()
|
||||
{
|
||||
var l_oResponse = JsonConvertRethrow.DeserializeObject<AuthorizationResponse>(@"
|
||||
{
|
||||
""response"" : ""authorization"",
|
||||
""authcookie"" : ""4da3044c8657a04ba60e2eaa753bc51a"",
|
||||
""user_group"" : [ ""TINK"", ""Konrad"" ],
|
||||
""response_state"" : ""OK"",
|
||||
""apiserver"" : ""https://tinkwwp.copri-bike.de""
|
||||
}");
|
||||
|
||||
Assert.AreEqual(2, l_oResponse.GetGroup().ToList().Count);
|
||||
Assert.AreEqual(FilterHelper.FILTERTINKGENERAL, l_oResponse.GetGroup().ToList()[0]);
|
||||
Assert.AreEqual("Konrad", l_oResponse.GetGroup().ToList()[1]);
|
||||
}
|
||||
|
||||
[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.AreEqual("Tunk,Unk", TextToTypeHelper.GetGroup(TextToTypeHelper.GetGroup(new [] { "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"" : ""TINK 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"" : [ ""TINK"" ],
|
||||
""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.AreEqual(
|
||||
99,
|
||||
TextToTypeHelper.GetUserKey(l_oInfo)[0]);
|
||||
Assert.AreEqual(
|
||||
104,
|
||||
TextToTypeHelper.GetUserKey(l_oInfo)[1]);
|
||||
}
|
||||
|
||||
[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"" : ""TINK 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"" : [ ""TINK"" ],
|
||||
""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.AreEqual(
|
||||
237,
|
||||
TextToTypeHelper.GetAdminKey(l_oInfo)[0]);
|
||||
Assert.AreEqual(
|
||||
29,
|
||||
TextToTypeHelper.GetAdminKey(l_oInfo)[1]);
|
||||
}
|
||||
|
||||
[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"" : ""TINK 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"" : [ ""TINK"" ],
|
||||
""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.AreEqual(
|
||||
238,
|
||||
TextToTypeHelper.GetSeed(l_oInfo)[0]);
|
||||
Assert.AreEqual(
|
||||
176,
|
||||
TextToTypeHelper.GetSeed(l_oInfo)[1]);
|
||||
}
|
||||
|
||||
[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"" : ""TINK 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"" : [ ""TINK"" ],
|
||||
""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.AreEqual(
|
||||
0,
|
||||
TextToTypeHelper.GetSeed(l_oInfo).Length);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
TextToTypeHelper.GetUserKey(l_oInfo).Length);
|
||||
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
TextToTypeHelper.GetAdminKey(l_oInfo).Length);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBluetoothLockId_FromBikeInfo_Invalid()
|
||||
{
|
||||
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
||||
{
|
||||
}");
|
||||
|
||||
Assert.AreEqual(0, TextToTypeHelper.GetBluetoothLockId (l_oInfo));
|
||||
|
||||
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
||||
{
|
||||
""Ilockit_ID"": """"
|
||||
}");
|
||||
|
||||
Assert.AreEqual(0, TextToTypeHelper.GetBluetoothLockId(l_oInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBluetoothLockId_FromBikeInfo()
|
||||
{
|
||||
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
|
||||
{
|
||||
""Ilockit_ID"": ""ISHAREIT-132""
|
||||
}");
|
||||
|
||||
Assert.AreEqual(
|
||||
132,
|
||||
TextToTypeHelper.GetBluetoothLockId(l_oInfo));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBluetoothLockId_FromString_Invalid()
|
||||
{
|
||||
Assert.AreEqual(0, TextToLockItTypeHelper.GetBluetoothLockId((string)null));
|
||||
Assert.AreEqual(0, TextToLockItTypeHelper.GetBluetoothLockId(""));
|
||||
|
||||
Assert.AreEqual(0, TextToLockItTypeHelper.GetBluetoothLockId("HubbaBubba"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBluetoothLockId_FromString()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
132,
|
||||
TextToLockItTypeHelper.GetBluetoothLockId("ISHAREIT-132"));
|
||||
|
||||
Assert.AreEqual(
|
||||
132,
|
||||
TextToLockItTypeHelper.GetBluetoothLockId("ISHAREIT+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>());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue