sharee.bike-App/TestShareeLib/Repository/Response/TestRentalDescription.cs
Anja Müller-Meißner 0468955d49 Version 3.0.338
2022-09-08 09:55:14 +02:00

192 lines
5.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 elemts 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),
"Dupliate elements are supposed to be ignored.");
}
}
}