mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-22 04:46:30 +02:00
Initial version
This commit is contained in:
parent
41b618cb27
commit
e4fb48f6ab
24 changed files with 4387 additions and 0 deletions
|
@ -0,0 +1,66 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.Repository.Response;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Bike
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestBikesAvailableResponse
|
||||
{
|
||||
[Test]
|
||||
public void TestDeserializeStationEmpty()
|
||||
{
|
||||
// Response for bike 231 is a real world answer.
|
||||
var l_oBikes = JsonConvert.DeserializeObject<BikesAvailableResponse>(@"
|
||||
{
|
||||
""apiserver"" : ""https://app.tink-konstanz.de"",
|
||||
""response"" : ""bikes_available"",
|
||||
""bikes"" : {
|
||||
""231"" : {
|
||||
""bike"" : ""231"",
|
||||
""description"" : ""Stadtrad"",
|
||||
""system"" : ""BC"",
|
||||
""bike_group"" : ""Konrad"",
|
||||
""station"" : """",
|
||||
""state"" : ""available"",
|
||||
""gps"" : ""9.1594501, 47.6749928""
|
||||
}
|
||||
},
|
||||
""copri_version"" : ""3.0.0.0"",
|
||||
""authcookie"" : """",
|
||||
""response_state"" : ""OK""
|
||||
}
|
||||
");
|
||||
|
||||
Assert.IsNull(l_oBikes.bikes[231].station);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeserializeStationInfoMissing()
|
||||
{
|
||||
// Response for bike 231 might not be real world answer.
|
||||
var l_oBikes = JsonConvert.DeserializeObject<BikesAvailableResponse>(@"
|
||||
{
|
||||
""apiserver"" : ""https://app.tink-konstanz.de"",
|
||||
""response"" : ""bikes_available"",
|
||||
""bikes"" : {
|
||||
""231"" : {
|
||||
""bike"" : ""231"",
|
||||
""description"" : ""Stadtrad"",
|
||||
""system"" : ""BC"",
|
||||
""bike_group"" : ""Konrad"",
|
||||
""state"" : ""available"",
|
||||
""gps"" : ""9.1594501, 47.6749928""
|
||||
}
|
||||
},
|
||||
""copri_version"" : ""3.0.0.0"",
|
||||
""authcookie"" : """",
|
||||
""response_state"" : ""OK""
|
||||
}
|
||||
");
|
||||
|
||||
Assert.IsNull(l_oBikes.bikes[231].station);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
26
TestShareeLib/Repository/Response/TestJsonConvert.cs
Normal file
26
TestShareeLib/Repository/Response/TestJsonConvert.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using NUnit.Framework;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TestShareeLib.Model.Repository.Response
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestJsonConvert
|
||||
{
|
||||
[Test]
|
||||
public void TestDeserializeObject()
|
||||
{
|
||||
Assert.That(
|
||||
() => JsonConvert.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.00"",
|
||||
""abo_eur_per_month"" : ""920.00"",
|
||||
""free_hours"" : ""3.00"",
|
||||
""number"" : ""5494"",
|
||||
-- this is not JSON !
|
||||
""name"" : ""Tester Basic""
|
||||
}"),
|
||||
Throws.InstanceOf<DeserializationException>());
|
||||
}
|
||||
}
|
||||
}
|
97
TestShareeLib/Repository/Response/TestTariffDescription.cs
Normal file
97
TestShareeLib/Repository/Response/TestTariffDescription.cs
Normal file
|
@ -0,0 +1,97 @@
|
|||
using NUnit.Framework;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TestShareeLib.Repository.Response
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestTariffDescription
|
||||
{
|
||||
[Test]
|
||||
public void TestDeserialize()
|
||||
{
|
||||
var tariffDescription = JsonConvert.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""eur_per_hour"" : ""10.00"",
|
||||
""abo_eur_per_month"" : ""920.00"",
|
||||
""free_hours"" : ""3.00"",
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.eur_per_hour,
|
||||
Is.EqualTo("10.00"));
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.abo_eur_per_month,
|
||||
Is.EqualTo("920.00"));
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.free_hours,
|
||||
Is.EqualTo("3.00"));
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.number,
|
||||
Is.EqualTo("5494"));
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.name,
|
||||
Is.EqualTo("Tester Basic"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that missing elements are initialized correctly.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestDeserialize_Missing()
|
||||
{
|
||||
var tariffDescription = JsonConvert.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.eur_per_hour,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.abo_eur_per_month,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.free_hours,
|
||||
Is.Null);
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.number,
|
||||
Is.EqualTo("5494"));
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.name,
|
||||
Is.EqualTo("Tester Basic"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that unknown elemts in JSON to not lead to firing of exceptions.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestDeserialize_NewElement()
|
||||
{
|
||||
var tariffDescription = JsonConvert.DeserializeObject<TariffDescription>(
|
||||
@"{
|
||||
""number"" : ""5494"",
|
||||
""name"" : ""Tester Basic"",
|
||||
""FancyNewElement"" : ""Yeah""
|
||||
}");
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.number,
|
||||
Is.EqualTo("5494"));
|
||||
|
||||
Assert.That(
|
||||
tariffDescription.name,
|
||||
Is.EqualTo("Tester Basic"));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue