2022-08-30 15:42:25 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
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>
|
|
|
|
|
/// Verifies that unknown elemts in JSON to not lead to firing of exceptions.
|
|
|
|
|
/// </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),
|
|
|
|
|
"Dupliate elements are supposed to be ignored.");
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-17 14:17:58 +02:00
|
|
|
|
}
|