sharee.bike-App/TestShareeLib/Repository/Response/TestRentalDescription.cs

233 lines
6.4 KiB
C#
Raw Normal View History

2023-06-06 12:00:24 +02:00
using System.Linq;
2022-08-30 15:42:25 +02:00
using NUnit.Framework;
2022-06-17 14:17:58 +02:00
using TINK.Repository.Response;
namespace TestShareeLib.Repository.Response
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestRentalDescription
{
[Test]
public void TestDeserialize()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<RentalDescription>(
@"{
2022-06-17 14:17:58 +02:00
""id"": ""1"",
""tarif_elements"" : {
""6"": [
""Gratis Mietzeit"",
""30 Min / Tag""
],
""1"": [
""Mietgebühr"",
""2,00 / 1 Std""
],
""4"": [
""Max. Gebühr"",
""40.00 / Tag""
]
},
""name"": ""REN E-Bike"",
""rental_info"" : {
""9"" : [
""AGB"",
""Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt""
],
""8"" : [
""Tracking"",
""Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!""
]
}
}");
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.id,
Is.EqualTo("1"));
Assert.That(
tariffDescription.name,
Is.EqualTo("REN E-Bike"));
var tariffEntires = tariffDescription.tarif_elements.OrderBy(x => x.Key).Select(x => x.Value).ToList();
Assert.That(
tariffEntires.Count,
Is.EqualTo(3));
Assert.That(
tariffEntires[0][0],
Is.EqualTo("Mietgebühr"));
Assert.That(
tariffEntires[0][1],
Is.EqualTo("2,00 € / 1 Std"));
Assert.That(
tariffEntires[1][0],
Is.EqualTo("Max. Gebühr"));
Assert.That(
tariffEntires[1][1],
Is.EqualTo("40.00 € / Tag"));
Assert.That(
tariffEntires[2][0],
Is.EqualTo("Gratis Mietzeit"));
Assert.That(
tariffEntires[2][1],
Is.EqualTo("30 Min / Tag"));
var rentalInfo = tariffDescription.rental_info.OrderBy(x => x.Key).Select(x => x.Value).ToList();
Assert.That(
rentalInfo.Count,
Is.EqualTo(2));
Assert.That(
rentalInfo[0][0],
Is.EqualTo("Tracking"));
Assert.That(
rentalInfo[0][1],
Is.EqualTo("Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!"));
Assert.That(
rentalInfo[1][0],
Is.EqualTo("AGB"));
Assert.That(
rentalInfo[1][1],
Is.EqualTo("Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt"));
}
/// <summary>
/// Verifies that missing elements are initialized correctly.
/// </summary>
[Test]
public void TestDeserialize_Missing()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<RentalDescription>(
@"{
2022-06-17 14:17:58 +02:00
""id"" : ""5494"",
""name"" : ""Tester Basic""
}");
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.id,
Is.EqualTo("5494"));
Assert.That(
tariffDescription.name,
Is.EqualTo("Tester Basic"));
Assert.That(
tariffDescription.tarif_elements,
Is.Null);
Assert.That(
tariffDescription.rental_info,
Is.Null);
}
/// <summary>
2023-06-06 12:00:24 +02:00
/// Verifies that unknown elements in JSON to not lead to firing of exceptions.
2022-09-06 16:08:19 +02:00
/// </summary>
[Test]
public void TestDeserialize_NewElement()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<RentalDescription>(
@"{
2022-06-17 14:17:58 +02:00
""id"" : ""5494"",
""name"" : ""Tester Basic"",
""FancyNewElement"" : ""Yeah""
}");
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.id,
Is.EqualTo("5494"));
2022-06-17 14:17:58 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.name,
Is.EqualTo("Tester Basic"));
}
2022-06-17 14:17:58 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestDeserializeDuplicateKey()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<RentalDescription>(
@"{
2022-06-17 14:17:58 +02:00
""id"": ""1"",
""tarif_elements"" : {
""6"": [
""Gratis Mietzeit"",
""30 Min / Tag""
],
""6"": [
""Mietgebühr"",
""2,00 / 1 Std""
],
""4"": [
""Max. Gebühr"",
""40.00 / Tag""
]
},
""name"": ""REN E-Bike"",
""rental_info"" : {
""9"" : [
""AGB"",
""Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt""
],
""8"" : [
""Tracking"",
""Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!""
]
}
}");
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.tarif_elements.Count,
Is.EqualTo(2),
2023-06-06 12:00:24 +02:00
"Duplicate elements are supposed to be ignored.");
2022-09-06 16:08:19 +02:00
}
2023-06-06 12:00:24 +02:00
public static string RENTALDESCRIPTIONRESPONSE_A_V4_1_23_03 = @"{
""tarif_elements"": {
""1"": [
""Mietgebühr"",
""1,50 / 30 Min ""
],
""4"": [
""Max. Gebühr"",
""25,00 / Tag""
],
""6"": [
""Gratis Mietzeit"",
""30 Min / Tag""
]
},
""reserve_timerange"": ""30"",
""id"": ""100"",
""name"": ""Basis"",
""rental_info"": {
""1"": [
""Tracking"",
""Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!""
],
""2"": [
""AAFahrten"",
""Dieses E-Lastenrad darf nur an der Station zurück gegeben werden an der es ausgeliehen wurde!""
]
}
}";
[Test]
public void TestReserveTimeRange()
{
var response = JsonConvertRethrow.DeserializeObject<RentalDescription>(RENTALDESCRIPTIONRESPONSE_A_V4_1_23_03);
Assert.That(
response.reserve_timerange,
Is.EqualTo("30"));
}
2022-09-06 16:08:19 +02:00
}
2022-06-17 14:17:58 +02:00
}