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

208 lines
5.2 KiB
C#

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
{
[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>(@"
{
""category"" : ""cargo"",
""wheels"" : ""2"",
""engine"" : {
}
}");
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);
}
[Test]
public void TestEngine()
{
var response = JsonConvert.DeserializeObject<BikeType>(@"
{
""category"" : ""cargo"",
""wheels"" : ""2"",
""engine"" : {
""manufacturer"" : ""dummy""
}
}");
Assert.That(
response.Create().Type,
Is.EqualTo(DriveType.Pedelec));
Assert.That(
response.Create().Engine.Manufacturer,
Is.EqualTo("dummy"));
Assert.That(
response.Create().Battery.CurrentChargePercent,
Is.NaN);
Assert.That(
response.Create().Battery.CurrentChargeBars,
Is.Null);
Assert.That(
response.Create().Battery.MaxChargeBars,
Is.Null);
}
[Test]
public void TestBatteryValues1()
{
var response = JsonConvert.DeserializeObject<BikeType>(@"
{
""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"",
}
}");
Assert.That(
response.Create().Type,
Is.EqualTo(DriveType.Pedelec));
Assert.That(
response.Create().Engine.Manufacturer,
Is.EqualTo("dummy"));
Assert.That(
response.Create().Battery.CurrentChargePercent,
Is.EqualTo(70.0));
Assert.That(
response.Create().Battery.CurrentChargeBars,
Is.EqualTo(4));
Assert.That(
response.Create().Battery.MaxChargeBars,
Is.EqualTo(5));
Assert.That(
response.Create().Battery.IsBackendAccessible,
Is.False);
Assert.That(
response.Create().Battery.IsHidden,
Is.False);
}
[Test]
public void TestBatteryValues2()
{
var response = JsonConvert.DeserializeObject<BikeType>(@"
{
""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"",
}
}");
Assert.That(
response.Create().Type,
Is.EqualTo(DriveType.Pedelec));
Assert.That(
response.Create().Engine.Manufacturer,
Is.EqualTo("dummy2"));
Assert.That(
response.Create().Battery.CurrentChargePercent,
Is.EqualTo(70.3));
Assert.That(
response.Create().Battery.CurrentChargeBars,
Is.EqualTo(1));
Assert.That(
response.Create().Battery.MaxChargeBars,
Is.EqualTo(6));
Assert.That(
response.Create().Battery.IsBackendAccessible,
Is.True);
Assert.That(
response.Create().Battery.IsHidden,
Is.True);
}
}
}