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 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 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")); } /// Log out functionality is only for test purposes. [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); } } /// /// Log out functionality is only for test purposes. /// [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( () => 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); } } /// /// 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. /// [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); } } /// /// From COPRI version v4.1 switched from ShareeBike devel CopriServerUriList.ShareeBike_DEVEL and CopriServerUriList.ShareeBike_LIVE to CopriServerUriList.SHAREE_DEVEL. /// [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"); } /// /// From COPRI version v4.1 switched from ShareeBike devel CopriServerUriList.ShareeBike_DEVEL and CopriServerUriList.ShareeBike_LIVE to CopriServerUriList.SHAREE_DEVEL. /// [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"); } /// /// Attention: Behaves different if called with a period smaller 15minutes because bike will already be reserved. /// [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); } } /// /// Attention: Behaves different if called with a period smaller 15minutes because bike will already be reserved. /// [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); } } /// Tests the member. /// Timecode is no more verified since COPRI 4.1. [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."); } /// /// 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. /// [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" } /// /// Tests the member. /// /// /// From COPRI version v4.1 switched from ShareeBike devel CopriServerUriList.ShareeBike_DEVEL and CopriServerUriList.ShareeBike_LIVE to CopriServerUriList.SHAREE_DEVEL. /// [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)); } /// /// Tests the member. /// /// /// From COPRI version v4.1 switched from ShareeBike devel CopriServerUriList.ShareeBike_DEVEL and CopriServerUriList.ShareeBike_LIVE to CopriServerUriList.SHAREE_DEVEL. /// [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."); } } }