mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
431 lines
16 KiB
C#
431 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using TINK.Model.Connector;
|
|
using TINK.Model.Device;
|
|
using TINK.Repository.Exception;
|
|
using TINK.Repository.Request;
|
|
|
|
namespace TestShareeLib.Repository.Request
|
|
{
|
|
[TestFixture]
|
|
public class TestRequestBuilderLoggedIn
|
|
{
|
|
|
|
[Test]
|
|
public void TestDoAuthorize()
|
|
{
|
|
Assert.Throws<CallNotRequiredException>(() => new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoAuthorization("abc@cde", "+?", "789"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestDoAuthout()
|
|
{
|
|
Assert.AreEqual(
|
|
"request=authout&authcookie=K%C3%A4ksM%C3%B6rchantId&lang=%C3%B6e",
|
|
new RequestBuilderLoggedIn("MörchantId", "öe" /* fictive UI language */, "Käks").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<ArgumentException>(() =>
|
|
new RequestBuilderLoggedIn("123", null /*UI language */, null).GetBikesAvailable());
|
|
|
|
Assert.Throws<ArgumentException>(() =>
|
|
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<ArgumentException>(() =>
|
|
new RequestBuilderLoggedIn("123", null /*UI language */, null).GetBikesOccupied());
|
|
|
|
Assert.Throws<ArgumentException>(() =>
|
|
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 TestGetStationsSmartDeviceManufacturer()
|
|
{
|
|
var sd = Substitute.For<ISmartDevice>();
|
|
sd.Manufacturer.Returns("Färphone");
|
|
|
|
Assert.AreEqual(
|
|
"request=stations_available&authcookie=456123&user_device_manufacturer=F%C3%A4rphone",
|
|
new RequestBuilderLoggedIn("123", null /*UI language */, "456" , sd).GetStations());
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetStations_Null()
|
|
{
|
|
Assert.Throws<ArgumentException>(() =>
|
|
new RequestBuilderLoggedIn("123", null /*UI language */, string.Empty).GetStations());
|
|
|
|
Assert.Throws<ArgumentException>(() =>
|
|
new RequestBuilderLoggedIn("123", null /*UI language */, null).GetStations());
|
|
}
|
|
|
|
[Test]
|
|
public void TestDoReserve()
|
|
{
|
|
Assert.AreEqual(
|
|
"request=booking_request&bike=M%C3%BChleNr42&authcookie=456123",
|
|
new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoReserve("MühleNr42"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestDoReserveSmartDeviceManufacturer()
|
|
{
|
|
var sd = Substitute.For<ISmartDevice>();
|
|
sd.Manufacturer.Returns("Färphone");
|
|
|
|
Assert.That(
|
|
new RequestBuilderLoggedIn("123", null /*UI language */, "456", sd).DoReserve("MühleNr42"),
|
|
Is.EqualTo("request=booking_request&bike=M%C3%BChleNr42&authcookie=456123&user_device_manufacturer=F%C3%A4rphone"));
|
|
}
|
|
|
|
[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=unlocking&voltage=33.21",
|
|
new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"), 33.21, LockingAction.Open));
|
|
}
|
|
|
|
[Test]
|
|
public void TestDoBookNoBatery()
|
|
{
|
|
Assert.AreEqual(
|
|
"request=booking_update&bike=42&authcookie=456123&Ilockit_GUID=0000f00d-1212-efde-1523-785fef13d123&state=occupied",
|
|
new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"), double.NaN));
|
|
}
|
|
|
|
[Test]
|
|
public void TestDoBookActionNone()
|
|
{
|
|
Assert.AreEqual(
|
|
"request=booking_update&bike=42&authcookie=456123&Ilockit_GUID=0000f00d-1212-efde-1523-785fef13d123&state=occupied",
|
|
new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"), double.NaN));
|
|
}
|
|
|
|
/// <summary> Hypothetical scenario.</summary>
|
|
[Test]
|
|
public void TestDoBookActionClose()
|
|
{
|
|
Assert.AreEqual(
|
|
"request=booking_update&bike=42&authcookie=456123&Ilockit_GUID=0000f00d-1212-efde-1523-785fef13d123&state=occupied&lock_state=locking",
|
|
new RequestBuilderLoggedIn("123", null /*UI language */, "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"), double.NaN, LockingAction.Close));
|
|
}
|
|
|
|
[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 TestBookAndStartOpeningSmartDeviceManufacturer()
|
|
{
|
|
var sd = Substitute.For<ISmartDevice>();
|
|
sd.Manufacturer.Returns("Färphone");
|
|
|
|
Assert.That(
|
|
new RequestBuilderLoggedIn("123", null /*UI language */, "456", sd).BookAvailableAndStartOpening("42"),
|
|
Is.EqualTo("request=booking_request&bike=42&authcookie=456123&state=occupied&lock_state=unlocking&user_device_manufacturer=F%C3%A4rphone"));
|
|
}
|
|
|
|
[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"),
|
|
Is.EqualTo("request=booking_update&bike=42&authcookie=456123&state=available&lock_state=locking"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestReturnAndStartClosingSmartDeviceManufacturer()
|
|
{
|
|
var sd = Substitute.For<ISmartDevice>();
|
|
sd.Manufacturer.Returns("Färphone");
|
|
|
|
Assert.That(
|
|
new RequestBuilderLoggedIn("123", null /*UI language */, "456", sd).ReturnAndStartClosing("42"),
|
|
Is.EqualTo("request=booking_update&bike=42&authcookie=456123&state=available&lock_state=locking&user_device_manufacturer=F%C3%A4rphone"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestDoSubmitMiniSurvey()
|
|
{
|
|
Assert.That(
|
|
new RequestBuilderLoggedIn("Merchy", null /*UI language */, "Keksi").DoSubmitMiniSurvey(new Dictionary<string, string> { { "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<string, string>()),
|
|
Is.EqualTo("request=user_minianswer&authcookie=KeksiMerchy"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestDoSubmitMiniSurveyFilterInvalidEntries()
|
|
{
|
|
Assert.That(
|
|
new RequestBuilderLoggedIn("Merchy", null /*UI language */, "Keksi").DoSubmitMiniSurvey(new Dictionary<string, string> { { "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 TestUpdateLockingStateGeolocationIsNull()
|
|
{
|
|
var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie");
|
|
Assert.That(
|
|
builder.UpdateLockingState("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 TestUpdateLockingStateGeolocationIsNullBatteryPercentageIsNAN()
|
|
{
|
|
var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie");
|
|
Assert.That(
|
|
builder.UpdateLockingState("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 TestUpdateLockingStateGeolocation_AccuraycyNull()
|
|
{
|
|
var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie");
|
|
Assert.That(
|
|
builder.UpdateLockingState("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 TestUpdateLockingStateGeolocation_AccuraycyNullBatteryPercentageIsNAN()
|
|
{
|
|
var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie");
|
|
Assert.That(
|
|
builder.UpdateLockingState("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 TestUpdateLockingStateGeolocation()
|
|
{
|
|
var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie");
|
|
Assert.That(
|
|
builder.UpdateLockingState("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 TestUpdateLockingStateVersionsInfo()
|
|
{
|
|
var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie");
|
|
Assert.That(
|
|
WebUtility.UrlDecode(builder.UpdateLockingState("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 12;FW 13;Lock 14&authcookie=MySessionCookieMyMeranctIt"));
|
|
}
|
|
|
|
|
|
[Test]
|
|
public void TestDoReturn()
|
|
{
|
|
var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie");
|
|
Assert.That(
|
|
builder.DoReturn("12", null /* Geolocation */),
|
|
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()),
|
|
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()),
|
|
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 TestDoReturnSmartDeviceManufacturer()
|
|
{
|
|
var sd = Substitute.For<ISmartDevice>();
|
|
sd.Manufacturer.Returns("Färphone");
|
|
var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie", sd);
|
|
Assert.That(
|
|
builder.DoReturn(
|
|
"12",
|
|
null), // Geolocation
|
|
Is.EqualTo("request=booking_update&bike=12&authcookie=MySessionCookieMyMeranctIt&state=available&lock_state=locked&user_device_manufacturer=F%C3%A4rphone"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestDoReturnSmartDeviceModel()
|
|
{
|
|
var sd = Substitute.For<ISmartDevice>();
|
|
sd.Model.Returns("Fön");
|
|
var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie", sd);
|
|
Assert.That(
|
|
builder.DoReturn(
|
|
"12",
|
|
null), // Geolocation
|
|
Is.EqualTo("request=booking_update&bike=12&authcookie=MySessionCookieMyMeranctIt&state=available&lock_state=locked&user_device_model=F%C3%B6n"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestDoReturnSmartDeviceVersion()
|
|
{
|
|
var sd = Substitute.For<ISmartDevice>();
|
|
sd.VersionText.Returns("ß1");
|
|
var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie", sd);
|
|
Assert.That(
|
|
builder.DoReturn(
|
|
"12",
|
|
null), // Geolocation
|
|
Is.EqualTo("request=booking_update&bike=12&authcookie=MySessionCookieMyMeranctIt&state=available&lock_state=locked&user_device_version=%C3%9F1"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestDoReturnSmartDeviceIdentifier()
|
|
{
|
|
var sd = Substitute.For<ISmartDevice>();
|
|
sd.Identifier.Returns("ß9");
|
|
var builder = new RequestBuilderLoggedIn("MyMeranctIt", null /*UI language */, "MySessionCookie", sd);
|
|
Assert.That(
|
|
builder.DoReturn(
|
|
"12",
|
|
null), // Geolocation
|
|
Is.EqualTo("request=booking_update&bike=12&authcookie=MySessionCookieMyMeranctIt&state=available&lock_state=locked&user_device_id=%C3%9F9"));
|
|
}
|
|
|
|
[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%C3%BChle&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"));
|
|
}
|
|
}
|
|
}
|