Initial version

This commit is contained in:
Oliver Hauff 2021-05-13 20:09:46 +02:00
parent 41b618cb27
commit e4fb48f6ab
24 changed files with 4387 additions and 0 deletions

View file

@ -0,0 +1,17 @@
using NUnit.Framework;
using TINK.Model.Bike.BC;
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BC
{
[TestFixture]
public class TestBikeInfo
{
[Test]
public void TestCtorCopyNull()
{
Assert.Throws<System.ArgumentException>(
() => new BikeInfo(null),
"Verify that no unspecific reference not set to... exception is thrown");
}
}
}

View file

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using TINK.Model.Bike;
using TINK.Model.Bikes.Bike;
using TINK.Model.State;
namespace TestTINKLib
{
[TestFixture]
class TestBikeMutable
{
private class BikeInfoMutable : TINK.Model.Bike.BC.BikeInfoMutable
{
public BikeInfoMutable(
int id,
bool isDemo = false,
IEnumerable<string> group = null,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null,
int? currentStationId = null,
Uri operatorUri = null,
TariffDescription tariffDescription = null,
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null) : base(id, isDemo, group, wheelType, typeOfBike, description, currentStationId, operatorUri, tariffDescription, dateTimeProvider, stateInfo)
{
}
}
[Test]
public void TestConstruct()
{
var l_oBike = new BikeInfoMutable(
42,
false,
new List<string> { "TINK" },
WheelType.Two,
TypeOfBike.Cargo);
Assert.AreEqual(42, l_oBike.Id);
Assert.IsFalse(l_oBike.IsDemo);
Assert.AreEqual(WheelType.Two, l_oBike.WheelType);
Assert.AreEqual(TypeOfBike.Cargo, l_oBike.TypeOfBike);
Assert.AreEqual(InUseStateEnum.Disposable, l_oBike.State.Value);
Assert.IsNull(l_oBike.CurrentStation);
l_oBike = new BikeInfoMutable(
17,
true,
new List<string> { "TINK" },
WheelType.Mono,
TypeOfBike.Allround,
"Test description",
1);
Assert.AreEqual(17, l_oBike.Id);
Assert.IsTrue(l_oBike.IsDemo);
Assert.AreEqual(WheelType.Mono, l_oBike.WheelType);
Assert.AreEqual(TypeOfBike.Allround, l_oBike.TypeOfBike);
Assert.AreEqual(InUseStateEnum.Disposable, l_oBike.State.Value);
Assert.AreEqual(1, l_oBike.CurrentStation);
}
[Test]
public void TestToString()
{
var l_oBike = new BikeInfoMutable(3, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Cargo, dateTimeProvider: () => new DateTime(1970, 1, 1));
Assert.AreEqual(
"Id=3, wheel(s)=Two, type=Cargo, demo=False, state=Disposable, location=On the road.",
l_oBike.ToString());
l_oBike = new BikeInfoMutable(3, true, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", 5, dateTimeProvider: () => new DateTime(1970, 1, 1));
Assert.AreEqual(
"Id=3, wheel(s)=Trike, type=Allround, demo=True, state=Disposable, location=Station 5.",
l_oBike.ToString());
}
}
}

View file

@ -0,0 +1,59 @@
using Newtonsoft.Json;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using TINK.Model.Bike;
using TINK.Model.State;
using BikeInfoMutable = TINK.Model.Bike.BC.BikeInfoMutable;
namespace TestTINKLib
{
/// <summary>
/// Exclude from build beause serialization... see below.
/// </summary>
[TestFixture]
public class TestBikeSerializeJSON
{
[Test, Ignore("Disabled because serialization does no more work due to inheritance since commit ec14b93b.")]
public void TestConstruct_SerializeJSON_Disposable()
{
// Create object to test.
var l_oBikeSource = new BikeInfoMutable(3, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Cargo, p_oDateTimeProvider: () => new DateTime(1970, 1, 1));
// Verify prerequisites
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeSource.State.Value);
Assert.IsNull(l_oBikeSource.State.MailAddress);
Assert.IsNull(l_oBikeSource.State.Code);
Assert.IsNull(l_oBikeSource.State.From);
// Serialize object and verify.
var l_oDetected = JsonConvert.SerializeObject(l_oBikeSource, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
const string EXPECTED = @"
{
""Id"": 3,
""CurrentStation"": null,
""WheelType"": 1,
""TypeOfBike"": 1,
""State"": {
""StateInfoObject"": {
""$type"": ""TINK.Model.State.StateAvailableInfo, TINKLib""
}
}
}";
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED),
TestHelper.PrepareXmlForStringCompare(l_oDetected));
// Deserialize object.
var l_oBikeTarget = JsonConvert.DeserializeObject<BikeInfoMutable>(l_oDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
// Verify state.
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeTarget.State.Value);
Assert.IsNull(l_oBikeTarget.State.MailAddress);
Assert.IsNull(l_oBikeTarget.State.Code);
Assert.IsNull(l_oBikeTarget.State.From);
}
}
}