mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-16 07:06:33 +01:00
209 lines
5.3 KiB
C#
209 lines
5.3 KiB
C#
using Newtonsoft.Json;
|
|
using NUnit.Framework;
|
|
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS;
|
|
using ShareeBike.Model.Connector.Updater;
|
|
using ShareeBike.Repository.Response;
|
|
using DriveType = ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.DriveType;
|
|
|
|
namespace SharedBusinessLogic.Tests.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);
|
|
}
|
|
}
|
|
}
|