Version 3.0.360

This commit is contained in:
Anja 2023-02-22 14:03:35 +01:00
parent 5c0b2e70c9
commit faf68061f4
160 changed files with 2114 additions and 1932 deletions

View file

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS;
using TINK.Model.Bikes.BikeInfoNS.BC;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
using TINK.Model.State;
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BC
{
[TestFixture]
public class TestBikeInfo
{
/// <summary>
/// Dummy subclass to provide assess to protected member for testing.
/// </summary>
private class TestBikeInfoSubClass : BikeInfo
{
public TestBikeInfoSubClass(
IStateInfo stateInfo,
TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike bike,
Drive drive,
bool? isDemo = DEFAULTVALUEISDEMO,
IEnumerable<string> group = null,
string stationId = null,
Uri operatorUri = null,
RentalDescription tariffDescription = null) : base(
stateInfo,
bike,
drive,
DataSource.Copri,
isDemo,
group,
stationId,
operatorUri,
tariffDescription)
{
}
}
[Test]
public void TestCtorCopyNull()
{
Assert.Throws<ArgumentNullException>(
() => new BikeInfo(null),
"Verify that no unspecific reference not set to... exception is thrown");
}
[Test]
public void TestCtorBikeNull()
{
Assert.That(
() => new TestBikeInfoSubClass(new StateInfo(), null, new Drive()),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorDriveNull()
{
Assert.That(
() => new TestBikeInfoSubClass(new StateInfo(), new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike(string.Empty, LockModel.ILockIt), null),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorCopy()
{
Assert.That(
() => new BikeInfo(null),
Throws.ArgumentNullException);
}
}
}

View file

@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using NSubstitute;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.State;
using IBikeInfo = TINK.Model.Bikes.BikeInfoNS.BC.IBikeInfo;
namespace TestTINKLib.Fixtures.ObjectTests.Bike
{
[TestFixture]
public class TestBikeInfoMutable
{
private class BikeInfoMutable : TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
{
public BikeInfoMutable(
string id,
LockModel lockModel,
bool isDemo = false,
IEnumerable<string> group = null,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null,
string stationId = null,
string stationName = null,
Uri operatorUri = null,
RentalDescription tariffDescription = null,
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null) : base(
new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike(id, lockModel, wheelType, typeOfBike, description),
new TINK.Model.Bikes.BikeInfoNS.DriveNS.Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
isDemo,
group,
stationId,
stationName,
operatorUri,
tariffDescription,
dateTimeProvider,
stateInfo)
{
}
}
[Test]
public void TestConstruct()
{
var l_oBikeInfo = new BikeInfoMutable("17", LockModel.ILockIt);
Assert.AreEqual("17", l_oBikeInfo.Id);
Assert.IsNull(l_oBikeInfo.StationId);
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeInfo.State.Value);
Assert.AreEqual(null, l_oBikeInfo.WheelType);
Assert.AreEqual(null, l_oBikeInfo.TypeOfBike);
l_oBikeInfo = new BikeInfoMutable("22", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo, "Test description", "23");
Assert.AreEqual("22", l_oBikeInfo.Id);
Assert.IsFalse(l_oBikeInfo.IsDemo);
Assert.AreEqual("23", l_oBikeInfo.StationId);
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeInfo.State.Value);
Assert.AreEqual(WheelType.Trike, l_oBikeInfo.WheelType);
Assert.AreEqual(TypeOfBike.Cargo, l_oBikeInfo.TypeOfBike);
}
[Test]
public void TestConstructCopyBooked()
{
// State Booked
var bikeInfoSource = Substitute.For<IBikeInfo>();
var stateSource = Substitute.For<IStateInfo>();
bikeInfoSource.Bike.Returns(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.BordComputer, WheelType.Trike, TypeOfBike.Cargo));
bikeInfoSource.StationId.Returns("23");
bikeInfoSource.State.Returns(stateSource);
stateSource.Value.Returns(InUseStateEnum.Booked);
stateSource.From.Returns(new System.DateTime(2018, 01, 03));
stateSource.MailAddress.Returns("a@b");
stateSource.Code.Returns("234");
var bikeInfoTarget = new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable(bikeInfoSource, "My Station Name");
Assert.AreEqual(InUseStateEnum.Booked, bikeInfoTarget.State.Value);
Assert.AreEqual("22", bikeInfoTarget.Id);
Assert.AreEqual("23", bikeInfoTarget.StationId);
Assert.AreEqual("My Station Name", bikeInfoTarget.StationName);
Assert.AreEqual(WheelType.Trike, bikeInfoTarget.WheelType);
Assert.AreEqual(TypeOfBike.Cargo, bikeInfoTarget.TypeOfBike);
Assert.AreEqual(InUseStateEnum.Booked, bikeInfoTarget.State.Value);
Assert.AreEqual(new System.DateTime(2018, 01, 03), bikeInfoTarget.State.From);
Assert.AreEqual("a@b", bikeInfoTarget.State.MailAddress);
}
[Test]
public void TestConstructCopyReserved()
{
// State Reserved
var bikeInfoSource = Substitute.For<IBikeInfo>();
var stateSource = Substitute.For<IStateInfo>();
bikeInfoSource.Bike.Returns(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.BordComputer, WheelType.Trike, TypeOfBike.Cargo));
bikeInfoSource.StationId.Returns("23");
bikeInfoSource.State.Returns(stateSource);
stateSource.Value.Returns(InUseStateEnum.Reserved);
stateSource.From.Returns(new System.DateTime(2018, 01, 03));
stateSource.MailAddress.Returns("a@b");
stateSource.Code.Returns("234");
var bikeInfoTarget = new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable(bikeInfoSource, "My Station Name");
Assert.AreEqual(InUseStateEnum.Reserved, bikeInfoTarget.State.Value);
Assert.AreEqual("22", bikeInfoTarget.Id);
Assert.AreEqual("23", bikeInfoTarget.StationId);
Assert.AreEqual(WheelType.Trike, bikeInfoTarget.WheelType);
Assert.AreEqual(TypeOfBike.Cargo, bikeInfoTarget.TypeOfBike);
Assert.AreEqual(InUseStateEnum.Reserved, bikeInfoTarget.State.Value);
Assert.AreEqual(new System.DateTime(2018, 01, 03), bikeInfoTarget.State.From);
Assert.AreEqual("a@b", bikeInfoTarget.State.MailAddress);
}
[Test]
public void TestConstructCopyAvailable()
{
// State Disposable
var bikeInfoSource = Substitute.For<IBikeInfo>();
var stateSource = Substitute.For<IStateInfo>();
bikeInfoSource.Bike.Returns(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.BordComputer, WheelType.Trike, TypeOfBike.Cargo));
bikeInfoSource.StationId.Returns("23");
bikeInfoSource.State.Returns(stateSource);
stateSource.Value.Returns(InUseStateEnum.Disposable);
var bikeInfoTarget = new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable(bikeInfoSource, "My Station Name");
Assert.AreEqual(InUseStateEnum.Disposable, bikeInfoTarget.State.Value);
Assert.AreEqual("22", bikeInfoTarget.Id);
Assert.AreEqual("23", bikeInfoTarget.StationId);
Assert.AreEqual(WheelType.Trike, bikeInfoTarget.WheelType);
Assert.AreEqual(TypeOfBike.Cargo, bikeInfoTarget.TypeOfBike);
Assert.AreEqual(InUseStateEnum.Disposable, bikeInfoTarget.State.Value);
Assert.IsNull(bikeInfoTarget.State.From);
}
[Test]
public void TestConstructBikeNull()
{
Assert.That(
() => new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable(null, "My Station Name"),
Throws.ArgumentNullException);
}
}
}

View file

@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.State;
namespace TestTINKLib
{
[TestFixture]
class TestBikeMutable
{
private class BikeInfoMutable : TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
{
public BikeInfoMutable(
string id,
LockModel lockType,
bool isDemo = false,
IEnumerable<string> group = null,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null,
string stationId = null,
string stationName = null,
Uri operatorUri = null,
RentalDescription tariffDescription = null,
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null) : base(
new Bike(id, lockType, wheelType, typeOfBike, description),
new TINK.Model.Bikes.BikeInfoNS.DriveNS.Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
isDemo,
group,
stationId,
stationName,
operatorUri,
tariffDescription,
dateTimeProvider,
stateInfo)
{
}
}
[Test]
public void TestConstruct()
{
var l_oBike = new BikeInfoMutable(
"42",
LockModel.ILockIt,
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.StationId);
l_oBike = new BikeInfoMutable(
"17",
LockModel.ILockIt,
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.StationId);
}
[Test]
public void TestToString()
{
var l_oBike = new BikeInfoMutable("3", LockModel.ILockIt, 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", LockModel.ILockIt, 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);
}
}
}