sharee.bike-App/TestShareeLib/Repository/Request/TestRequestBuilderLoggedIn.cs

162 lines
5.7 KiB
C#
Raw Normal View History

2021-07-12 21:31:46 +02:00
using NUnit.Framework;
using System;
2021-08-01 17:24:15 +02:00
using System.Collections.Generic;
2021-07-12 21:31:46 +02:00
using TINK.Repository.Exception;
using TINK.Repository.Request;
2021-08-01 17:24:15 +02:00
namespace TestShareeLib.Repository.Request
2021-07-12 21:31:46 +02:00
{
[TestFixture]
public class TestRequestBuilderLoggedIn
{
[Test]
public void TestDoAuthorize()
{
Assert.Throws <CallNotRequiredException>(() =>new RequestBuilderLoggedIn("123", "456").DoAuthorization("abc@cde", "+?", "789"));
}
[Test]
public void TestDoAuthout()
{
Assert.AreEqual(
"request=authout&authcookie=456123",
new RequestBuilderLoggedIn ("123", "456").DoAuthout());
}
[Test]
public void TestGetBikesAvailable()
{
Assert.AreEqual(
"request=bikes_available&system=all&authcookie=456123",
new RequestBuilderLoggedIn("123", "456").GetBikesAvailable());
}
[Test]
public void TestGetBikesAvailable_Null()
{
Assert.Throws<ArgumentException>(() =>
new RequestBuilderLoggedIn("123", null).GetBikesAvailable());
Assert.Throws<ArgumentException>(() =>
new RequestBuilderLoggedIn("123", string.Empty).GetBikesAvailable());
}
[Test]
public void TestGetBikesOccupied()
{
Assert.AreEqual(
"request=user_bikes_occupied&system=all&genkey=1&authcookie=456123",
new RequestBuilderLoggedIn("123", "456").GetBikesOccupied());
}
[Test]
public void TestGetBikesOccupied_Null()
{
Assert.Throws<ArgumentException>(() =>
new RequestBuilderLoggedIn("123", null).GetBikesOccupied());
Assert.Throws<ArgumentException>(() =>
new RequestBuilderLoggedIn("123", "").GetBikesOccupied());
}
[Test]
public void TestGetStations()
{
Assert.AreEqual(
"request=stations_available&authcookie=456123",
new RequestBuilderLoggedIn("123", "456").GetStations());
}
[Test]
public void TestGetStations_Null()
{
Assert.Throws<ArgumentException>(() =>
new RequestBuilderLoggedIn("123", string.Empty).GetStations());
Assert.Throws<ArgumentException>(() =>
new RequestBuilderLoggedIn("123", null).GetStations());
}
[Test]
public void TestDoReserve()
{
Assert.AreEqual(
"request=booking_request&bike=42&authcookie=456123",
new RequestBuilderLoggedIn("123", "456").DoReserve("42"));
}
[Test]
public void TestDoCancelReservation()
{
Assert.AreEqual(
"request=booking_cancel&bike=42&authcookie=456123",
new RequestBuilderLoggedIn("123", "456").DoCancelReservation("42"));
}
[Test]
public void TestDoBook()
{
Assert.AreEqual(
"request=booking_update&bike=42&authcookie=456123&Ilockit_GUID=0000f00d-1212-efde-1523-785fef13d123&state=occupied&lock_state=unlocked&voltage=33.21",
new RequestBuilderLoggedIn("123", "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"),33.21));
}
[Test]
public void TestDoBookNoBatery()
{
Assert.AreEqual(
"request=booking_update&bike=42&authcookie=456123&Ilockit_GUID=0000f00d-1212-efde-1523-785fef13d123&state=occupied&lock_state=unlocked",
new RequestBuilderLoggedIn("123", "456").DoBook("42", new Guid("0000f00d-1212-efde-1523-785fef13d123"), double.NaN));
}
2021-08-01 17:24:15 +02:00
2022-04-25 22:15:15 +02:00
[Test]
public void TestBookAndStartOpening()
{
Assert.That(
new RequestBuilderLoggedIn("123", "456").BookAndStartOpening("42"),
Is.EqualTo("request=booking_request&bike=42&authcookie=456123&state=occupied&lock_state=unlocking"));
}
[Test]
public void TestReturnAndStartClosing()
{
Assert.That(
new RequestBuilderLoggedIn("123", "456").ReturnAndStartClosing("42", null),
Is.EqualTo("request=booking_update&bike=42&authcookie=456123&state=available&lock_state=locking"));
}
2021-08-01 17:24:15 +02:00
[Test]
public void TestDoSubmitMiniSurvey()
{
Assert.That(
new RequestBuilderLoggedIn("Merchy", "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", "Keksi").DoSubmitMiniSurvey(null),
Is.EqualTo("request=user_minianswer&authcookie=KeksiMerchy"));
}
[Test]
public void TestDoSubmitMiniSurveyEmptyDict()
{
Assert.That(
new RequestBuilderLoggedIn("Merchy", "Keksi").DoSubmitMiniSurvey(new Dictionary<string, string>()),
Is.EqualTo("request=user_minianswer&authcookie=KeksiMerchy"));
}
[Test]
public void TestDoSubmitMiniSurveyFilterInvalidEntries()
{
Assert.That(
new RequestBuilderLoggedIn("Merchy", "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"));
}
2021-07-12 21:31:46 +02:00
}
}