sharee.bike-App/TestShareeLib/Model/Connector/Updater/TestDriveFactory.cs

209 lines
5.2 KiB
C#
Raw Normal View History

2022-08-30 15:42:25 +02:00
using Newtonsoft.Json;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
using TINK.Model.Connector.Updater;
using TINK.Repository.Response;
namespace TestShareeLib.Model.Connector.Updater
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestDriveFactory
{
[Test]
public void TestEmpty()
{
var response = JsonConvert.DeserializeObject<BikeType>(@"");
Assert.That(
response.Create().Type,
Is.EqualTo(DriveType.SoleHumanPowered));
Assert.That(
response.Create().Engine.Manufacturer,
Is.Null);
Assert.That(
response.Create().Battery.CurrentChargePercent,
Is.NaN);
Assert.That(
response.Create().Battery.CurrentChargeBars,
Is.Null);
Assert.That(
response.Create().Battery.MaxChargeBars,
Is.Null);
Assert.That(
response.Create().Battery.IsBackendAccessible,
Is.Null);
Assert.That(
response.Create().Battery.IsHidden,
Is.Null);
}
[Test]
public void TestEmptyEngine()
{
var response = JsonConvert.DeserializeObject<BikeType>(@"
2022-08-30 15:42:25 +02:00
{
""category"" : ""cargo"",
""wheels"" : ""2"",
""engine"" : {
}
}");
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Type,
Is.EqualTo(DriveType.SoleHumanPowered));
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Engine.Manufacturer,
Is.Null);
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.CurrentChargePercent,
Is.NaN);
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.CurrentChargeBars,
Is.Null);
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.MaxChargeBars,
Is.Null);
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestEngine()
{
var response = JsonConvert.DeserializeObject<BikeType>(@"
2022-08-30 15:42:25 +02:00
{
""category"" : ""cargo"",
""wheels"" : ""2"",
""engine"" : {
""manufacturer"" : ""dummy""
}
}");
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Type,
Is.EqualTo(DriveType.Pedelec));
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Engine.Manufacturer,
Is.EqualTo("dummy"));
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.CurrentChargePercent,
Is.NaN);
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.CurrentChargeBars,
Is.Null);
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.MaxChargeBars,
Is.Null);
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestBatteryValues1()
{
var response = JsonConvert.DeserializeObject<BikeType>(@"
2022-08-30 15:42:25 +02:00
{
""category"" : ""cargo"",
""wheels"" : ""2"",
""engine"" : {
""manufacturer"" : ""dummy""
},
""battery"" : {
""charge_current_bars"" : ""4"",
""charge_max_bars"" : ""5"",
""charge_current_percent"" : ""70"",
""backend_accessible"" : ""0"",
""hidden"" : ""0"",
}
}");
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Type,
Is.EqualTo(DriveType.Pedelec));
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Engine.Manufacturer,
Is.EqualTo("dummy"));
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.CurrentChargePercent,
Is.EqualTo(70.0));
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.CurrentChargeBars,
Is.EqualTo(4));
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.MaxChargeBars,
Is.EqualTo(5));
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.IsBackendAccessible,
Is.False);
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.IsHidden,
Is.False);
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestBatteryValues2()
{
var response = JsonConvert.DeserializeObject<BikeType>(@"
2022-08-30 15:42:25 +02:00
{
""category"" : ""cargo"",
""wheels"" : ""2"",
""engine"" : {
""manufacturer"" : ""dummy2""
},
""battery"" : {
""charge_current_bars"" : ""1"",
""charge_max_bars"" : ""6"",
""charge_current_percent"" : ""70.3"",
""backend_accessible"" : ""1"",
""hidden"" : ""1"",
}
}");
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Type,
Is.EqualTo(DriveType.Pedelec));
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Engine.Manufacturer,
Is.EqualTo("dummy2"));
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.CurrentChargePercent,
Is.EqualTo(70.3));
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.CurrentChargeBars,
Is.EqualTo(1));
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.MaxChargeBars,
Is.EqualTo(6));
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.IsBackendAccessible,
Is.True);
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
response.Create().Battery.IsHidden,
Is.True);
}
}
2022-08-30 15:42:25 +02:00
}