sharee.bike-App/TestShareeLib/Repository/Response/TestRentalDescription.cs
2023-06-06 12:05:48 +02:00

232 lines
6.4 KiB
C#

using System.Linq;
using NUnit.Framework;
using TINK.Repository.Response;
namespace TestShareeLib.Repository.Response
{
[TestFixture]
public class TestRentalDescription
{
[Test]
public void TestDeserialize()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<RentalDescription>(
@"{
""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!""
]
}
}");
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>(
@"{
""id"" : ""5494"",
""name"" : ""Tester Basic""
}");
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>
/// Verifies that unknown elements in JSON to not lead to firing of exceptions.
/// </summary>
[Test]
public void TestDeserialize_NewElement()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<RentalDescription>(
@"{
""id"" : ""5494"",
""name"" : ""Tester Basic"",
""FancyNewElement"" : ""Yeah""
}");
Assert.That(
tariffDescription.id,
Is.EqualTo("5494"));
Assert.That(
tariffDescription.name,
Is.EqualTo("Tester Basic"));
}
[Test]
public void TestDeserializeDuplicateKey()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<RentalDescription>(
@"{
""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!""
]
}
}");
Assert.That(
tariffDescription.tarif_elements.Count,
Is.EqualTo(2),
"Duplicate elements are supposed to be ignored.");
}
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"));
}
}
}