using System; using System.Collections.Generic; using NUnit.Framework; using TINK.Repository.Exception; using TINK.Repository.Request; namespace TestShareeLib.Repository.Request { [TestFixture] public class TestRequestBuilderLoggedIn { [Test] public void TestDoAuthorize() { Assert.Throws(() => new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoAuthorization("abc@cde", "+?", "789")); } [Test] public void TestDoAuthout() { Assert.AreEqual( "request=authout&authcookie=456123", new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoAuthout()); } [Test] public void TestDoAuthoutLangDe() => Assert.That( new RequestBuilderLoggedIn("123", "de", "456").DoAuthout(), Is.EqualTo("request=authout&authcookie=456123&lang=de")); [Test] public void TestGetBikesAvailable() { Assert.AreEqual( "request=bikes_available&system=all&authcookie=456123", new RequestBuilderLoggedIn("123", null /*UI language */, "456").GetBikesAvailable()); } [Test] public void TestGetBikesAvailable_Null() { Assert.Throws(() => new RequestBuilderLoggedIn("123", null /*UI language */, null).GetBikesAvailable()); Assert.Throws(() => new RequestBuilderLoggedIn("123", null /*UI language */, string.Empty).GetBikesAvailable()); } [Test] public void TestGetBikesOccupied() { Assert.AreEqual( "request=user_bikes_occupied&system=all&genkey=1&authcookie=456123", new RequestBuilderLoggedIn("123", null /*UI language */, "456").GetBikesOccupied()); } [Test] public void TestGetBikesOccupied_Null() { Assert.Throws(() => new RequestBuilderLoggedIn("123", null /*UI language */, null).GetBikesOccupied()); Assert.Throws(() => new RequestBuilderLoggedIn("123", null /*UI language */, "").GetBikesOccupied()); } [Test] public void TestGetStations() { Assert.AreEqual( "request=stations_available&authcookie=456123", new RequestBuilderLoggedIn("123", null /*UI language */, "456").GetStations()); } [Test] public void TestGetStations_Null() { Assert.Throws(() => new RequestBuilderLoggedIn("123", null /*UI language */, string.Empty).GetStations()); Assert.Throws(() => new RequestBuilderLoggedIn("123", null /*UI language */, null).GetStations()); } [Test] public void TestDoReserve() { Assert.AreEqual( "request=booking_request&bike=42&authcookie=456123", new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoReserve("42")); } [Test] public void TestDoCancelReservation() { Assert.AreEqual( "request=booking_cancel&bike=42&authcookie=456123", new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoCancelReservation("42")); } [Test] public void TestCalculateAuthParameters() => Assert.That( new RequestBuilderLoggedIn("123", "zh", "456").CalculateAuthParameters("42"), Is.EqualTo("request=booking_update&bike=42&authcookie=456123&genkey=1&lang=zh")); [Test] public void TestStartReturningBike() => Assert.That( new RequestBuilderLoggedIn("123", "zh", "456").StartReturningBike("42"), Is.EqualTo("request=booking_update&bike=42&lock_state=locking&authcookie=456123&lang=zh")); [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", null /*UI language */, "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", null /*UI language */, "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"), double.NaN)); } [Test] public void TestBookAndStartOpening() => Assert.That( new RequestBuilderLoggedIn("123", null /*UI language */, "456").BookAvailableAndStartOpening("42"), Is.EqualTo("request=booking_request&bike=42&authcookie=456123&state=occupied&lock_state=unlocking")); [Test] public void TestBookReservedAndStartOpening() => Assert.That( new RequestBuilderLoggedIn("123", null /*UI language */, "456").BookReservedAndStartOpening("42"), Is.EqualTo("request=booking_update&bike=42&authcookie=456123&state=occupied&lock_state=unlocking")); [Test] public void TestReturnAndStartClosing() { Assert.That( new RequestBuilderLoggedIn("123", null /*UI language */, "456").ReturnAndStartClosing("42", null), Is.EqualTo("request=booking_update&bike=42&authcookie=456123&state=available&lock_state=locking")); } [Test] public void TestDoSubmitMiniSurvey() { Assert.That( new RequestBuilderLoggedIn("Merchy", null /*UI language */, "Keksi").DoSubmitMiniSurvey(new Dictionary { { "q1", "opt5" }, { "q2", "opt4" }, { "q3", "der Freitext" } }), Is.EqualTo("request=user_minianswer&q1=opt5&q2=opt4&q3=der+Freitext&authcookie=KeksiMerchy")); } [Test] public void TestDoSubmitMiniSurveyNull() { Assert.That( new RequestBuilderLoggedIn("Merchy", null /*UI language */, "Keksi").DoSubmitMiniSurvey(null), Is.EqualTo("request=user_minianswer&authcookie=KeksiMerchy")); } [Test] public void TestDoSubmitMiniSurveyEmptyDict() { Assert.That( new RequestBuilderLoggedIn("Merchy", null /*UI language */, "Keksi").DoSubmitMiniSurvey(new Dictionary()), Is.EqualTo("request=user_minianswer&authcookie=KeksiMerchy")); } [Test] public void TestDoSubmitMiniSurveyFilterInvalidEntries() { Assert.That( new RequestBuilderLoggedIn("Merchy", null /*UI language */, "Keksi").DoSubmitMiniSurvey(new Dictionary { { "q1", "opt5" }, { "", "opt99" }, { "q99", "" }, { "q2", "opt4" }, { "q3", "der Freitext" } }), Is.EqualTo("request=user_minianswer&q1=opt5&q2=opt4&q3=der+Freitext&authcookie=KeksiMerchy")); } [Test] public void TestUpateLockingStateGeolocationIsNull() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.UpateLockingState("12", lock_state.locked, null /* geolocaion */, 15.03, null /* version info */), Is.EqualTo("request=booking_update&bike=12&lock_state=locked&voltage=15.03&authcookie=MySessionCookieMyMeranctIt")); } [Test] public void TestUpateLockingStateGeolocationIsNullBatteryPercentageIsNAN() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.UpateLockingState("12", lock_state.locked, null /* geolocaion */, double.NaN, null /* version info */), Is.EqualTo("request=booking_update&bike=12&lock_state=locked&authcookie=MySessionCookieMyMeranctIt")); } [Test] public void TestUpateLockingStateGeolocation_AccuraycyNull() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.UpateLockingState("12", lock_state.locked, new LocationDto.Builder { Latitude = 21, Longitude = 17, Age = new TimeSpan(0, 0, 0, 0, 70) }.Build(), 12, null /* version info */), Is.EqualTo("request=booking_update&bike=12&gps=21,17&gps_age=0.07&lock_state=locked&voltage=12&authcookie=MySessionCookieMyMeranctIt")); } [Test] public void TestUpateLockingStateGeolocation_AccuraycyNullBatteryPercentageIsNAN() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.UpateLockingState("12", lock_state.locked, new LocationDto.Builder { Latitude = 21, Longitude = 17, Age = new TimeSpan(0, 0, 0, 0, 70) }.Build(), double.NaN, null /* version info */), Is.EqualTo("request=booking_update&bike=12&gps=21,17&gps_age=0.07&lock_state=locked&authcookie=MySessionCookieMyMeranctIt")); } [Test] public void TestUpateLockingStateGeolocation() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.UpateLockingState("12", lock_state.locked, new LocationDto.Builder { Latitude = 21, Longitude = 17, Accuracy = 5.7, Age = new TimeSpan(0, 0, 0, 0, 70) }.Build(), 98, null /* version info */), Is.EqualTo("request=booking_update&bike=12&gps=21,17&gps_accuracy=5.7&gps_age=0.07&lock_state=locked&voltage=98&authcookie=MySessionCookieMyMeranctIt")); } [Test] public void TestUpateLockingStateVersionsInfo() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.UpateLockingState("12", lock_state.locked, null /* geolocaion */, 15.03, new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.VersionInfo.Builder { FirmwareVersion=13, HardwareVersion=12, LockVersion=14}.Build()), Is.EqualTo("request=booking_update&bike=12&lock_state=locked&voltage=15.03&firmware=HW%2012;FW%2013;Lock%2014&authcookie=MySessionCookieMyMeranctIt")); } [Test] public void TestDoReturnGeolocationIsNull() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.DoReturn("12", null, null), Is.EqualTo("request=booking_update&bike=12&authcookie=MySessionCookieMyMeranctIt&state=available&lock_state=locked")); } [Test] public void TestDoReturnGeolocation_AccuraycyNull() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.DoReturn( "12", new LocationDto.Builder { Latitude = 21, Longitude = 17, Age = new TimeSpan(0, 0, 0, 0, 70) }.Build(), null), Is.EqualTo("request=booking_update&bike=12&authcookie=MySessionCookieMyMeranctIt&state=available&gps=21,17&gps_age=0.07&lock_state=locked")); } [Test] public void TestDoReturnGeolocation() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.DoReturn( "12", new LocationDto.Builder { Latitude = 21, Longitude = 17, Accuracy = 5.7, Age = new TimeSpan(0, 0, 0, 0, 70) }.Build(), null), Is.EqualTo("request=booking_update&bike=12&authcookie=MySessionCookieMyMeranctIt&state=available&gps=21,17&gps_accuracy=5.7&gps_age=0.07&lock_state=locked")); } [Test] public void TestDoSubmitFeedback_Ok() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.DoSubmitFeedback("Radl22"), Is.EqualTo("request=user_feedback&bike=Radl22&authcookie=MySessionCookieMyMeranctIt")); } [Test] public void TestDoSubmitFeedback_BikeBroken() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.DoSubmitFeedback("Cycle33", null, isBikeBroken: true), Is.EqualTo("request=user_feedback&bike=Cycle33&bike_broken=1&authcookie=MySessionCookieMyMeranctIt")); } [Test] public void TestDoSubmitFeedback_Message() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.DoSubmitFeedback("Mühle", null, "Uno due tre"), Is.EqualTo("request=user_feedback&bike=Mühle&message=Uno+due+tre&authcookie=MySessionCookieMyMeranctIt")); } [Test] public void TestDoSubmitFeedback_ErrorMessage() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.DoSubmitFeedback("bike12", null, "Uno due tre", true), Is.EqualTo("request=user_feedback&bike=bike12&bike_broken=1&message=Uno+due+tre&authcookie=MySessionCookieMyMeranctIt")); } [Test] public void TestDoSubmitFeedback_ChargeLevel() { var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie"); Assert.That( builder.DoSubmitFeedback("bike12", 3, "Uno due tre", true), Is.EqualTo("request=user_feedback&bike=bike12&charge_current_bars=3&bike_broken=1&message=Uno+due+tre&authcookie=MySessionCookieMyMeranctIt")); } } }