mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
187 lines
8 KiB
C#
187 lines
8 KiB
C#
using NUnit.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TINK.Model.Bike;
|
|
using TINK.Model.Bikes.Bike;
|
|
using TINK.Model.State;
|
|
using TINK.Model.Station;
|
|
using BikeInfo = TINK.Model.Bike.BC.BikeInfo;
|
|
|
|
namespace TestTINKLib
|
|
{
|
|
|
|
[TestFixture]
|
|
public class TestBikeCollectionMutable
|
|
{
|
|
private class BikeInfoMutable : TINK.Model.Bike.BC.BikeInfoMutable
|
|
{
|
|
public BikeInfoMutable(
|
|
string id,
|
|
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,
|
|
TariffDescription tariffDescription = null,
|
|
Func<DateTime> dateTimeProvider = null,
|
|
IStateInfo stateInfo = null) : base(id, isDemo, group, wheelType, typeOfBike, description, stationId, stationName, operatorUri, tariffDescription, dateTimeProvider, stateInfo)
|
|
{
|
|
}
|
|
}
|
|
|
|
/// <summary> Tests the member.</summary>
|
|
[Test]
|
|
public void TestAdd()
|
|
{
|
|
var l_oColl = new BikeCollectionMutable();
|
|
|
|
l_oColl.Add(new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround));
|
|
|
|
Assert.Throws<Exception>(() => l_oColl.Add(new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo)));
|
|
}
|
|
|
|
[Test]
|
|
public void TestUpdate_Null()
|
|
{
|
|
var l_oBikeRequested = new BikeInfoMutable("20", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround);
|
|
l_oBikeRequested.State.Load(new StateInfo(() => DateTime.Now, DateTime.Now, "john@long", "1234"));
|
|
|
|
var l_oBikeColl = new BikeCollectionMutable
|
|
{
|
|
new BikeInfoMutable("63", false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround),
|
|
new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
|
|
l_oBikeRequested,
|
|
};
|
|
|
|
// Verify initial state
|
|
Assert.NotNull(l_oBikeColl.GetById("63"));
|
|
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeColl.GetById("57").State.Value);
|
|
Assert.AreEqual(InUseStateEnum.Reserved, l_oBikeColl.GetById("20").State.Value);
|
|
Assert.Null(l_oBikeColl.GetById("33"));
|
|
|
|
l_oBikeColl.Update(null, null );
|
|
|
|
// Verify modified state
|
|
Assert.Null(l_oBikeColl.GetById("63"));
|
|
Assert.Null(l_oBikeColl.GetById("57"));
|
|
Assert.Null(l_oBikeColl.GetById("20"));
|
|
Assert.Null(l_oBikeColl.GetById("33"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestUpdate()
|
|
{
|
|
var bikeRequested = new BikeInfoMutable("20", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Allround);
|
|
bikeRequested.State.Load(new StateInfo(() => DateTime.Now, DateTime.Now, "john@long", "1234"));
|
|
|
|
var bikeColl = new BikeCollectionMutable
|
|
{
|
|
new BikeInfoMutable("63", false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround),
|
|
new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
|
|
bikeRequested,
|
|
};
|
|
|
|
// Verify initial state
|
|
Assert.NotNull(bikeColl.GetById("63")); // Will be removed
|
|
Assert.AreEqual(InUseStateEnum.Disposable, bikeColl.GetById("57").State.Value); // Will be requested
|
|
Assert.AreEqual(InUseStateEnum.Reserved, bikeColl.GetById("20").State.Value); // Will be booked
|
|
Assert.Null(bikeColl.GetById("33")); //
|
|
|
|
var l_oBikeResponse = new List<BikeInfo>
|
|
{
|
|
new BikeInfo("57" /* bike id*/, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "7" /*station id*/, null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
|
|
new BikeInfo("20", false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "7", null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
|
|
new BikeInfo("33", "7", null /*operator uri*/, null, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround),
|
|
};
|
|
|
|
|
|
bikeColl.Update(l_oBikeResponse, new List<IStation>());
|
|
|
|
// Verify modified state
|
|
Assert.Null(bikeColl.GetById("63"), "Bike not contained in response must not exist.");
|
|
Assert.AreEqual(InUseStateEnum.Booked, bikeColl.GetById("57").State.Value);
|
|
Assert.AreEqual(InUseStateEnum.Booked, bikeColl.GetById("20").State.Value);
|
|
Assert.NotNull(bikeColl.GetById("33"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bike for which station name is updated is not contained in bike collection when calling update.
|
|
/// </summary>
|
|
[Test]
|
|
public void TestUpdate_StationName_NewBike()
|
|
{
|
|
var bikeColl = new BikeCollectionMutable();
|
|
|
|
// Verify initial state
|
|
Assert.That(bikeColl.GetById("57"), Is.Null);
|
|
|
|
var l_oBikeResponse = new List<BikeInfo>
|
|
{
|
|
new BikeInfo("57" /* bike id*/, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "7" /*station id*/, null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
|
|
};
|
|
|
|
var stations = new List<IStation>
|
|
{
|
|
new Station("7", new List<string>(), null, "My facy station")
|
|
};
|
|
|
|
bikeColl.Update(l_oBikeResponse, stations);
|
|
|
|
// Verify modified state
|
|
Assert.That(bikeColl.GetById("57").StationId, Is.EqualTo("7"));
|
|
Assert.That(bikeColl.GetById("57").StationName, Is.EqualTo("My facy station"));
|
|
}
|
|
|
|
|
|
[Test]
|
|
public void TestUpdate_StationName_UpdateExistingBike()
|
|
{
|
|
|
|
var bikeColl = new BikeCollectionMutable
|
|
{
|
|
new BikeInfoMutable("57", false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo),
|
|
};
|
|
|
|
// Verify initial state
|
|
Assert.That(bikeColl.GetById("57"), Is.Not.Null);
|
|
|
|
var bikeResponse = new List<BikeInfo>
|
|
{
|
|
new BikeInfo("57" /* bike id*/, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "7" /*station id*/, null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
|
|
};
|
|
|
|
var stations = new List<IStation>
|
|
{
|
|
new Station("7", new List<string>(), null, "My facy station")
|
|
};
|
|
|
|
bikeColl.Update(bikeResponse, stations);
|
|
|
|
// Verify modified state
|
|
Assert.That(bikeColl.GetById("57").StationId, Is.Null, "Station id is only set when update creates BikeInfo object, not when updating object BikeInfo because station name does not change.");
|
|
Assert.That(bikeColl.GetById("57").StationName, Is.Null, "Station name is only set when update creates BikeInfo object, not when updating object BikeInfo because station name does not change.");
|
|
}
|
|
|
|
[Test]
|
|
public void TestUpdate_StationName_Nullstations()
|
|
{
|
|
|
|
var bikeColl = new BikeCollectionMutable();
|
|
|
|
|
|
var l_oBikeResponse = new List<BikeInfo>
|
|
{
|
|
new BikeInfo("57" /* bike id*/, false, new List<string> {"TINK" }, WheelType.Trike, TypeOfBike.Allround, "Test description", "7" /*station id*/, null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
|
|
};
|
|
|
|
bikeColl.Update(l_oBikeResponse, null);
|
|
|
|
// Verify modified state
|
|
Assert.That(bikeColl.GetById("57").StationId, Is.EqualTo("7"));
|
|
Assert.That(bikeColl.GetById("57").StationName, Is.EqualTo(""));
|
|
}
|
|
}
|
|
}
|