sharee.bike-App/TestShareeLib/Repository/TestResponseHelper.cs

87 lines
3.1 KiB
C#
Raw Normal View History

2021-07-12 21:31:46 +02:00
using Newtonsoft.Json;
using NUnit.Framework;
using TINK.Repository.Exception;
using TINK.Repository.Response;
namespace TestTINKLib.Fixtures.ObjectTests.Connector.Response
{
2022-09-06 16:08:19 +02:00
[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));
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[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"));
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestGetIsResponseOk_NoBikes()
{
var l_oResponse = JsonConvert.DeserializeObject<ReservationBookingResponse>(
@"{ ""response_state"" : ""OK"", " +
@"""authcookie"" : ""KeksoiF2kahH"" }");
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(() => l_oResponse.GetIsReserveResponseOk("8"), Throws.Exception.TypeOf<System.Exception>());
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[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);
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestGetIsResposeOk_Logout_AutcookieUnknown()
{
var l_oResponse = JsonConvert.DeserializeObject<AuthorizationoutResponse>($"{{ \"response_state\" : \"Failure 1004: authcookie not defined\"}}");
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.Throws<AuthcookieNotDefinedException>(() => l_oResponse.GetIsResponseOk());
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestGetIsReturnBikeResponseOk_Error()
{
var l_oResponse = JsonConvert.DeserializeObject<DoReturnResponse>(
@"{ ""response_state"" : ""Failure 1234"", " +
@"""authcookie"" : ""KeksoiF2kahH"" }");
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
() => l_oResponse.GetIsReturnBikeResponseOk("8"),
Throws.Exception.TypeOf<InvalidResponseException<ResponseBase>>());
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[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"" }");
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(() => l_oResponse.GetIsReturnBikeResponseOk("8"), Throws.Exception.TypeOf<NotAtStationException>());
}
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestGetIsReturnBikeResponseOk_ErrorNoGPSData()
{
var l_oResponse = JsonConvert.DeserializeObject<DoReturnResponse>(
@"{ ""response_state"" : ""Failure 2245: No GPS data, state change forbidden."", " +
@"""authcookie"" : ""KeksoiF2kahH"" }");
2021-07-12 21:31:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(() => l_oResponse.GetIsReturnBikeResponseOk("8"), Throws.Exception.TypeOf<NoGPSDataException>());
}
}
2021-07-12 21:31:46 +02:00
}