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

98 lines
2.1 KiB
C#
Raw Normal View History

2023-06-06 12:00:24 +02:00
using NUnit.Framework;
2021-05-13 20:09:46 +02:00
using TINK.Repository.Response;
namespace TestShareeLib.Repository.Response
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestTariffDescription
{
[Test]
public void TestDeserialize()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
@"{
2021-05-13 20:09:46 +02:00
""eur_per_hour"" : ""10.00"",
""abo_eur_per_month"" : ""920.00"",
""free_hours"" : ""3.00"",
""number"" : ""5494"",
""name"" : ""Tester Basic""
}");
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.eur_per_hour,
Is.EqualTo("10.00"));
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.abo_eur_per_month,
Is.EqualTo("920.00"));
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.free_hours,
Is.EqualTo("3.00"));
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.number,
Is.EqualTo("5494"));
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.name,
Is.EqualTo("Tester Basic"));
}
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Verifies that missing elements are initialized correctly.
/// </summary>
[Test]
public void TestDeserialize_Missing()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
@"{
2021-05-13 20:09:46 +02:00
""number"" : ""5494"",
""name"" : ""Tester Basic""
}");
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.eur_per_hour,
Is.Null);
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.abo_eur_per_month,
Is.Null);
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.free_hours,
Is.Null);
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.number,
Is.EqualTo("5494"));
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.name,
Is.EqualTo("Tester Basic"));
}
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
/// <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<TariffDescription>(
@"{
2021-05-13 20:09:46 +02:00
""number"" : ""5494"",
""name"" : ""Tester Basic"",
""FancyNewElement"" : ""Yeah""
}");
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.number,
Is.EqualTo("5494"));
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
tariffDescription.name,
Is.EqualTo("Tester Basic"));
}
}
2021-05-13 20:09:46 +02:00
}