mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-05-11 12:17:28 +02:00
Version 3.0.381
This commit is contained in:
parent
f963c0a219
commit
3a363acf3a
1525 changed files with 60589 additions and 125098 deletions
|
@ -0,0 +1,68 @@
|
|||
using NUnit.Framework;
|
||||
using ShareeBike.Model.Bike;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using ShareeBike.Model.State;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BikeInfoMutable = ShareeBike.Model.Bike.BC.BikeInfoMutable;
|
||||
|
||||
namespace SharedBusinessLogic.Tests
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Moved to SharedBusinessLogic.Tests (.Net Core)
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class TestBikeCollectionSerializeJSON
|
||||
{
|
||||
[Test, Ignore("Disabled because serialization does no more work due to inheritance since commit ec14b93b.")]
|
||||
public void Test_SerializeJSON()
|
||||
{
|
||||
var l_oCollSource = new BikeCollectionMutable
|
||||
{
|
||||
new BikeInfoMutable(57, false, new List<string> { "ShareeBike" }, WheelType.Two, TypeOfBike.Allround)
|
||||
};
|
||||
|
||||
// Verify prerequisites.
|
||||
Assert.AreEqual(1, l_oCollSource.Count);
|
||||
Assert.AreEqual(57, l_oCollSource[0].Id);
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oCollSource[0].State.Value);
|
||||
Assert.IsNull(l_oCollSource[0].State.MailAddress);
|
||||
Assert.IsNull(l_oCollSource[0].State.Code);
|
||||
Assert.IsNull(l_oCollSource[0].State.From);
|
||||
|
||||
// Serialize object and verify json
|
||||
var l_oDetected = JsonConvert.SerializeObject(l_oCollSource, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
|
||||
const string EXPECTED = @"
|
||||
[
|
||||
{
|
||||
""Id"": 57,
|
||||
""CurrentStation"": null,
|
||||
""WheelType"": 1,
|
||||
""TypeOfBike"": 0,
|
||||
""State"": {
|
||||
""StateInfoObject"": {
|
||||
""$type"": ""ShareeBike.Model.State.StateAvailableInfo, SharedBusinessLogic""
|
||||
}
|
||||
}
|
||||
}
|
||||
]";
|
||||
|
||||
Assert.AreEqual(
|
||||
TestHelper.PrepareXmlForStringCompare(EXPECTED),
|
||||
TestHelper.PrepareXmlForStringCompare(l_oDetected));
|
||||
|
||||
// Deserialize object.
|
||||
var l_oBikeCollectionTarget = JsonConvert.DeserializeObject<BikeCollectionMutable>(l_oDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
|
||||
|
||||
// Verify state.
|
||||
Assert.AreEqual(1, l_oBikeCollectionTarget.Count);
|
||||
Assert.AreEqual(57, l_oBikeCollectionTarget[0].Id);
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeCollectionTarget[0].State.Value);
|
||||
Assert.IsNull(l_oBikeCollectionTarget[0].State.MailAddress);
|
||||
Assert.IsNull(l_oBikeCollectionTarget[0].State.Code);
|
||||
Assert.IsNull(l_oBikeCollectionTarget[0].State.From);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ShareeBike.Model.Bike;
|
||||
using ShareeBike.Model.State;
|
||||
|
||||
using BikeInfoMutable = ShareeBike.Model.Bike.BC.BikeInfoMutable;
|
||||
|
||||
namespace SharedBusinessLogic.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Moved to SharedBusinessLogic.Tests (.Net Core)
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class TestBikeSerializeJSON
|
||||
{
|
||||
[Test, Ignore("Disabled because serialization does no more work due to inheritance since commit ec14b93b.")]
|
||||
public void TestConstruct_SerializeJSON_Disposable()
|
||||
{
|
||||
// Create object to test.
|
||||
var l_oBikeSource = new BikeInfoMutable(3, false, new List<string> { "ShareeBike" }, WheelType.Two, TypeOfBike.Cargo, p_oDateTimeProvider: () => new DateTime(1970, 1, 1));
|
||||
|
||||
// Verify prerequisites
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeSource.State.Value);
|
||||
Assert.IsNull(l_oBikeSource.State.MailAddress);
|
||||
Assert.IsNull(l_oBikeSource.State.Code);
|
||||
Assert.IsNull(l_oBikeSource.State.From);
|
||||
|
||||
// Serialize object and verify.
|
||||
var l_oDetected = JsonConvert.SerializeObject(l_oBikeSource, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
|
||||
const string EXPECTED = @"
|
||||
{
|
||||
""Id"": 3,
|
||||
""CurrentStation"": null,
|
||||
""WheelType"": 1,
|
||||
""TypeOfBike"": 1,
|
||||
""State"": {
|
||||
""StateInfoObject"": {
|
||||
""$type"": ""ShareeBike.Model.State.StateAvailableInfo, SharedBusinessLogic""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
Assert.AreEqual(
|
||||
TestHelper.PrepareXmlForStringCompare(EXPECTED),
|
||||
TestHelper.PrepareXmlForStringCompare(l_oDetected));
|
||||
|
||||
// Deserialize object.
|
||||
var l_oBikeTarget = JsonConvert.DeserializeObject<BikeInfoMutable>(l_oDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
|
||||
|
||||
// Verify state.
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeTarget.State.Value);
|
||||
Assert.IsNull(l_oBikeTarget.State.MailAddress);
|
||||
Assert.IsNull(l_oBikeTarget.State.Code);
|
||||
Assert.IsNull(l_oBikeTarget.State.From);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,291 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using ShareeBike.Repository;
|
||||
using ShareeBike.Repository.Exception;
|
||||
using ShareeBike.Repository.Response;
|
||||
using ShareeBike.Repository.Response.Stations;
|
||||
|
||||
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">Mail address 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 logoutResponse;
|
||||
|
||||
logoutResponse = Post(l_oCommand, copriHost);
|
||||
|
||||
/// Extract session cookie from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<AuthorizationoutResponse>>(logoutResponse)?.shareejson;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get list of stations from file.
|
||||
/// </summary>
|
||||
/// <param name="copriHost">URL of the copri host to connect to.</param>
|
||||
/// <param name="merchantId">Id of the merchant.</param>
|
||||
/// <param name="cookie">Auto cookie of user if user is logged in.</param>
|
||||
/// <returns>List of files.</returns>
|
||||
public static StationsAvailableResponse GetStationsAllCall(
|
||||
string copriHost,
|
||||
string merchantId,
|
||||
string cookie = null)
|
||||
{
|
||||
var l_oCommand = string.Format(
|
||||
"request=stations_all&authcookie={0}{1}",
|
||||
cookie,
|
||||
merchantId);
|
||||
|
||||
#if !WINDOWS_UWP
|
||||
string l_oStationsAllResponse;
|
||||
|
||||
l_oStationsAllResponse = Post(l_oCommand, copriHost);
|
||||
|
||||
// Extract bikes from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<StationsAvailableResponse>>(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="merchantId">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 active user from Copri.
|
||||
/// </summary>
|
||||
/// <param name="merchantId">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="merchantId">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 merchantId,
|
||||
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,
|
||||
merchantId);
|
||||
|
||||
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 cancel booking request response.
|
||||
/// </summary>
|
||||
/// <param name="merchantId">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 BookingActionResponse DoCancelReservationCall(
|
||||
string copriHost,
|
||||
string merchantId,
|
||||
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,
|
||||
merchantId);
|
||||
string l_oBikesAvaialbeResponse;
|
||||
|
||||
l_oBikesAvaialbeResponse = Post(l_oCommand, copriHost);
|
||||
|
||||
// Extract bikes from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<BookingActionResponse>>(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,678 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using ShareeBike.Model;
|
||||
using ShareeBike.Model.Services.CopriApi.ServerUris;
|
||||
using ShareeBike.Repository;
|
||||
using ShareeBike.Repository.Exception;
|
||||
using ShareeBike.Repository.Request;
|
||||
using ShareeBike.Repository.Response;
|
||||
using static ShareeBike.Repository.CopriCallsHttps;
|
||||
|
||||
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 = "SharedBusinessLogic.Tests";
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Thread.Sleep(2000); // Sleep, otherwise copri will block requested calls.
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIsConnected()
|
||||
{
|
||||
Assert.That(new CopriCallsHttps(new Uri("http://127.0.0.0/api"), new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)), "123").IsConnected, Is.True);
|
||||
}
|
||||
|
||||
[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(ShareeBikeApp.MerchantId, null /*UI language */).DoAuthorization(
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
password,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
||||
|
||||
var l_oSessionCookieJM_Dev1 = DoAuthorizationAsync(
|
||||
url,
|
||||
command(SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd),
|
||||
() => command("*******"),
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogin)}").Result;
|
||||
|
||||
Assert.That(
|
||||
l_oSessionCookieJM_Dev1.authcookie, Is.EqualTo(string.Format("{0}{1}", "6103_4da3044c8657a04ba60e2eaa753bc51a_", "oiF2kahH")),
|
||||
"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(ShareeBikeApp.MerchantId, null /*UI language */).DoAuthorization(
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerGibtsNet.Mail,
|
||||
password,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerGibtsNet.DeviceId);
|
||||
|
||||
var l_oSessionCookieJM_Dev1 = DoAuthorizationAsync(
|
||||
url,
|
||||
command(SharedBusinessLogic.Tests.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.That(l_oSessionCookieJM_Dev1.authcookie, Is.Empty);
|
||||
|
||||
Assert.That(
|
||||
l_oSessionCookieJM_Dev1.response, Is.EqualTo("authorization"));
|
||||
|
||||
Assert.That(
|
||||
l_oSessionCookieJM_Dev1.response_state, Is.EqualTo("Failure: cannot generate authcookie"));
|
||||
}
|
||||
|
||||
/// <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,
|
||||
ShareeBikeApp.MerchantId,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
||||
|
||||
Assert.That(
|
||||
string.IsNullOrEmpty(l_oSessionCookie?.authcookie), Is.False,
|
||||
"Prerequisites not matched: User must be logged on before beeing able to log out.");
|
||||
|
||||
// Verify logout
|
||||
try
|
||||
{
|
||||
Assert.That(DoAuthoutAsync(
|
||||
url,
|
||||
new RequestBuilderLoggedIn(
|
||||
ShareeBikeApp.MerchantId,
|
||||
null /*UI language */,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).DoAuthout(),
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogout)}"
|
||||
).Result.GetIsResponseOk(), Is.Not.Null);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Log in again to ensure that tests do not change state of database (assumtion: user is always logged in).
|
||||
CopriCallsHttpsReference.DoAuthorizeCall(
|
||||
url,
|
||||
ShareeBikeApp.MerchantId,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
||||
SharedBusinessLogic.Tests.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,
|
||||
ShareeBikeApp.MerchantId,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
||||
|
||||
Assert.That(
|
||||
string.IsNullOrEmpty(l_oLoginResponse?.authcookie), Is.False,
|
||||
"Prerequisites not matched: User must be logged out before beeing able to log out.");
|
||||
|
||||
CopriCallsHttpsReference.DoAuthoutCall(url, ShareeBikeApp.MerchantId, l_oLoginResponse.authcookie);
|
||||
|
||||
try
|
||||
{
|
||||
// Verify logout
|
||||
Assert.Throws<AuthcookieNotDefinedException>(
|
||||
() => DoAuthoutAsync(
|
||||
url,
|
||||
new RequestBuilderLoggedIn(ShareeBikeApp.MerchantId, null /*UI language */, 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,
|
||||
ShareeBikeApp.MerchantId,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
||||
SharedBusinessLogic.Tests.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,
|
||||
ShareeBikeApp.MerchantId,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
||||
|
||||
Assert.That(
|
||||
string.IsNullOrEmpty(l_oSessionCookie?.authcookie), Is.False,
|
||||
"Prerequisites not matched: User must be logged on before beeing able to log out.");
|
||||
|
||||
// Verify logout that expected excepton is thrown.
|
||||
try
|
||||
{
|
||||
Assert.That(
|
||||
DoAuthoutAsync(
|
||||
url,
|
||||
new RequestBuilderLoggedIn(
|
||||
ShareeBikeApp.MerchantId,
|
||||
null /*UI language */,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerKeksGibtsNet.AuthCookie).DoAuthout(),
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestLogout_AuthcookieUnknown)}"
|
||||
).Result.response_state, Is.EqualTo("Failure 1001: authcookie not defined"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Log in again to ensure that tests do not change state of database (assumtion: user is always logged in).
|
||||
CopriCallsHttpsReference.DoAuthorizeCall(
|
||||
url,
|
||||
ShareeBikeApp.MerchantId,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Mail,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.Pwd,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.DeviceId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// From COPRI version v4.1 switched from ShareeBike devel CopriServerUriList.ShareeBike_DEVEL and CopriServerUriList.ShareeBike_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, ShareeBikeApp.MerchantId, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes;
|
||||
Assert.That(bikesReference, Is.Not.Null);
|
||||
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(
|
||||
ShareeBikeApp.MerchantId,
|
||||
null /*UI language */,
|
||||
SharedBusinessLogic.Tests.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.That(
|
||||
bike.description.Length, Is.GreaterThan(0),
|
||||
"Bike description must never be empty.");
|
||||
|
||||
Assert.That(
|
||||
bike.bike,
|
||||
Is.Not.Null,
|
||||
"Bike index must never be null");
|
||||
|
||||
Assert.That(
|
||||
bike.state, Is.EqualTo("available"),
|
||||
"Bike state must be available");
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// From COPRI version v4.1 switched from ShareeBike devel CopriServerUriList.ShareeBike_DEVEL and CopriServerUriList.ShareeBike_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, ShareeBikeApp.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(ShareeBikeApp.MerchantId, null /*UI language */).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.That(
|
||||
bike.description.Length, Is.GreaterThan(0),
|
||||
"Bike description must never be empty.");
|
||||
|
||||
Assert.That(
|
||||
bike.bike,
|
||||
Is.Not.Null,
|
||||
"Bike index must never be null");
|
||||
|
||||
Assert.That(
|
||||
bike.state, Is.EqualTo("available"),
|
||||
"Bike state must be available");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attention: Behaves different if called with a period smaller 15minutes because bike will already 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.That(
|
||||
CopriCallsHttpsReference.GetBikesOccupiedCall(url, ShareeBikeApp.MerchantId, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes_occupied.Count,
|
||||
Is.LessThan(3),
|
||||
"Too many bikes requested/ booked.");
|
||||
|
||||
var l_oBikesAvailable = CopriCallsHttpsReference.GetBikesAvailableCall(CopriServerUriList.DevelopUri.AbsoluteUri, ShareeBikeApp.MerchantId, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes;
|
||||
|
||||
Assert.That(
|
||||
l_oBikesAvailable.Count, Is.GreaterThan(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.That(
|
||||
CopriCallsHttpsReference.GetBikesAvailableCall(url, ShareeBikeApp.MerchantId, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes?.FirstOrDefault(x => x.Value.bike == l_oBikeId).Value, Is.Not.Null,
|
||||
"Prerequisites check failed: Bike with given id must be available;");
|
||||
|
||||
var l_oBookingResponse = DoReserveAsync(
|
||||
CopriServerUriList.DevelopUri.AbsoluteUri,
|
||||
new RequestBuilderLoggedIn(
|
||||
ShareeBikeApp.MerchantId, null /*UI language */, SharedBusinessLogic.Tests.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.That(l_oBookingResponse.response_state, Is.EqualTo(string.Format("OK: requested bike {0}", l_oBikeId)));
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Clean up to ensure that running tests does not modify data base.
|
||||
CopriCallsHttpsReference.DoCancelReservationCall(url, ShareeBikeApp.MerchantId, l_oBikeId, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attention: Behaves different if called with a period smaller 15minutes because bike will already 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.That(
|
||||
CopriCallsHttpsReference.GetBikesOccupiedCall(url, ShareeBikeApp.MerchantId, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes_occupied.Count,
|
||||
Is.LessThan(3),
|
||||
"Too many bikes requested/ booked.");
|
||||
|
||||
var l_oBikesAvailable = CopriCallsHttpsReference.GetBikesAvailableCall(CopriServerUriList.DevelopUri.AbsoluteUri, ShareeBikeApp.MerchantId, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes;
|
||||
|
||||
Assert.That(
|
||||
l_oBikesAvailable.Count, Is.GreaterThan(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, ShareeBikeApp.MerchantId, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes?.FirstOrDefault(x => x.Value.bike == l_oBikeId).Value;
|
||||
if (l_oBikeToCancel != null)
|
||||
{
|
||||
// Bike is available. Do request before running test.
|
||||
CopriCallsHttpsReference.DoReserveCall(url, ShareeBikeApp.MerchantId, l_oBikeId, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie);
|
||||
}
|
||||
|
||||
// State of bike for which to cancel booking must be reserved.
|
||||
var l_oReservedBike = CopriCallsHttpsReference.GetBikesOccupiedCall(url, ShareeBikeApp.MerchantId, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).bikes_occupied.FirstOrDefault(x => x.Value.bike == l_oBikeId).Value;
|
||||
Assert.That(l_oReservedBike, Is.Not.Null, string.Format("Setup test failed. Bike with id {0} must be booked before verifying cancel of booking.", l_oReservedBike));
|
||||
Assert.That(l_oReservedBike.state, Is.EqualTo("requested"), 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(
|
||||
ShareeBikeApp.MerchantId,
|
||||
null /*UI language */,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).DoReserve(l_oBikeId)).Result;
|
||||
|
||||
try
|
||||
{
|
||||
Assert.That(l_oBookingResponse.response_state, Is.EqualTo(string.Format("OK: canceled bike {0}", l_oBikeId)));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Clean up to ensure that running tests does not modify data base.
|
||||
CopriCallsHttpsReference.DoCancelReservationCall(url, ShareeBikeApp.MerchantId, l_oBikeId, SharedBusinessLogic.Tests.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, ShareeBikeApp.MerchantId, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes_occupied;
|
||||
if (bikesOccupied == null || bikesOccupied.Count < 1)
|
||||
{
|
||||
// There must be at least one bike booked.
|
||||
var bikesAvailable = CopriCallsHttpsReference.GetBikesAvailableCall(
|
||||
url,
|
||||
ShareeBikeApp.MerchantId,
|
||||
SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes;
|
||||
|
||||
Assert.That(
|
||||
bikesAvailable.Count, Is.GreaterThan(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",
|
||||
ShareeBikeApp.MerchantId,
|
||||
bike.bike,
|
||||
SharedBusinessLogic.Tests.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, ShareeBikeApp.MerchantId, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie)?.bikes_occupied?.FirstOrDefault().Value;
|
||||
Assert.That(l_oBike, Is.Not.Null, "Response on GetBikesOccupiedCall of must contain at least one bike.");
|
||||
|
||||
l_oBookingResponse = GetBikesOccupiedAsync(
|
||||
url,
|
||||
new RequestBuilderLoggedIn(ShareeBikeApp.MerchantId, null /*UI language */, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).GetBikesOccupied(),
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetBikesOccupiedCall_SomeRequestedBooked)}").Result;
|
||||
|
||||
// Check first entry.
|
||||
Assert.That(
|
||||
l_oBookingResponse.authcookie, Is.EqualTo(string.Format("{0}{1}", SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie, ShareeBikeApp.MerchantId)));
|
||||
|
||||
Assert.That(l_oBike.description.Length, Is.GreaterThan(0), "Bike description 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.That(l_oBike.state.Length, Is.GreaterThan(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.That(l_oBike.start_time.Length, Is.GreaterThan(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(ShareeBikeApp.MerchantId, null /*UI language */, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerKeksGibtsNet.AuthCookie).GetBikesOccupied();
|
||||
|
||||
var l_oBookingResponse = GetBikesOccupiedAsync(
|
||||
url,
|
||||
request,
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetBikesOccupiedCall_KeksGibtsNet)}").Result;
|
||||
|
||||
Assert.That(
|
||||
l_oBookingResponse.response_state, Is.EqualTo("Failure 1001: authcookie on primary not defined")); // 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 ShareeBike devel CopriServerUriList.ShareeBike_DEVEL and CopriServerUriList.ShareeBike_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, ShareeBikeApp.MerchantId)?.stations;
|
||||
Assert.That(
|
||||
l_oStationsReference != null && l_oStationsReference.Count > 0, Is.True,
|
||||
"Prerequisites are not matched: There are no stations.");
|
||||
|
||||
// Verify implementation
|
||||
var l_oStationsAll = GetStationsAsync(url, new RequestBuilder(ShareeBikeApp.MerchantId, null /*UI language */).GetStations()).Result;
|
||||
Assert.That(l_oStationsAll?.stations, Is.Not.Null);
|
||||
Assert.That(l_oStationsAll.stations.Count, Is.GreaterThan(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the member.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// From COPRI version v4.1 switched from ShareeBike devel CopriServerUriList.ShareeBike_DEVEL and CopriServerUriList.ShareeBike_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(ShareeBikeApp.MerchantId, null /*UI language */, SharedBusinessLogic.Tests.LoginSessionCopriInfo.JavaministerHardwareNr1.AuthCookie).GetStations(),
|
||||
$"{Assembly.GetAssembly(GetType()).GetName().Name}-{GetType().Name}-{nameof(TestGetStationsAllCall_LoggedIn)}").Result;
|
||||
|
||||
Assert.That(stationsAll?.stations, Is.Not.Null);
|
||||
Assert.That(
|
||||
stationsAll.stations.Count,
|
||||
Is.GreaterThan(0),
|
||||
$"There must be at least one station.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using SharedBusinessLogic.Tests.Framework.Repository;
|
||||
using ShareeBike.Model.Connector;
|
||||
using ShareeBike.Repository;
|
||||
|
||||
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.Connector
|
||||
{
|
||||
/// <summary> Tests filter object. </summary>
|
||||
[TestFixture]
|
||||
public class TestFilter
|
||||
{
|
||||
/// <summary> Tests all stations. </summary>
|
||||
[Test]
|
||||
public void TestGetStationsAll()
|
||||
{
|
||||
var appContextInfo = new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2));
|
||||
var connector = new ConnectorCache(
|
||||
appContextInfo,
|
||||
null /*UI language */,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
server: new CopriCallsMemory001(merchantId: appContextInfo.MerchantId));
|
||||
|
||||
var filter = new FilteredConnector(new List<string> { FilterHelper.CARGOBIKE, FilterHelper.CITYBIKE }, connector);
|
||||
var stations = filter.Query.GetBikesAndStationsAsync().Result.Response;
|
||||
Assert.That(stations.StationsAll.Count(), Is.EqualTo(41)); // Count of stations was 9 before switching to data provider CopriCallsMemory(CopriCallsMemory.SampleSets.Set2, 1)
|
||||
|
||||
filter = new FilteredConnector(new List<string> { FilterHelper.CARGOBIKE }, connector);
|
||||
stations = filter.Query.GetBikesAndStationsAsync().Result.Response;
|
||||
Assert.That(stations.StationsAll.Count(), Is.EqualTo(27));
|
||||
|
||||
filter = new FilteredConnector(new List<string> { FilterHelper.CITYBIKE }, connector);
|
||||
stations = filter.Query.GetBikesAndStationsAsync().Result.Response;
|
||||
Assert.That(stations.StationsAll.Count(), Is.EqualTo(21));
|
||||
|
||||
filter = new FilteredConnector(new List<string> { "AGroupNamedNonsensDoesNotExist" }, connector);
|
||||
stations = filter.Query.GetBikesAndStationsAsync().Result.Response;
|
||||
Assert.That(stations.StationsAll.Count(), Is.EqualTo(0));
|
||||
|
||||
filter = new FilteredConnector(new List<string>(), connector);
|
||||
stations = filter.Query.GetBikesAndStationsAsync().Result.Response;
|
||||
Assert.That(stations.StationsAll.Count(), Is.EqualTo(41));
|
||||
|
||||
filter = new FilteredConnector(null, connector);
|
||||
stations = filter.Query.GetBikesAndStationsAsync().Result.Response;
|
||||
Assert.That(stations.StationsAll.Count(), Is.EqualTo(41), "Null means filter none.");
|
||||
}
|
||||
|
||||
/// <summary> Tests all stations. </summary>
|
||||
[Test]
|
||||
public void TestGetBikesAll()
|
||||
{
|
||||
var appContextInfo = new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2));
|
||||
var l_oConnector = new ConnectorCache(
|
||||
appContextInfo,
|
||||
null /*UI language */,
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
server: new CopriCallsMemory001(merchantId: appContextInfo.MerchantId));
|
||||
|
||||
var l_oFilter = new FilteredConnector(new List<string> { FilterHelper.CARGOBIKE, FilterHelper.CITYBIKE }, l_oConnector);
|
||||
var l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
|
||||
Assert.That(l_oBikes.Count(), Is.EqualTo(8)); // Count of stations was 12 CopriCallsMemory(CopriCallsMemory.SampleSets.Set2, 1)
|
||||
|
||||
l_oFilter = new FilteredConnector(new List<string> { FilterHelper.CARGOBIKE }, l_oConnector);
|
||||
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
|
||||
Assert.That(l_oBikes.Count(), Is.EqualTo(3)); // Was 11
|
||||
|
||||
l_oFilter = new FilteredConnector(new List<string> { FilterHelper.CITYBIKE }, l_oConnector);
|
||||
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
|
||||
Assert.That(l_oBikes.Count(), Is.EqualTo(5)); // Was 1
|
||||
|
||||
l_oFilter = new FilteredConnector(new List<string> { "AGroupNamedNonsensDoesNotExist" }, l_oConnector);
|
||||
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
|
||||
Assert.That(l_oBikes.Count(), Is.EqualTo(0));
|
||||
|
||||
l_oFilter = new FilteredConnector(new List<string>(), l_oConnector);
|
||||
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
|
||||
Assert.That(l_oBikes.Count(), Is.EqualTo(8), "List with zero element means filter all."); // Was 12
|
||||
|
||||
l_oFilter = new FilteredConnector(null, l_oConnector);
|
||||
l_oBikes = l_oFilter.Query.GetBikesAsync().Result.Response;
|
||||
Assert.That(l_oBikes.Count(), Is.EqualTo(8), "Null means filter none.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIsConnected()
|
||||
{
|
||||
var connector = Substitute.For<IConnector>();
|
||||
connector.IsConnected.Returns(true);
|
||||
Assert.That(new FilteredConnector(new List<string>(), connector).IsConnected, Is.True);
|
||||
var dummy = connector.Received().IsConnected;
|
||||
|
||||
connector = Substitute.For<IConnector>();
|
||||
connector.IsConnected.Returns(false);
|
||||
Assert.That(new FilteredConnector(new List<string>(), connector).IsConnected, Is.False);
|
||||
dummy = connector.Received().IsConnected;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ShareeBike.Model.User.Account;
|
||||
|
||||
namespace UITest.Fixtures.ObjectTests.User.Account
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestStore
|
||||
{
|
||||
[Test, Explicit("Did never ran, file load exception.")]
|
||||
public void TestLoadSaveRoundtrip()
|
||||
{
|
||||
var l_oStore = new Store("4711");
|
||||
l_oStore.Save(new ShareeBike.Model.User.Account.Account("a@b", "112", "3330", new List<string> { "Honkey", "Tonkey" }, 17));
|
||||
var l_oAccount = l_oStore.Load();
|
||||
Assert.AreEqual("a@b", l_oAccount.Mail);
|
||||
Assert.AreEqual("112", l_oAccount.Pwd);
|
||||
Assert.AreEqual("3330", l_oAccount.SessionCookie);
|
||||
Assert.AreEqual("Honkey,Tonkey", String.Join(",", l_oAccount.Group));
|
||||
Assert.AreEqual(17, l_oAccount.DebugLevel);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue