mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-15 06:36:38 +01:00
86 lines
3.1 KiB
C#
86 lines
3.1 KiB
C#
using Newtonsoft.Json;
|
|
using NUnit.Framework;
|
|
using TINK.Repository.Exception;
|
|
using TINK.Repository.Response;
|
|
|
|
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Response
|
|
{
|
|
|
|
[TestFixture]
|
|
public class TestResponseHelper
|
|
{
|
|
[Test]
|
|
public void TestGetIsResponseOk_BikesOccupied_Ok()
|
|
{
|
|
var l_oResponse = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(@"{ ""response_state"" : ""OK"" }");
|
|
Assert.NotNull(l_oResponse.GetIsResponseOk(ResponseHelper.BIKES_OCCUPIED_ACTIONTEXT));
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetIsResponseOk_BikesOccupied_AuthcookieNotDefined()
|
|
{
|
|
var l_oResponseBase = JsonConvert.DeserializeObject<ResponseBase>($"{{ \"response_state\" : \"Failure 1003: authcookie not defined\" }}");
|
|
Assert.Throws<AuthcookieNotDefinedException>(() => l_oResponseBase.GetIsResponseOk("Get not succeed"));
|
|
}
|
|
|
|
|
|
[Test]
|
|
public void TestGetIsResponseOk_NoBikes()
|
|
{
|
|
var l_oResponse = JsonConvert.DeserializeObject<ReservationBookingResponse>(
|
|
@"{ ""response_state"" : ""OK"", " +
|
|
@"""authcookie"" : ""KeksoiF2kahH"" }");
|
|
|
|
Assert.That(() => l_oResponse.GetIsReserveResponseOk("8"), Throws.Exception.TypeOf<System.Exception>());
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetIsResposeOk_Booking_Declined()
|
|
{
|
|
var l_oResponse = JsonConvert.DeserializeObject<ReservationBookingResponse>(@"{ ""response_state"" : ""OK: booking_request declined. max count of 8 occupied bikes has been reached"", ""authcookie"" : ""KeksoiF2kahH"" }");
|
|
Assert.AreEqual(
|
|
8,
|
|
Assert.Throws<BookingDeclinedException>(() => l_oResponse.GetIsReserveResponseOk("8")).MaxBikesCount);
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetIsResposeOk_Logout_AutcookieUnknown()
|
|
{
|
|
var l_oResponse = JsonConvert.DeserializeObject<AuthorizationoutResponse>($"{{ \"response_state\" : \"Failure 1004: authcookie not defined\"}}");
|
|
|
|
Assert.Throws<AuthcookieNotDefinedException>(() => l_oResponse.GetIsResponseOk());
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetIsReturnBikeResponseOk_Error()
|
|
{
|
|
var l_oResponse = JsonConvert.DeserializeObject<DoReturnResponse>(
|
|
@"{ ""response_state"" : ""Failure 1234"", " +
|
|
@"""authcookie"" : ""KeksoiF2kahH"" }");
|
|
|
|
Assert.That(
|
|
() => l_oResponse.GetIsReturnBikeResponseOk("8"),
|
|
Throws.Exception.TypeOf<InvalidResponseException<ResponseBase>>());
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetIsReturnBikeResponseOk_ErrorNotAtStation()
|
|
{
|
|
var l_oResponse = JsonConvert.DeserializeObject<DoReturnResponse>(
|
|
@"{ ""response_state"" : ""Failure 2178: bike 1545 out of GEO fencing. 15986 meter distance to next station 66. OK: bike 1545 locked confirmed"", " +
|
|
@"""authcookie"" : ""KeksoiF2kahH"" }");
|
|
|
|
Assert.That(() => l_oResponse.GetIsReturnBikeResponseOk("8"), Throws.Exception.TypeOf<NotAtStationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void TestGetIsReturnBikeResponseOk_ErrorNoGPSData()
|
|
{
|
|
var l_oResponse = JsonConvert.DeserializeObject<DoReturnResponse>(
|
|
@"{ ""response_state"" : ""Failure 2245: No GPS data, state change forbidden."", " +
|
|
@"""authcookie"" : ""KeksoiF2kahH"" }");
|
|
|
|
Assert.That(() => l_oResponse.GetIsReturnBikeResponseOk("8"), Throws.Exception.TypeOf<NoGPSDataException>());
|
|
}
|
|
}
|
|
}
|