Version 3.0.337

This commit is contained in:
Anja Müller-Meißner 2022-08-30 15:42:25 +02:00
parent fd0e63cf10
commit 573fe77e12
2336 changed files with 33688 additions and 86082 deletions

View file

@ -1,17 +1,73 @@
using NUnit.Framework;
using TINK.Model.Bike.BC;
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,
isDemo,
group,
stationId,
operatorUri,
tariffDescription)
{
}
}
[Test]
public void TestCtorCopyNull()
{
Assert.Throws<System.ArgumentException>(
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

@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using TINK.Model.Bike;
using TINK.Model.Bikes.Bike;
using TINK.Model.Bikes.BikeInfoNS;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.State;
namespace TestTINKLib
@ -10,22 +10,32 @@ namespace TestTINKLib
[TestFixture]
class TestBikeMutable
{
private class BikeInfoMutable : TINK.Model.Bike.BC.BikeInfoMutable
private class BikeInfoMutable : TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
{
public BikeInfoMutable(
string id,
string id,
LockModel lockType,
bool isDemo = false,
IEnumerable<string> group = null,
WheelType? wheelType = null,
bool isDemo = false,
IEnumerable<string> group = null,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null,
string description = null,
string stationId = null,
string stationName = null,
Uri operatorUri = null,
RentalDescription tariffDescription = null,
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null) : base(id, lockType, isDemo, group, wheelType, typeOfBike, description, stationId, stationName, operatorUri, tariffDescription, dateTimeProvider, stateInfo)
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null) : base(
new Bike(id, lockType, wheelType, typeOfBike, description),
new TINK.Model.Bikes.BikeInfoNS.DriveNS.Drive(),
isDemo,
group,
stationId,
stationName,
operatorUri,
tariffDescription,
dateTimeProvider,
stateInfo)
{
}
}
@ -51,7 +61,7 @@ namespace TestTINKLib
l_oBike = new BikeInfoMutable(
"17",
LockModel.ILockIt,
true,
true,
new List<string> { "TINK" },
WheelType.Mono,
TypeOfBike.Allround,

View file

@ -1,7 +1,8 @@
using NUnit.Framework;
using System;
using TINK.Model.Bike;
using TINK.Model.Bike.BluetoothLock;
using System;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
using TINK.Model.State;
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
@ -17,32 +18,86 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
"Verify that no unspecific reference not set to... exception is thrown");
Assert.Throws<ArgumentException>(
() => new BikeInfo(new TINK.Model.Bike.BC.BikeInfo("12", LockModel.ILockIt, "1"), null),
() => new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), "1"), null),
"Verify that no unspecific reference not set to... exception is thrown");
}
[Test]
public void TestCtorAvailable()
{
Assert.AreEqual ("12",new BikeInfo("12", 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "13").Id);
Assert.AreEqual("13", new BikeInfo("12", 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "13").StationId);
Assert.AreEqual(InUseStateEnum.Disposable, new BikeInfo("12", 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "13").State.Value);
Assert.AreEqual("12", new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "13").Id);
Assert.AreEqual("13", new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "13").StationId);
Assert.AreEqual(InUseStateEnum.Disposable, new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "13").State.Value);
}
[Test]
public void TestCtorAvailableBikeNull()
{
Assert.That(
() => new BikeInfo(
null,
new Drive(),
5200544,
new Guid("00000000-0000-0000-0000-000000000001"),
"13"),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorRequested()
{
Assert.AreEqual("12", new BikeInfo("12", 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null, null, dateTimeProvider: () => new DateTime(2019, 1, 1), false /*isDemo*/, null /*group*/, null /*wheelType*/, null /*typeOfBike*/, null /*description*/).Id);
Assert.AreEqual(112, new BikeInfo("12", 112, new Guid(), null, null, null, new DateTime(2020,1,1), "a@b", "13", null, null, dateTimeProvider: () => new DateTime(2019, 1, 1), false /*isDemo*/, null /*group*/, null /*wheelType*/, null /*typeOfBike*/, null /*description*/).LockInfo.Id);
Assert.AreEqual(InUseStateEnum.Reserved, new BikeInfo("12", 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null, null, dateTimeProvider: () => new DateTime(2019, 1, 1), false /*isDemo*/, null /*group*/, null /*wheelType*/, null /*typeOfBike*/, null /*description*/).State.Value);
Assert.AreEqual("12", new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null, null, dateTimeProvider: () => new DateTime(2019, 1, 1), false /*isDemo*/, null /*group*/).Id);
Assert.AreEqual(112, new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null, null, dateTimeProvider: () => new DateTime(2019, 1, 1), false /*isDemo*/, null /*group*/).LockInfo.Id);
Assert.AreEqual(InUseStateEnum.Reserved, new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null, null, dateTimeProvider: () => new DateTime(2019, 1, 1), false /*isDemo*/, null /*group*/).State.Value);
}
[Test]
public void TestCtorRequestedBikeNull()
{
Assert.That(
() => new BikeInfo(
null,
new Drive(), 112,
new Guid(),
null,
null,
null,
new DateTime(2020, 1, 1),
"a@b",
"13",
null,
null,
dateTimeProvider: () => new DateTime(2019, 1, 1),
false /*isDemo*/,
null /*group*/),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorBooked()
{
Assert.AreEqual("12", new BikeInfo("12", 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null /*operator uri*/).Id);
Assert.AreEqual(112, new BikeInfo("12", 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null /*operator uri*/).LockInfo.Id);
Assert.AreEqual(InUseStateEnum.Booked, new BikeInfo("12", 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null /*operator uri*/).State.Value);
Assert.AreEqual("12", new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null /*operator uri*/).Id);
Assert.AreEqual(112, new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null /*operator uri*/).LockInfo.Id);
Assert.AreEqual(InUseStateEnum.Booked, new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("12", LockModel.ILockIt), new Drive(), 112, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b", "13", null /*operator uri*/).State.Value);
}
[Test]
public void TestCtorBookedNull()
{
Assert.That(
() => new BikeInfo(
null,
new Drive(),
112,
new Guid(),
null,
null,
null,
new DateTime(2020, 1, 1),
"a@b",
"13",
null /*operator uri*/),
Throws.ArgumentNullException);
}
}
}

View file

@ -1,6 +1,7 @@
using NUnit.Framework;
using System;
using TINK.Model.Bike.BluetoothLock;
using System;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
namespace TestShareeLib.Model.Bike.BluetoothLock
{
@ -11,8 +12,16 @@ namespace TestShareeLib.Model.Bike.BluetoothLock
public void TestCtor()
{
Assert.That(
new BikeInfoMutable(new BikeInfo("MyBikeId", 42, new Guid(), "17"), "My Station Name").StationName,
new BikeInfoMutable(new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("MyBikeId", TINK.Model.Bikes.BikeInfoNS.BikeNS.LockModel.ILockIt), new Drive(), 42, new Guid(), "17"), "My Station Name").StationName,
Is.EqualTo("My Station Name"));
}
[Test]
public void TestCtorBikeNull()
{
Assert.That(
() => new BikeInfoMutable(null, "My Station Name"),
Throws.ArgumentNullException);
}
}
}

View file

@ -1,6 +1,6 @@
using NUnit.Framework;
using System;
using TINK.Model.Bike.BluetoothLock;
using System;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
{
[TestFixture]
@ -12,7 +12,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
Assert.AreEqual(
LockingState.UnknownDisconnected,
new LockInfo.Builder { Id = 123 }.Build().State);
Assert.AreEqual(
123,
new LockInfo.Builder { Id = 123 }.Build().Id);
@ -21,20 +21,23 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
[Test]
public void TestEquals()
{
Assert.IsTrue(new LockInfo.Builder {
Assert.IsTrue(new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed}.Build() == new LockInfo.Builder {
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build());
State = LockingState.Closed
}.Build() == new LockInfo.Builder
{
Id = 2,
Guid = new Guid("0000f00d-1212-efde-1523-785fef13d123"),
Seed = new byte[] { 1, 2 },
UserKey = new byte[] { 7, 2 },
AdminKey = new byte[] { 2, 1 },
State = LockingState.Closed
}.Build());
}
[Test]

View file

@ -1,8 +1,8 @@
using NUnit.Framework;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using TINK.Model.Bike.BluetoothLock;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
using TINK.Services.BluetoothLock.Tdo;
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
@ -13,7 +13,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
[Test]
public void TestUpdateById_State()
{
var locksInfo = new List<LockInfo> {
var locksInfo = new List<LockInfo> {
new LockInfo.Builder { Id = 12, Seed = new byte[] { 3, 5 }, UserKey = new byte[] {2, 1 }, State = LockingState.UnknownFromHardwareError }.Build(),
new LockInfo.Builder { Id = 14, Seed = new byte[] { 3, 1 }, UserKey = new byte[] {2, 7 }, State = LockingState.Open }.Build(),
new LockInfo.Builder { Id = 3, Seed = new byte[] { 1, 5 }, UserKey = new byte[] {2, 9 }, State = LockingState.Closed }.Build(),

View file

@ -1,7 +1,7 @@
using NUnit.Framework;
using System;
using System;
using System.Linq;
using TINK.Model.Bike.BluetoothLock;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
{
@ -12,8 +12,8 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
public void TestCtor()
{
var lockInfo = new LockInfoMutable(
1,
new Guid("00000000-0000-0000-0000-e57e6b9aee16"),
1,
new Guid("00000000-0000-0000-0000-e57e6b9aee16"),
new byte[] { 1, 2, 3 }, // User key
new byte[] { 1, 23 }, // Admin key
new byte[] { 1, 12 }, // Seed

View file

@ -0,0 +1,87 @@
using System;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
namespace TestShareeLib.Model.Bike.CopriLock
{
[TestFixture]
public class TestBikeInfo
{
[Test]
public void TestCtorAvailable()
{
var bike = new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("bikeId", LockModel.Sigo),
new Drive(),
"stationId",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo());
Assert.That(
bike.State.Value,
Is.EqualTo(TINK.Model.State.InUseStateEnum.Disposable));
}
[Test]
public void TestCtorAvailableBikeNull()
{
Assert.That(
() => new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
null,
new Drive(),
"stationId",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo()),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorFeedbackRequired()
{
var bike = new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("bikeId", LockModel.Sigo),
new Drive(),
"stationId",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo(),
true);
Assert.That(
bike.State.Value,
Is.EqualTo(TINK.Model.State.InUseStateEnum.FeedbackPending));
}
[Test]
public void TestCtorRequestedBikeNull()
{
Assert.That(
() => new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
null,
new Drive(),
DateTime.Now,
"a@b",
"stationId",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo(),
new Uri("https://sharee.bike"),
new RentalDescription(),
() => DateTime.Now),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorOccupiedBikeNull()
{
Assert.That(
() => new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
null,
new Drive(),
DateTime.Now,
"a@b",
"stationId",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo(),
new Uri("https://sharee.bike"),
new RentalDescription()),
Throws.ArgumentNullException);
}
}
}

View file

@ -0,0 +1,36 @@
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BC;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
namespace TestShareeLib.Model.Bike.CopriLock
{
[TestFixture]
public class TestBikeInfoMutable
{
[Test]
public void TestCtorBikeInfoNull()
{
Assert.That(
() => new BikeInfoMutable(null, "Station 32"),
Throws.ArgumentNullException);
}
[Test]
public void TestCtorBikeInfo()
{
var bike = new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike(
"MyId",
TINK.Model.Bikes.BikeInfoNS.BikeNS.LockModel.Sigo);
var bikeInfo = new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
bike,
new Drive(new TINK.Model.Bikes.BikeInfoNS.DriveNS.EngineNS.Engine("BackendLock")),
"StationId",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo());
Assert.That(
new BikeInfoMutable(bikeInfo, "Station 32").Drive.Type,
Is.EqualTo(DriveType.Pedelec));
}
}
}

View file

@ -2,7 +2,7 @@
namespace TestTINKLib.Fixtures.ObjectTests.Bike
{
using TINK.Model.Bike;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
[TestFixture]
public class TestBike

View file

@ -1,11 +1,10 @@
using NUnit.Framework;
using System;
using TINK.Model.Bike;
using TINK.Model.Bikes;
namespace TestTINKLib
{
[TestFixture]
public class TestBikeCollection
{

View file

@ -1,21 +1,23 @@
using Newtonsoft.Json;
using NUnit.Framework;
using System;
using System;
using System.Collections.Generic;
using TINK.Model.Bike;
using TINK.Model.Bikes.Bike;
using TINK.Model.Connector;
using Newtonsoft.Json;
using NUnit.Framework;
using TINK.Model.Bikes;
using TINK.Model.Bikes.BikeInfoNS;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
using TINK.Model.Connector.Updater;
using TINK.Model.State;
using TINK.Model.Station;
using BikeInfo = TINK.Model.Bike.BC.BikeInfo;
using BikeInfo = TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo;
namespace TestTINKLib
{
[TestFixture]
public class TestBikeCollectionMutable
{
private class BikeInfoMutable : TINK.Model.Bike.BC.BikeInfoMutable
private class BikeInfoMutable : TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
{
public BikeInfoMutable(
string id,
@ -30,7 +32,17 @@ namespace TestTINKLib
Uri operatorUri = null,
RentalDescription tariffDescription = null,
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null) : base(id, lockType, isDemo, group, wheelType, typeOfBike, description, stationId, stationName, operatorUri, tariffDescription, dateTimeProvider, stateInfo)
IStateInfo stateInfo = null) : base(
new Bike(id, lockType, wheelType, typeOfBike, description),
new TINK.Model.Bikes.BikeInfoNS.DriveNS.Drive(),
isDemo,
group,
stationId,
stationName,
operatorUri,
tariffDescription,
dateTimeProvider,
stateInfo)
{
}
}
@ -41,7 +53,7 @@ namespace TestTINKLib
{
var l_oColl = new BikeCollectionMutable();
l_oColl.Add(new BikeInfoMutable("57", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround));
l_oColl.Add(new BikeInfoMutable("57", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Allround));
Assert.Throws<Exception>(() => l_oColl.Add(new BikeInfoMutable("57", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Trike, TypeOfBike.Cargo)));
}
@ -65,7 +77,7 @@ namespace TestTINKLib
Assert.AreEqual(InUseStateEnum.Reserved, l_oBikeColl.GetById("20").State.Value);
Assert.Null(l_oBikeColl.GetById("33"));
l_oBikeColl.Update(null, null );
l_oBikeColl.Update(null, null);
// Verify modified state
Assert.Null(l_oBikeColl.GetById("63"));
@ -95,24 +107,26 @@ namespace TestTINKLib
var bikeResponse = new List<BikeInfo>
{
new TINK.Model.Bike.CopriLock.BikeInfo(
"57" /* bike id*/,
new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new Bike("57", LockModel.ILockIt),
new Drive(),
DateTime.Now,
"john@long",
"7" /*station id*/,
new TINK.Model.Bikes.Bike.CopriLock.LockInfo(),
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo(),
null),
new TINK.Model.Bike.CopriLock.BikeInfo(
"20",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new Bike("20", LockModel.ILockIt),
new Drive(),
DateTime.Now,
"john@long",
"7",
new TINK.Model.Bikes.Bike.CopriLock.LockInfo(),
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo(),
null),
new TINK.Model.Bike.CopriLock.BikeInfo(
"33",
new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new Bike("33", LockModel.Sigo), new Drive(),
"7",
new TINK.Model.Bikes.Bike.CopriLock.LockInfo()),
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo()),
};
@ -138,10 +152,10 @@ namespace TestTINKLib
var l_oBikeResponse = new List<BikeInfo>
{
new TINK.Model.Bike.CopriLock.BikeInfo(
"57" /* bike id*/,
new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new Bike("57", LockModel.Sigo), new Drive(),
"7" /*station id*/,
new TINK.Model.Bikes.Bike.CopriLock.LockInfo()),
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo()),
};
var stations = new List<IStation>
@ -171,7 +185,7 @@ namespace TestTINKLib
var bikeResponse = new List<BikeInfo>
{
new BikeInfo("57" /* bike id*/, LockModel.ILockIt, 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(new Bike("57" /* bike id*/, LockModel.ILockIt, WheelType.Trike, TypeOfBike.Allround, "Test description"), new Drive(), false, new List<string> {"TINK" }, "7" /*station id*/, null /*operator uri*/, null, DateTime.Now, "john@long,", "1234"),
};
var stations = new List<IStation>
@ -195,11 +209,11 @@ namespace TestTINKLib
var bikeResponse = new List<BikeInfo>
{
new TINK.Model.Bike.CopriLock.BikeInfo(
"57" /* bike id*/,
"7" /*station id*/,
new TINK.Model.Bikes.Bike.CopriLock.LockInfo(),
null /*operator uri*/),
new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(
new Bike("57", LockModel.Sigo), new Drive(),
"7" /*station id*/,
new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo(),
operatorUri: null /*operator uri*/),
};
bikeColl.Update(bikeResponse, null);
@ -224,7 +238,7 @@ namespace TestTINKLib
Assert.That(
BikeCollectionMutable.BikeInfoMutableFactory.Create(bikeInfo, "Stat1").GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.BluetoothLock.BikeInfoMutable)));
Is.EqualTo(typeof(TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfoMutable)));
}
[Test]
@ -242,7 +256,7 @@ namespace TestTINKLib
Assert.That(
BikeCollectionMutable.BikeInfoMutableFactory.Create(bikeInfo, "Stat1").GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.CopriLock.BikeInfoMutable)));
Is.EqualTo(typeof(TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfoMutable)));
}

View file

@ -1,7 +1,6 @@
using NUnit.Framework;
using System;
using TINK.Model.Bike;
using TINK.Model.Bikes.Bike;
using System;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
namespace TestShareeLib.Model.Bike
{
@ -14,7 +13,7 @@ namespace TestShareeLib.Model.Bike
Assert.That(LockModel.Sigo.GetLockType(), Is.EqualTo(LockType.Backend));
Assert.That(LockModel.ILockIt.GetLockType(), Is.EqualTo(LockType.Bluethooth));
Assert.That(
() => LockModel.BordComputer.GetLockType(),
() => LockModel.BordComputer.GetLockType(),
Throws.InstanceOf<ArgumentException>());
}

View file

@ -0,0 +1,49 @@
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
namespace TestShareeLib.Model.BikeInfo.DriveNS.BatteryNS
{
[TestFixture]
public class TestBattery
{
[Test]
public void TestSetCurrentChargePercent() => Assert.That(
new Battery.Builder { CurrentChargePercent = 20 }.Build().CurrentChargePercent,
Is.EqualTo(20.0));
[Test]
public void TestSetCurrentChargePercentOutOfRange() => Assert.That(
new Battery.Builder { CurrentChargePercent = 101 }.Build().CurrentChargePercent,
Is.NaN);
[Test]
public void TestSetCurrentChargeBars() => Assert.That(
new Battery.Builder { CurrentChargeBars = 21, MaxChargeBars = 22 }.Build().CurrentChargeBars,
Is.EqualTo(21));
[Test]
public void TestSetCurrentChargeBarsOutOfRange() => Assert.That(
new Battery.Builder { CurrentChargeBars = -1, MaxChargeBars = 22 }.Build().CurrentChargeBars,
Is.Null);
[Test]
public void TestSetMaxChargeBars() => Assert.That(
new Battery.Builder { MaxChargeBars = 23 }.Build().MaxChargeBars,
Is.EqualTo(23));
[Test]
public void TestSetMaxChargeBarsOutOfRange() => Assert.That(
new Battery.Builder { MaxChargeBars = -1 }.Build().MaxChargeBars,
Is.Null);
[Test]
public void TestSetCurrentChargeBarsNoMaxValueSet() => Assert.That(
new Battery.Builder { CurrentChargeBars = 21 }.Build().CurrentChargeBars,
Is.Null);
[Test]
public void TestSetCurrentChargeBars_CurrentValueTooLarge() => Assert.That(
new Battery.Builder { CurrentChargeBars = 25, MaxChargeBars = 22 }.Build().CurrentChargeBars,
Is.Null);
}
}

View file

@ -0,0 +1,49 @@
using NSubstitute;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS.EngineNS;
namespace TestShareeLib.Model.BikeInfo.DriveNS
{
[TestFixture]
public class TestDriveMutable
{
[Test]
public void TestCtorNoArgs()
{
var drive = new TINK.Model.Bikes.BikeInfoNS.DriveNS.Drive();
Assert.That(
drive.Type,
Is.EqualTo(DriveType.SoleHumanPowered));
Assert.That(
drive.Engine,
Is.Not.Null);
Assert.That(
drive.Battery,
Is.Not.Null);
}
[Test]
public void TestCtor()
{
var engine = Substitute.For<IEngine>();
var battery = Substitute.For<IBattery>();
engine.Manufacturer.Returns("Bosch");
battery.CurrentChargePercent.Returns(97);
var drive = new TINK.Model.Bikes.BikeInfoNS.DriveNS.Drive(engine, battery);
Assert.That(
drive.Engine.Manufacturer,
Is.EqualTo("Bosch"));
Assert.That(
drive.Battery.CurrentChargePercent,
Is.EqualTo(97));
}
}
}

View file

@ -1,6 +1,6 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using TINK.Model.Connector.Filter;
namespace TestShareeLib.Model.Connector.Filter
@ -52,7 +52,7 @@ namespace TestShareeLib.Model.Connector.Filter
public void TestIntersectByGoupId_Empty()
{
CollectionAssert.AreEqual(
new List<string> (),
new List<string>(),
new List<string> { "FR_300102" }.IntersectByGoupId(new List<string> { "FR_300101" }));
}

View file

@ -1,6 +1,6 @@
using Newtonsoft.Json;
using NUnit.Framework;
using TINK.Model.Connector;
using TINK.Model.Connector.Updater;
using TINK.Repository.Response;
namespace TestShareeLib.Model.Connector
@ -80,7 +80,7 @@ namespace TestShareeLib.Model.Connector
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse).GetType(),
Is.EqualTo( typeof(TINK.Model.Bike.CopriLock.BikeInfo)),
Is.EqualTo(typeof(TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo)),
"Default lock by is BackendLock.");
}
@ -99,7 +99,7 @@ namespace TestShareeLib.Model.Connector
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse).GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.BluetoothLock.BikeInfo)));
Is.EqualTo(typeof(TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo)));
}
[Test]
@ -117,7 +117,67 @@ namespace TestShareeLib.Model.Connector
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse).GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.CopriLock.BikeInfo)));
Is.EqualTo(typeof(TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo)));
}
[Test]
public void TestCreate_Available_CorpiLock_FeedbackPending()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoAvailable>(
@"{
""description"" : ""Cargo Long"",
""state"" : ""available"",
""bike"" : ""1"",
""gps"" : { ""latitude"": ""47.669888"", ""longitude"": ""9.167749"" },
""station"" : ""9"",
""system"" : ""SIGO"",
""co2saving"" : ""You saved tonns of co2!"",
""user_miniquery"" : {
""footer"" : ""Herzlichen Dank und viel Spaß bei der nächsten Fahrt!"",
""subtitle"" : ""Ihre drei Antworten werden anonym gespeichert."",
""title"" : ""Bitte unterstützen Sie unsere Begleitforschung"",
""questions"" : {
""q1"" : {
""quest_text"" : ""1. Was war der Hauptzweck dieser Ausleihe?"",
""type"" : ""check_one"",
""query"" : {
""opt5"" : ""e. Ausprobieren"",
""opt3"" : ""c. Lastentransport"",
""opt6"" : ""f. Sonstiges"",
""opt1"" : ""a. Einkauf"",
""opt4"" : ""d. Freizeit"",
""opt2"" : ""b. Kinderbeförderung""
}
},
""q2"" : {
""type"" : ""check_one"",
""quest_text"" : ""2. Welches Verkehrsmittel hätten Sie ansonsten benutzt?"",
""query"" : {
""opt1"" : ""a. Auto"",
""opt7"" : ""g. Sonstige"",
""opt2"" : ""b. Motorrad oder Motorroller"",
""opt4"" : ""d. Eigenes Fahrrad"",
""opt6"" : ""f. Keines (ich hätte die Fahrt sonst nicht gemacht)"",
""opt5"" : ""e. Zu Fuß"",
""opt3"" : ""c. Bus oder Bahn""
},
},
""q3"" : {
""type"" : ""text"",
""quest_text"" : ""3. Haben Sie Anmerkungen oder Anregungen?"",
""query"" : {
""opt1"" : """"
},
},
},
}
}");
var bike = BikeInfoFactory.Create(bikeInfoResponse) as TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo;
Assert.That(
bike,
Is.Not.Null);
}
[Test]
@ -156,7 +216,7 @@ namespace TestShareeLib.Model.Connector
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse, "a@b", () => new System.DateTime()).GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.CopriLock.BikeInfo)));
Is.EqualTo(typeof(TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo)));
}
[Test]
@ -175,7 +235,7 @@ namespace TestShareeLib.Model.Connector
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse, "a@b", () => new System.DateTime()).GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.BluetoothLock.BikeInfo)));
Is.EqualTo(typeof(TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo)));
}
@ -195,7 +255,72 @@ namespace TestShareeLib.Model.Connector
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse, "a@b", () => new System.DateTime()).GetType(),
Is.EqualTo(typeof(TINK.Model.Bike.CopriLock.BikeInfo)));
Is.EqualTo(typeof(TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo)));
}
[Test]
public void TestCreate_Available_CopriLock_FeedBackRequied()
{
var bikeInfoResponse = JsonConvert.DeserializeObject<BikeInfoAvailable>(
@"{
""rental_description"": {
""reserve_timerange"": ""30 Min"",
""name"": ""Lastenrad"",
""rental_info"": {
""2"": [
""AGB"",
""Mit der Mietrad Anmietung wird folgender Betreiber <a href='https://shareeapp-wue.copri.eu/site/agb.html' target='_blank'>AGB</a> zugestimmt (als Demo sharee AGB).""
],
""1"": [
""Tracking"",
""Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!""
]
},
""id"": ""5523"",
""tarif_elements"": {
""1"": [
""Mietgebühr"",
""3,00 / 1 Std ""
],
""6"": [
""Gratis Mietzeit"",
""30 Min / Tag""
],
""4"": [
""Max. Gebühr"",
""15.00 / Tag""
]
}
},
""uri_operator"": ""https://shareeapp-wue.copri.eu"",
""state"": ""available"",
""bike"": ""WUE5529"",
""authed"": ""1"",
""bike_group"": [
""WUE300101""
],
""gps"": {
""longitude"": null,
""latitude"": null
},
""system"": ""sigo"",
""tariff_description"": {
""free_hours"": ""0.50"",
""number"": ""5523"",
""max_eur_per_day"": ""15.00"",
""name"": ""Lastenrad"",
""eur_per_hour"": ""3.00""
},
""station"": ""WUE9301"",
""description"": ""sigolaster Bay"",
""lock_state"": ""locked"",
""co2saving"" : """"
}");
Assert.That(
BikeInfoFactory.Create(bikeInfoResponse)?.State?.Value,
Is.EqualTo(TINK.Model.State.InUseStateEnum.FeedbackPending),
"Bikes with state booking state available in ");
}
}
}

View file

@ -0,0 +1,298 @@
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using NSubstitute;
using NUnit.Framework;
using TINK.Model.Connector;
using TINK.Model.Services.CopriApi;
using TINK.Repository;
using TINK.Repository.Response;
using TINK.Services.CopriApi;
namespace TestShareeLib.Model.Connector
{
[TestFixture]
public class TestCachedQueryLoggedIn
{
/// <summary>
/// Verifies that available bikes are not considered to by kind of MyBikes.
/// </summary>
[Test]
public async Task TestGetBikesOccupiedAsyncMyBikesNone()
{
var server = Substitute.For<ICachedCopriServer>();
var bikesAvailable = JsonConvert.DeserializeObject<BikesAvailableResponse>(@"
{
""bikes"": {
""FR1005"": {
""system"": ""Sigo"",
""state"": ""available"",
""bike"": ""FR1005"",
""station"": ""REN0"",
}
},
""copri_version"": ""4.1.12.5"",
}");
var bikesOccupied = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(@"
{
""bikes_occupied"": { },
""copri_version"": ""4.1.12.5"",
}");
var resultAvailable = new Result<BikesAvailableResponse>(
typeof(CopriCallsHttps), // Marks that response was taken from cache
bikesAvailable,
new GeneralData());
var resultOccupied = new Result<BikesReservedOccupiedResponse>(
typeof(CopriCallsHttps),
bikesOccupied,
new GeneralData());
server.GetBikesAvailable(false).Returns(Task.FromResult(resultAvailable));
server.GetBikesOccupied(false).Returns(Task.FromResult(resultOccupied));
var query = new CachedQueryLoggedIn(
server,
"SessionCookie",
"Mail",
() => new DateTime(2022, 7, 16));
var bikesResponse = await query.GetBikesOccupiedAsync();
Assert.That(
bikesResponse.Response.Count,
Is.EqualTo(0));
}
/// <summary>
/// Verifies that available bikes with Co2Saving entry set are considered to by kind of MyBikes.
/// </summary>
[Test]
public async Task TestGetBikesOccupiedAsyncMyBikesOneFeedbackPending()
{
var server = Substitute.For<ICachedCopriServer>();
var bikesAvailable = JsonConvert.DeserializeObject<BikesAvailableResponse>(@"
{
""bikes"": {
""FR1005"": {
""system"": ""Sigo"",
""state"": ""available"",
""bike"": ""FR1005"",
""station"": ""REN0"",
""co2saving"" : """"
}
},
""copri_version"": ""4.1.12.5"",
}");
var bikesOccupied = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(@"
{
""bikes_occupied"": { },
""copri_version"": ""4.1.12.5"",
}");
var resultAvailable = new Result<BikesAvailableResponse>(
typeof(CopriCallsHttps),
bikesAvailable,
new GeneralData());
var resultOccupied = new Result<BikesReservedOccupiedResponse>(
typeof(CopriCallsHttps),
bikesOccupied,
new GeneralData());
server.GetBikesAvailable(false).Returns(Task.FromResult(resultAvailable));
server.GetBikesOccupied(false).Returns(Task.FromResult(resultOccupied));
var query = new CachedQueryLoggedIn(
server,
"SessionCookie",
"Mail",
() => new DateTime(2022, 7, 16));
var bikesResponse = await query.GetBikesOccupiedAsync();
Assert.That(
bikesResponse.Response.Count,
Is.EqualTo(1));
}
/// <summary>
/// .
/// </summary>
[Test]
public async Task TestGetBikesOccupiedAsyncMyBikesOneOccupied()
{
var server = Substitute.For<ICachedCopriServer>();
var bikesAvailable = JsonConvert.DeserializeObject<BikesAvailableResponse>(@"
{
""bikes"": { },
""copri_version"": ""4.1.12.5"",
}");
var bikesOccupied = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(@"
{
""bikes_occupied"": {
""FR1005"": {
""lock_state"": ""occupied"",
""system"": ""Sigo"",
""state"": ""occupied"",
""bike"": ""FR1005"",
""station"": ""REN0"",
}
},
""copri_version"": ""4.1.12.5"",
}");
var resultAvailable = new Result<BikesAvailableResponse>(
typeof(CopriCallsHttps),
bikesAvailable,
new GeneralData());
var resultOccupied = new Result<BikesReservedOccupiedResponse>(
typeof(CopriCallsHttps),
bikesOccupied,
new GeneralData());
server.GetBikesAvailable(false).Returns(Task.FromResult(resultAvailable)); // Get bikes from copri
server.GetBikesOccupied(false).Returns(Task.FromResult(resultOccupied)); // Get bikes from cache
var query = new CachedQueryLoggedIn(
server,
"SessionCookie",
"Mail",
() => new DateTime(2022, 7, 16));
var bikesResponse = await query.GetBikesOccupiedAsync();
Assert.That(
bikesResponse.Response.Count,
Is.EqualTo(1));
}
/// <summary>
/// Scenario: Call of GetBikesAvailable fails data is taken from cache.
/// </summary>
[Test]
public async Task TestGetBikesOccupiedAsyncGetAvailableFailsMyBikeOneFeedbackPending()
{
var server = Substitute.For<ICachedCopriServer>();
var bikesAvailable = JsonConvert.DeserializeObject<BikesAvailableResponse>(@"
{
""bikes"": {
""FR1005"": {
""system"": ""Sigo"",
""state"": ""available"",
""bike"": ""FR1005"",
""station"": ""REN0"",
""co2saving"" : """"
}
},
""copri_version"": ""4.1.12.5"",
}");
var bikesOccupied = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(@"
{
""bikes_occupied"": { },
""copri_version"": ""4.1.12.5"",
}");
var resultAvailable = new Result<BikesAvailableResponse>(
typeof(CopriCallsMonkeyStore),
bikesAvailable,
new GeneralData());
var resultOccupied = new Result<BikesReservedOccupiedResponse>(
typeof(CopriCallsMonkeyStore),
bikesOccupied,
new GeneralData());
server.GetBikesAvailable(false).Returns(Task.FromResult(resultAvailable));
server.GetBikesOccupied(true).Returns(Task.FromResult(resultOccupied));
var query = new CachedQueryLoggedIn(
server,
"SessionCookie",
"Mail",
() => new DateTime(2022, 7, 16));
var bikesResponse = await query.GetBikesOccupiedAsync();
Assert.That(
bikesResponse.Response.Count,
Is.EqualTo(1));
}
/// <summary>
/// Scenario: Call of GetBikesAvailable succeeds but because call of GetBikesOccupied fails data is taken from cache.
/// </summary>
[Test]
public async Task TestGetBikesOccupiedAsyncGetGetBikesOccupiedFailsMyBikeFeedbackPending()
{
var server = Substitute.For<ICachedCopriServer>();
var bikesAvailableCopri = JsonConvert.DeserializeObject<BikesAvailableResponse>(@"
{
""bikes"": { },
""copri_version"": ""4.1.12.5"",
}");
var bikesAvailableCache = JsonConvert.DeserializeObject<BikesAvailableResponse>(@"
{
""bikes"": {
""FR1005"": {
""system"": ""Sigo"",
""state"": ""available"",
""bike"": ""FR1005"",
""station"": ""REN0"",
""co2saving"" : """"
}
},
""copri_version"": ""4.1.12.5"",
}");
var bikesOccupied = JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(@"
{
""bikes_occupied"": { },
""copri_version"": ""4.1.12.5"",
}");
var resultAvailableCopri = new Result<BikesAvailableResponse>(
typeof(CopriCallsHttps), // Marks that response was taken from copri
bikesAvailableCache,
new GeneralData());
var resultAvailableCache = new Result<BikesAvailableResponse>(
typeof(CopriCallsMonkeyStore), // Marks that response was taken from cache
bikesAvailableCache,
new GeneralData());
var resultOccupied = new Result<BikesReservedOccupiedResponse>(
typeof(CopriCallsMonkeyStore),
bikesOccupied,
new GeneralData());
server.GetBikesAvailable(false).Returns(Task.FromResult(resultAvailableCopri)); // Get bikes from copri
server.GetBikesOccupied(false).Returns(Task.FromResult(resultOccupied)); // Get bikes from copri fails
server.GetBikesAvailable(true).Returns(Task.FromResult(resultAvailableCache)); // Get bikes from cache
var query = new CachedQueryLoggedIn(
server,
"SessionCookie",
"Mail",
() => new DateTime(2022, 7, 16));
var bikesResponse = await query.GetBikesOccupiedAsync();
Assert.That(
bikesResponse.Response.Count,
Is.EqualTo(1));
}
}
}

View file

@ -1,7 +1,7 @@
using MonkeyCache.FileStore;
using System;
using MonkeyCache.FileStore;
using NUnit.Framework;
using Serilog;
using System;
using TINK.Model.Connector;
using TINK.Model.Services.CopriApi.ServerUris;
using TINK.Repository;
@ -32,7 +32,7 @@ namespace TestTINKLib.Fixtures.Misc
{
Barrel.ApplicationId = GetType().Name + nameof(TestCachedQuery_GetStationsAll);
Log .Logger = new LoggerConfiguration()
Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(new Serilog.Core.LoggingLevelSwitch(Serilog.Events.LogEventLevel.Error))
.WriteTo.Debug()
.CreateLogger();
@ -41,6 +41,7 @@ namespace TestTINKLib.Fixtures.Misc
true, // Is connected
new Uri(url),
new AppContextInfo("oiF2kahH" + nameof(TestCachedQuery_GetStationsAll), "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
cookieAndMail.Split(';')[0],
cookieAndMail.Split(';')[1],
TimeSpan.FromSeconds(3)); // See task #97 for need of custom expiresAfter value.
@ -92,6 +93,7 @@ namespace TestTINKLib.Fixtures.Misc
true, // Is connected
new Uri(url),
new AppContextInfo("oiF2kahH" + nameof(TestCachedQuery_GetBikes), "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
cookieAndMail.Split(';')[0],
cookieAndMail.Split(';')[1],
TimeSpan.FromSeconds(3)); // See task #97 for need of custom expiresAfter value.
@ -139,6 +141,7 @@ namespace TestTINKLib.Fixtures.Misc
true, // Is connected
new Uri(url),
new AppContextInfo("oiF2kahH" + nameof(TestCachedQuery_GetBikesOccupied), "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
cookieAndMail.Split(';')[0],
cookieAndMail.Split(';')[1],
TimeSpan.FromSeconds(3)); // See task #97 for need of custom expiresAfter value.

View file

@ -1,10 +1,6 @@
using MonkeyCache.FileStore;
using System;
using MonkeyCache.FileStore;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TINK.Model.Connector;
using TINK.Repository;
@ -21,10 +17,10 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
Barrel.ApplicationId = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
}
var connector = ConnectorFactory.Create(false, new Uri("https://1.2.3.4"), new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)), "123456789", "a@b");
var connector = ConnectorFactory.Create(false, new Uri("https://1.2.3.4"), new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)), null /*UI language */, "123456789", "a@b");
Assert.AreEqual(typeof(ConnectorCache), connector.GetType());
connector = ConnectorFactory.Create(true, new Uri("https://1.2.3.4"), new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)), "123456789", "a@b");
connector = ConnectorFactory.Create(true, new Uri("https://1.2.3.4"), new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)), null /*UI language */, "123456789", "a@b");
Assert.AreEqual(typeof(TINK.Model.Connector.Connector), connector.GetType());
}
}

View file

@ -1,9 +1,9 @@
using MonkeyCache.FileStore;
using System;
using System.Threading.Tasks;
using MonkeyCache.FileStore;
using Newtonsoft.Json;
using NSubstitute;
using NUnit.Framework;
using System;
using System.Threading.Tasks;
using TINK.Model.Services.CopriApi;
using TINK.Repository;
using TINK.Repository.Exception;
@ -110,7 +110,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
public async Task TestGetBikesAvailable_NotExpired()
{
var cache = Substitute.For<ICopriCache>();
var https = Substitute.For<ICopriServer >();
var https = Substitute.For<ICopriServer>();
cache.IsBikesAvailableExpired.Returns(false);
cache.GetBikesAvailableAsync().Returns(Task.Run(() => JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE)));
@ -119,6 +119,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
new Uri("http://1.2.3.4"),
"123", // Merchant id
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)), // User agent
null /*UI language */,
"456", // cookie
cacheServer: cache,
httpsServer: https);
@ -130,7 +131,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
Assert.IsNull(bikes.Exception);
}
[Test]
public async Task TestGetBikesAvailable_ExpiredForceCache()
{
@ -144,6 +145,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
new Uri("http://1.2.3.4"),
"123",
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
cacheServer: cache,
httpsServer: https);
@ -167,6 +169,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
new Uri("http://1.2.3.4"),
"123",
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
cacheServer: cache,
httpsServer: https);
@ -191,6 +194,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
new Uri("http://1.2.3.4"),
"123",
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
cacheServer: cache,
httpsServer: https);
@ -214,6 +218,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
new Uri("http://1.2.3.4"),
"12345678", // Merchant id
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)), // User agent
null /*UI language */,
"f782a208d9399291ba8d086b5dcc2509", // Auth cookie
cacheServer: cache,
httpsServer: https);
@ -238,6 +243,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
new Uri("http://1.2.3.4"),
"12345678", // Merchant id
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)), // User agent
null /*UI language */,
"f782a208d9399291ba8d086b5dcc2509", // Auth cookie
cacheServer: cache,
httpsServer: https);
@ -262,6 +268,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
new Uri("http://1.2.3.4"),
"12345678", // Merchant id
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)), // User agent
null /*UI language */,
"f782a208d9399291ba8d086b5dcc2509", // Auth cookie
cacheServer: cache,
httpsServer: https);
@ -287,6 +294,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
new Uri("http://1.2.3.4"),
"12345678", // Merchant id
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)), // User agent
null /*UI language */,
"f782a208d9399291ba8d086b5dcc2509", // Auth cookie
cacheServer: cache,
httpsServer: https);
@ -311,6 +319,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
new Uri("http://1.2.3.4"),
"123", // Merchant id
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)), // User agent
null /*UI language */,
"456", // cookie
cacheServer: cache,
httpsServer: https);
@ -335,6 +344,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
new Uri("http://1.2.3.4"),
"123",
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
cacheServer: cache,
httpsServer: https);
@ -358,6 +368,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
new Uri("http://1.2.3.4"),
"123",
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
cacheServer: cache,
httpsServer: https);
@ -382,6 +393,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
new Uri("http://1.2.3.4"),
"123",
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */,
cacheServer: cache,
httpsServer: https);
@ -403,7 +415,8 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
var provider = new CopriProviderHttps(
new Uri("http://1.2.3.4"),
"123456789",
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)));
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */);
var stations = await provider.GetStations(true);
Assert.AreEqual(0, stations.Response.stations.Count);
@ -442,7 +455,8 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
var provider = new CopriProviderHttps(
new Uri("http://1.2.3.4"),
"123456789",
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)));
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
null /*UI language */);
var bikes = await provider.GetBikesAvailable(true);
Assert.AreEqual(0, bikes.Response.bikes.Count);
@ -483,6 +497,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.Connector
new Uri("http://1.2.3.4"),
"123456789",
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)), // User agent
null /* langugage */,
"876");
var bikes = await provider.GetBikesOccupied(true);

View file

@ -1,8 +1,8 @@
using Newtonsoft.Json;
using NUnit.Framework;
using System;
using System;
using System.Linq;
using TINK.Model.Bike;
using Newtonsoft.Json;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Connector;
using TINK.Repository.Exception;
using TINK.Repository.Response;
@ -34,6 +34,10 @@ namespace TestTINKLib.Fixtures.Connector
""bike"" : ""2"",
""bike_group"" : [ ""TINK"" ],
""description"" : ""Cargo Long"",
""bike_type"": {
""category"": ""cargo"",
""wheels"": ""2""
},
""gps"" : { ""latitude"": ""47.6612083333"", ""longitude"": ""9.16637533333"" },
""station"" : ""9"",
""state"" : ""available""
@ -47,6 +51,10 @@ namespace TestTINKLib.Fixtures.Connector
""bike"" : ""11"",
""bike_group"" : [ ""TINK"" ],
""description"" : ""Cargo Trike"",
""bike_type"": {
""category"": ""cargo"",
""wheels"": ""3""
},
""gps"" : { ""latitude"": ""47.665051"", ""longitude"": ""9.174096"" },
""station"" : ""1"",
""state"" : ""available""
@ -66,7 +74,7 @@ namespace TestTINKLib.Fixtures.Connector
}");
// Verify behaviour of member.
Assert.AreEqual(WheelType.Two, TextToTypeHelper.GetWheelType(l_oInfo));
Assert.That(TextToTypeHelper.GetWheelType(l_oInfo), Is.Null); // Was WheelType.Two up to 3.0.322
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
{
@ -79,7 +87,7 @@ namespace TestTINKLib.Fixtures.Connector
}");
// Verify behaviour of member.
Assert.AreEqual(WheelType.Two, TextToTypeHelper.GetWheelType(l_oInfo));
Assert.That(TextToTypeHelper.GetWheelType(l_oInfo), Is.Null); // Was WheelType.Two up to 3.0.322
}
[Test]
@ -97,69 +105,132 @@ namespace TestTINKLib.Fixtures.Connector
[Test]
public void TestGetTypeOfBike()
{
var l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
var info = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
{
""bike"" : ""2"",
""bike_group"" : [ ""TINK"" ],
""description"" : ""Cargo Long"",
""bike_type"": {
""category"": ""cargo"",
""wheels"": ""2""
},
""gps"" : { ""latitude"": ""47.6612083333"", ""longitude"": ""9.16637533333"" },
""station"" : ""9"",
""state"" : ""available""
}");
// Verify behaviour of member.
Assert.AreEqual(TypeOfBike.Cargo, TextToTypeHelper.GetTypeOfBike(l_oInfo));
Assert.AreEqual(TypeOfBike.Cargo, TextToTypeHelper.GetTypeOfBike(info));
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
info = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
{
""bike"" : ""11"",
""bike_group"" : [ ""TINK"" ],
""description"" : ""Cargo Trike"",
""bike_type"": {
""category"": ""cargo"",
""wheels"": ""2""
},
""gps"" : { ""latitude"": ""47.665051"", ""longitude"": ""9.174096"" },
""station"" : ""1"",
""state"" : ""available""
}");
// Verify behaviour of member.
Assert.AreEqual(TypeOfBike.Cargo, TextToTypeHelper.GetTypeOfBike(l_oInfo));
Assert.AreEqual(TypeOfBike.Cargo, TextToTypeHelper.GetTypeOfBike(info));
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
info = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
{
""bike"" : ""51"",
""bike_group"" : [ ""Konrad"" ],
""description"" : ""Demo Stadtrad"",
""bike_type"": {
""category"": ""city"",
""wheels"": ""2""
},
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
""station"" : ""8"",
""state"" : ""available""
}");
// Verify behaviour of member.
Assert.AreEqual(TypeOfBike.Citybike, TextToTypeHelper.GetTypeOfBike(l_oInfo));
Assert.AreEqual(TypeOfBike.City, TextToTypeHelper.GetTypeOfBike(info));
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
info = JsonConvertRethrow.DeserializeObject<BikeInfoBase>(@"
{
""bike"" : ""51"",
""bike_group"" : [ ""Konrad"" ],
""description"" : ""Stadtrad"",
""bike_type"": {
},
""gps"" : { ""latitude"": ""47.657766"", ""longitude"": ""9.176094"" },
""station"" : ""8"",
""state"" : ""available""
}");
// Verify behaviour of member.
Assert.AreEqual(TypeOfBike.Citybike, TextToTypeHelper.GetTypeOfBike(l_oInfo));
Assert.That(
TextToTypeHelper.GetTypeOfBike(info),
Is.Null); // Version up to 3.0.322 considered this bike to be a city bike to to description "Stadtrad"
}
[Test]
public void TestGetStateAvailable()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"available\" }").GetState(),
Is.EqualTo(TINK.Model.State.InUseStateEnum.Disposable));
[Test]
public void TestGetStateAvailableCase()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"availablE \" }").GetState(),
Is.EqualTo(TINK.Model.State.InUseStateEnum.Disposable));
[Test]
public void TestGetStateReserved()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"requested\" }").GetState(),
Is.EqualTo(TINK.Model.State.InUseStateEnum.Reserved));
[Test]
public void TestGetStateReservedCase()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \" reQuested\" }").GetState(),
Is.EqualTo(TINK.Model.State.InUseStateEnum.Reserved));
[Test]
public void TestGetStateOccupied()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"occupied\" }").GetState(),
Is.EqualTo(TINK.Model.State.InUseStateEnum.Booked));
[Test]
public void TestGetStateOccupiedCase()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"state\" : \"occuPied\" }").GetState(),
Is.EqualTo(TINK.Model.State.InUseStateEnum.Booked));
[Test]
public void TestGetStateBikeInfoAvailableDisposable()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ \"state\" : \"available\" }").GetState(),
Is.EqualTo(TINK.Model.State.InUseStateEnum.Disposable));
[Test]
public void TestGetStateBikeInfoAvailableFeedbackPending()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ \"state\" : \"available\", \"co2saving\" : \"\" }").GetState(),
Is.EqualTo(TINK.Model.State.InUseStateEnum.FeedbackPending));
[Test]
public void TestGetState_InvalidDescription()
{
var l_oInfo = new BikeInfoBase();
var info = new BikeInfoBase();
// Verify prerequisites
Assert.IsNull(l_oInfo.state);
Assert.IsNull(info.state);
// Verify behaviour of member.
Assert.Throws<InvalidResponseException<BikeInfoBase>>(() => TextToTypeHelper.GetState(l_oInfo));
Assert.Throws<InvalidResponseException<BikeInfoBase>>(() => TextToTypeHelper.GetState(info));
}
[Test]
@ -445,7 +516,7 @@ namespace TestTINKLib.Fixtures.Connector
[Test]
public void TestGetGroupString_Roundtrip()
{
Assert.AreEqual("Tunk,Unk", TextToTypeHelper.GetGroup(TextToTypeHelper.GetGroup(new [] { "Tunk", "Unk" })));
Assert.AreEqual("Tunk,Unk", TextToTypeHelper.GetGroup(TextToTypeHelper.GetGroup(new[] { "Tunk", "Unk" })));
}
[Test]
@ -592,7 +663,7 @@ namespace TestTINKLib.Fixtures.Connector
{
}");
Assert.AreEqual(0, TextToTypeHelper.GetBluetoothLockId (l_oInfo));
Assert.AreEqual(0, TextToTypeHelper.GetBluetoothLockId(l_oInfo));
l_oInfo = JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
{
@ -643,10 +714,10 @@ namespace TestTINKLib.Fixtures.Connector
{
""copri_version"": ""4.3.2.1""
}");
Assert.That(
version.GetCopriVersion(),
Is.EqualTo(new Version(4,3,2,1)));
Is.EqualTo(new Version(4, 3, 2, 1)));
}
[Test]
@ -819,7 +890,7 @@ namespace TestTINKLib.Fixtures.Connector
Assert.That(
TextToTypeHelper.GetCopriLockingState(response),
Is.EqualTo(TINK.Model.Bikes.Bike.CopriLock.LockingState.Closed));
Is.EqualTo(TINK.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Closed));
}
[Test]
@ -838,7 +909,7 @@ namespace TestTINKLib.Fixtures.Connector
Assert.That(
TextToTypeHelper.GetCopriLockingState(response),
Is.EqualTo(TINK.Model.Bikes.Bike.CopriLock.LockingState.Closing));
Is.EqualTo(TINK.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Closing));
}
[Test]
@ -857,7 +928,7 @@ namespace TestTINKLib.Fixtures.Connector
Assert.That(
TextToTypeHelper.GetCopriLockingState(response),
Is.EqualTo(TINK.Model.Bikes.Bike.CopriLock.LockingState.Open));
Is.EqualTo(TINK.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Open));
}
[Test]
@ -876,7 +947,84 @@ namespace TestTINKLib.Fixtures.Connector
Assert.That(
TextToTypeHelper.GetCopriLockingState(response),
Is.EqualTo(TINK.Model.Bikes.Bike.CopriLock.LockingState.Opening));
Is.EqualTo(TINK.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Opening));
}
[Test]
public void TestGetIsFeedbackPendingIsPendingValue()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ \"co2saving\" : \"Tonns\" }").GetIsFeedbackPending(),
Is.True);
[Test]
public void TestGetIsFeedbackPendingIsPending()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ \"co2saving\" : \"\" }").GetIsFeedbackPending(),
Is.True);
[Test]
public void TestGetIsFeedbackPendingNot()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoAvailable>("{ }").GetIsFeedbackPending(),
Is.False);
[Test]
public void TestGetTypeOfBikeCity()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"category\" : \"city\" } }").GetTypeOfBike(),
Is.EqualTo(TypeOfBike.City));
[Test]
public void TestGetTypeOfBikeCargo()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"category\" : \"cargo\" } }").GetTypeOfBike(),
Is.EqualTo(TypeOfBike.Cargo));
[Test]
public void TestGetTypeOfBikeNull()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { } }").GetTypeOfBike(),
Is.Null);
[Test]
public void TestGetWheelTypeTrike()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"wheels\" : \"3\" } }").GetWheelType(),
Is.EqualTo(WheelType.Trike));
[Test]
public void TestGetWheelTypeQuad()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"wheels\" : \"4\" } }").GetWheelType(),
Is.EqualTo(WheelType.Quad));
[Test]
public void TestGetWheelTypeTow()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { \"wheels\" : \"2\" } }").GetWheelType(),
Is.EqualTo(WheelType.Two));
[Test]
public void TestGetWheelTypeNull()
=> Assert.That(
JsonConvert.DeserializeObject<BikeInfoBase>("{ \"bike_type\" : { } }").GetWheelType(),
Is.Null);
[Test]
public void TestGetFrom()
=> Assert.That(
JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
{
""start_time"" : ""2022-7-16"",
}").GetFrom(),
Is.EqualTo(new DateTime(2022, 7, 16)));
[Test]
public void TestGetFromInvalid()
=> Assert.That(
JsonConvertRethrow.DeserializeObject<BikeInfoReservedOrBooked>(@"
{
}").GetFrom(),
Is.EqualTo(DateTime.MinValue));
}
}
}

View file

@ -0,0 +1,259 @@
using Newtonsoft.Json;
using NUnit.Framework;
using TINK.Model.Connector.Updater;
using TINK.Repository.Response;
namespace TestShareeLib.Model.Connector.Updater
{
[TestFixture]
public class TestBookingFinishedModelFactory
{
/// <summary>
/// COPRI response shortened, part not belonging to user_miniquery discarded.
/// </summary>
[Test]
public void TestCreateMiniSurvey_Co2Saving()
{
var response = JsonConvert.DeserializeObject<ResponseContainer<DoReturnResponse>>(@"
{
""shareejson"" : {
""co2saving"" : ""Einsparung: 1,95 kg CO2 und 3,00 EUR bei einer Strecke von 10 KM""
}
}");
var bookingFinshed = response.shareejson.Create();
Assert.That(
bookingFinshed.Co2Saving,
Is.EqualTo("Einsparung: 1,95 kg CO2 und 3,00 EUR bei einer Strecke von 10 KM"));
}
/// <summary>
/// COPRI response shortened, part not belonging to user_miniquery discarded.
/// </summary>
[Test]
public void TestCreateMiniSurvey()
{
var response = JsonConvert.DeserializeObject<ResponseContainer<DoReturnResponse>>(@"
{
""shareejson"" : {
""user_miniquery"" : {
""title"" : ""Bitte unterstützen Sie unsere Begleitforschung"",
""footer"" : ""Herzlichen Dank und viel Spaß bei der nächsten Fahrt!"",
""questions"" : {
""q3"" : {
""quest_text"" : ""3. Haben Sie Anmerkungen oder Anregungen?"",
""type"" : ""text"",
""query"" : {
""opt1"" : """"
}
},
""q1"" : {
""type"" : ""check_one"",
""quest_text"" : ""1. Was war der Hauptzweck dieser Ausleihe?"",
""query"" : {
""opt2"" : ""b. Kinderbeförderung"",
""opt5"" : ""e. Ausprobieren"",
""opt4"" : ""d. Freizeit"",
""opt1"" : ""a. Einkauf"",
""opt3"" : ""c. Lastentransport"",
""opt6"" : ""f. Sonstiges""
}
},
""q2"" : {
""type"" : ""check_one"",
""quest_text"" : ""2. Welches Verkehrsmittel hätten Sie ansonsten benutzt?"",
""query"" : {
""opt6"" : ""f. Keines (ich hätte die Fahrt sonst nicht gemacht)"",
""opt3"" : ""c. Bus oder Bahn"",
""opt1"" : ""a. Auto"",
""opt2"" : ""b. Motorrad oder Motorroller"",
""opt7"" : ""g. Sonstige"",
""opt4"" : ""d. Eigenes Fahrrad"",
""opt5"" : ""e. Zu Fuß""
}
}
},
""subtitle"" : ""Ihre drei Antworten werden anonym gespeichert.""
},
}
}
");
var bookingFinished = response.shareejson.Create();
Assert.That(
bookingFinished,
Is.Not.Null);
Assert.That(
bookingFinished.MiniSurvey.Title,
Is.EqualTo("Bitte unterstützen Sie unsere Begleitforschung"));
Assert.That(
bookingFinished.MiniSurvey.Subtitle,
Is.EqualTo("Ihre drei Antworten werden anonym gespeichert."));
Assert.That(
bookingFinished.MiniSurvey.Footer,
Is.EqualTo("Herzlichen Dank und viel Spaß bei der nächsten Fahrt!"));
Assert.That(
bookingFinished.MiniSurvey.Questions.Count,
Is.EqualTo(3));
}
/// <summary>
/// COPRI response shortened, part not belonging to user_miniquery discarded.
/// </summary>
[Test]
public void TestCreateMiniSurvey_Null()
{
var response = JsonConvert.DeserializeObject<ResponseContainer<DoReturnResponse>>(@"
{
""shareejson"" : {
}
}
");
var bookingFinshed = response.shareejson.Create();
Assert.That(
bookingFinshed,
Is.Not.Null);
Assert.That(
bookingFinshed.MiniSurvey.Questions.Count,
Is.EqualTo(0));
Assert.That(
bookingFinshed.MiniSurvey.Title,
Is.Null);
Assert.That(
bookingFinshed.MiniSurvey.Subtitle,
Is.Null);
Assert.That(
bookingFinshed.MiniSurvey.Footer,
Is.Null);
}
/// <summary>
/// COPRI response shortened, part not belonging to user_miniquery discarded.
/// </summary>
[Test]
public void TestCreateMiniSurvey_EmptyQuery()
{
var response = JsonConvert.DeserializeObject<ResponseContainer<DoReturnResponse>>(@"
{
""shareejson"" : {
""user_miniquery"" : {
},
}
}
");
var bookingFinished = response.shareejson.Create();
Assert.That(
bookingFinished,
Is.Not.Null);
Assert.That(
bookingFinished.MiniSurvey.Title,
Is.Null);
Assert.That(
bookingFinished.MiniSurvey.Subtitle,
Is.Null);
Assert.That(
bookingFinished.MiniSurvey.Footer,
Is.Null);
}
/// <summary>
/// COPRI response shortened, part not belonging to user_miniquery discarded.
/// </summary>
[Test]
public void TestCreateMiniSurvey_InvalidQuestion_KeyNull()
{
var response = JsonConvert.DeserializeObject<ResponseContainer<DoReturnResponse>>(@"
{
""shareejson"" : {
""user_miniquery"" : {
""title"" : ""Bitte unterstützen Sie unsere Begleitforschung"",
""footer"" : ""Herzlichen Dank und viel Spaß bei der nächsten Fahrt!"",
""questions"" : {
"""" : {
""type"" : ""check_one"",
""quest_text"" : ""1. Was war der Hauptzweck dieser Ausleihe?"",
""query"" : {
""opt2"" : ""b. Kinderbeförderung"",
""opt5"" : ""e. Ausprobieren"",
""opt4"" : ""d. Freizeit"",
""opt1"" : ""a. Einkauf"",
""opt3"" : ""c. Lastentransport"",
""opt6"" : ""f. Sonstiges""
}
},
},
""subtitle"" : ""Ihre drei Antworten werden anonym gespeichert.""
},
}
}
");
var bookingFinised = response.shareejson.Create();
Assert.That(
bookingFinised,
Is.Not.Null);
Assert.That(
bookingFinised.MiniSurvey.Questions.Count,
Is.EqualTo(0));
}
/// <summary>
/// COPRI response shortened, part not belonging to user_miniquery discarded.
/// </summary>
[Test]
public void TestCreateMiniSurvey_InvalidQuestion_ValueNull()
{
var response = JsonConvert.DeserializeObject<ResponseContainer<DoReturnResponse>>(@"
{
""shareejson"" : {
""user_miniquery"" : {
""title"" : ""Bitte unterstützen Sie unsere Begleitforschung"",
""footer"" : ""Herzlichen Dank und viel Spaß bei der nächsten Fahrt!"",
""questions"" : {
""q1"" : {
},
},
""subtitle"" : ""Ihre drei Antworten werden anonym gespeichert.""
},
}
}
");
var bookingFinished = response.shareejson.Create();
Assert.That(
bookingFinished,
Is.Not.Null);
Assert.That(
bookingFinished.MiniSurvey.Questions.Count,
Is.EqualTo(0));
}
}
}

View file

@ -0,0 +1,208 @@
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);
}
}
}

View file

@ -0,0 +1,200 @@
using Newtonsoft.Json;
using NUnit.Framework;
using TINK.Model.Connector.Updater;
using TINK.Repository.Response;
namespace TestShareeLib.Model.Connector.Updater
{
[TestFixture]
public class TestRentalDescription
{
[Test]
public void TestCreateRentalDescriptionEmpyJson()
{
var response = JsonConvert.DeserializeObject<RentalDescription>(@"");
Assert.That(
response.Create().Name,
Is.Empty);
Assert.That(
response.Create().TariffEntries.Count,
Is.EqualTo(0));
Assert.That(
response.Create().InfoEntries.Count,
Is.EqualTo(0));
}
[Test]
public void TestCreateRentalDescription()
{
var response = JsonConvertRethrow.DeserializeObject<RentalDescription>(
@"{
""id"": ""1"",
""tarif_elements"" : {
""6"": [
""Gratis Mietzeit"",
""30 Min / Tag""
],
""1"": [
""Mietgebühr"",
""2,00 / 1 Std""
],
""4"": [
""Max. Gebühr"",
""40.00 / Tag""
]
},
""name"": ""REN E-Bike"",
""rental_info"" : {
""9"" : [
""AGB"",
""Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt""
],
""8"" : [
""Tracking"",
""Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!""
]
}
}");
Assert.That(
response.Create().Name,
Is.EqualTo("REN E-Bike"));
Assert.That(
response.Create().Id,
Is.EqualTo(1));
Assert.That(
response.Create().TariffEntries.Count,
Is.EqualTo(3));
Assert.That(
response.Create().InfoEntries.Count,
Is.EqualTo(2));
Assert.That(
response.Create().TariffEntries["1"].Description,
Is.EqualTo("Mietgebühr"));
Assert.That(
response.Create().TariffEntries["1"].Value,
Is.EqualTo("2,00 € / 1 Std"));
Assert.That(
response.Create().TariffEntries["4"].Description,
Is.EqualTo("Max. Gebühr"));
Assert.That(
response.Create().TariffEntries["4"].Value,
Is.EqualTo("40.00 € / Tag"));
Assert.That(
response.Create().TariffEntries["6"].Description,
Is.EqualTo("Gratis Mietzeit"));
Assert.That(
response.Create().TariffEntries["6"].Value,
Is.EqualTo("30 Min / Tag"));
Assert.That(
response.Create().InfoEntries["8"].Key,
Is.EqualTo("Tracking"));
Assert.That(
response.Create().InfoEntries["8"].Value,
Is.EqualTo("Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!"));
Assert.That(
response.Create().InfoEntries["9"].Key,
Is.EqualTo("AGB"));
Assert.That(
response.Create().InfoEntries["9"].Value,
Is.EqualTo("Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt"));
}
[Test]
public void TestCreateRentalDescriptionDupeTarifElements()
{
var response = JsonConvertRethrow.DeserializeObject<RentalDescription>(
@"{
""id"": ""1"",
""tarif_elements"" : {
""6"": [
""Gratis Mietzeit"",
""30 Min / Tag""
],
""6"": [
""Mietgebühr"",
""2,00 / 1 Std""
],
""4"": [
""Max. Gebühr"",
""40.00 / Tag""
]
}
}");
Assert.That(
response.Create().TariffEntries.Count,
Is.EqualTo(2));
}
[Test]
public void TestCreateRentalDescriptionDupeInfoElements()
{
var response = JsonConvertRethrow.DeserializeObject<RentalDescription>(
@"{
""rental_info"" : {
""9"" : [
""AGB"",
""Mit der Mietrad Anmietung wird folgender Betreiber <a href='$varenv->{wwwhost}/site/agb.html' target='_blank'>AGB</a> zugestimmt""
],
""9"" : [
""Tracking"",
""Ich stimme der Speicherung (Tracking) meiner Fahrstrecke zwecks wissenschaftlicher Auswertung und Berechnung der CO2-Einsparung zu!""
]
}
}");
Assert.That(
response.Create().InfoEntries.Count,
Is.EqualTo(1));
}
[Test]
public void TestCreateRentalDescriptionsNoTariffElements()
{
var response = JsonConvertRethrow.DeserializeObject<RentalDescription>(
@"{
""rental_info"" : {
}
}");
Assert.That(
response.Create().TariffEntries,
Is.Not.Null);
}
[Test]
public void TestCreateRentalDescriptionsNoInfoElements()
{
var response = JsonConvertRethrow.DeserializeObject<RentalDescription>(
@"{
""rental_info"" : {
}
}");
Assert.That(
response.Create().InfoEntries,
Is.Not.Null);
}
}
}

View file

@ -0,0 +1,224 @@
using NUnit.Framework;
using TINK.Model.Connector.Updater;
using TINK.Repository.Response;
namespace TestShareeLib.Model.Connector.Updater
{
[TestFixture]
public class TestTariffDescriptionFactory
{
[Test]
public void TestCreateTariffDescription()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
@"{
""eur_per_hour"" : ""10.50"",
""abo_eur_per_month"" : ""920.99"",
""free_hours"" : ""1.50"",
""number"" : ""5494"",
""name"" : ""Tester Basic""
}");
Assert.That(
tariffDescription.Create().Name,
Is.EqualTo("Tester Basic"));
Assert.That(
tariffDescription.Create().Id,
Is.EqualTo(5494));
Assert.That(
tariffDescription.Create().TariffEntries["1"].Value, // Free time per session
Is.EqualTo("1.50 hour(s)/day")); // Did not contain unit before switching signature from TariffDescription to TariffDescription2.
Assert.That(
tariffDescription.Create().TariffEntries["2"].Value, // FeeEuroPerHour
Is.EqualTo("10.50 €/hour")); // Did not contain unit before switching signature from TariffDescription to TariffDescription2.
Assert.That(
tariffDescription.Create().TariffEntries["4"].Value, // Abo euro per month
Is.EqualTo("920.99 €/month"));
}
[Test]
public void TestCreateTariffDescription_Name()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
@"{
""eur_per_hour"" : ""10.50"",
""abo_eur_per_month"" : ""920.99"",
""free_hours"" : ""1.50"",
""number"" : ""5494"",
""name"" : ""Tester Basic""
}");
Assert.That(
tariffDescription.Create().Name,
Is.EqualTo("Tester Basic"));
}
[Test]
public void TestCreateTariffDescription_Number()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
@"{
""eur_per_hour"" : ""10.50"",
""abo_eur_per_month"" : ""920.99"",
""free_hours"" : ""1.50"",
""number"" : ""5494"",
""name"" : ""Tester Basic""
}");
Assert.That(
tariffDescription.Create().Id,
Is.EqualTo(5494));
}
[Test]
public void TestCreateTariffDescription_FreeTimePerSession()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
@"{
""eur_per_hour"" : ""10.50"",
""abo_eur_per_month"" : ""920.99"",
""free_hours"" : ""1.50"",
""number"" : ""5494"",
""name"" : ""Tester Basic""
}");
Assert.That(
tariffDescription.Create().TariffEntries["1"].Value, // Free time per session
Is.EqualTo("1.50 hour(s)/day")); // Did not contain unit before switching signature from TariffDescription to TariffDescription2.
}
[Test]
public void TestCreateTariffDescription_FeeEuroPerHour()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
@"{
""eur_per_hour"" : ""10.50"",
""abo_eur_per_month"" : ""920.99"",
""free_hours"" : ""1.50"",
""number"" : ""5494"",
""name"" : ""Tester Basic""
}");
Assert.That(
tariffDescription.Create().TariffEntries["2"].Value, // FeeEuroPerHour
Is.EqualTo("10.50 €/hour")); // Did not contain unit before switching signature from TariffDescription to TariffDescription2.
}
[Test]
public void TestCreateTariffDescription_AboEuroPerMonth()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
@"{
""eur_per_hour"" : ""10.50"",
""abo_eur_per_month"" : ""920.99"",
""free_hours"" : ""1.50"",
""number"" : ""5494"",
""name"" : ""Tester Basic""
}");
Assert.That(
tariffDescription.Create().TariffEntries["4"].Value, // Abo euro per month
Is.EqualTo("920.99 €/month"));
}
[Test]
public void TestCreateTariffDescription_Name_Empty()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
@"{}");
Assert.That(
tariffDescription.Create().Name,
Is.Null);
}
[Test]
public void TestCreateTariffDescription_Number_Empty()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
@"{}");
Assert.That(
tariffDescription.Create().Id,
Is.Null);
}
[Test]
public void TestCreateTariffDescription_FreeTimePerSession_Empty()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
@"{}");
Assert.That(
tariffDescription.Create().TariffEntries.ContainsKey("1"), // Free time per session
Is.False);
}
[Test]
public void TestCreateTariffDescription_FeeEuroPerHour_Empty()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
@"{}");
Assert.That(
tariffDescription.Create().TariffEntries.ContainsKey("2"), // FeeEuroPerHour
Is.False);
}
[Test]
public void TestCreateTariffDescription_AboEuroPerMonth_Empty()
{
var tariffDescription = JsonConvertRethrow.DeserializeObject<TariffDescription>(
@"{}");
Assert.That(
tariffDescription.Create().TariffEntries.ContainsKey("4"), // Abo euro per month
Is.False);
}
[Test]
public void TestCreateTariffDescription_Name_Null()
{
Assert.That(
TariffDescriptionFactory.Create(null).Name,
Is.Null);
}
[Test]
public void TestCreateTariffDescription_Number_Null()
{
Assert.That(
TariffDescriptionFactory.Create(null).Id,
Is.Null);
}
[Test]
public void TestCreateTariffDescription_FreeTimePerSession_Null()
{
Assert.That(
TariffDescriptionFactory.Create(null).TariffEntries.ContainsKey("1"), // Free time per session
Is.False);
}
[Test]
public void TestCreateTariffDescription_FeeEuroPerHour_Null()
{
Assert.That(
TariffDescriptionFactory.Create(null).TariffEntries.ContainsKey("2"), // FeeEuroPerHour
Is.False);
}
[Test]
public void TestCreateTariffDescription_AboEuroPerMonth_Null()
{
Assert.That(
TariffDescriptionFactory.Create(null).TariffEntries.ContainsKey("4"), // Abo euro per month
Is.False);
}
}
}

View file

@ -6,7 +6,7 @@ namespace TestShareeLib.Model.Map
[TestFixture]
internal class TestNullMapSpan
{
[Test]
[Test]
public void TestCtor()
{
var mapSpan = MapSpanFactory.Create();

View file

@ -1,7 +1,4 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
using TINK.Model.MiniSurvey;
namespace TestShareeLib.Model.MiniSurvey

View file

@ -9,7 +9,7 @@ namespace TestShareeLib.Model.MiniSurvey
public void TestCtro()
{
Assert.That(
new MiniSurveyModel.QuestionModel().PossibleAnswers.Count,
new QuestionModel().PossibleAnswers.Count,
Is.EqualTo(1));
}
}

View file

@ -0,0 +1,176 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using NUnit.Framework;
using Serilog.Events;
using TINK.Model.Settings;
using TINK.Settings;
namespace TestTINKLib.Model.Settings
{
[TestFixture]
public class TestJsonSettingsDictionary
{
/// <summary> Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.</summary>
[Test]
public void TestGetCopriHostUri_NoFile()
{
Assert.IsNull(JsonSettingsDictionary.GetCopriHostUri(new Dictionary<string, string>()));
}
/// <summary> Verifies that empty log file leads to expected default value and doesn not throw exceptions.</summary>
[Test]
public void TestGetPolling()
{
// Serialize parameters.
var l_oDict = new Dictionary<string, string>()
.SetPollingParameters(new PollingParameters(new TimeSpan(0, 0, 0, 15, 0), false));
// Deserialize parameters.
Assert.AreEqual(
new PollingParameters(new TimeSpan(0, 0, 0, 15, 0), false),
l_oDict.GetPollingParameters());
}
/// <summary> Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.</summary>
[Test]
public void TestGetPolling_NoFile()
{
Assert.IsNull(JsonSettingsDictionary.GetPollingParameters(new Dictionary<string, string>()));
}
[Test]
public void TestGetGetCopriHostUri()
{
var l_oDict = new Dictionary<string, string>()
.SetCopriHostUri("http://1.2.3.4");
Assert.AreEqual(
new Uri("http://1.2.3.4"),
JsonSettingsDictionary.GetCopriHostUri(l_oDict));
}
/// <summary> Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.</summary>
[Test]
public void TestGetLoggingLevel()
{
var l_oDictionary = new Dictionary<string, string>()
.SetMinimumLoggingLevel(0); // Verbose = 0
Assert.AreEqual(
LogEventLevel.Verbose,
JsonSettingsDictionary.GetMinimumLoggingLevel(l_oDictionary)); // LogEventLevel.Error = 4
}
/// <summary> Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.</summary>
[Test]
public void TestGetLoggingLevel_NoFile()
{
Assert.IsNull(JsonSettingsDictionary.GetMinimumLoggingLevel(new Dictionary<string, string>()));
}
[Test]
public void TestGetAppVersion_FirstInstall()
{
var l_oDict = new Dictionary<string, string>();
Assert.IsNull(JsonSettingsDictionary.GetAppVersion(l_oDict));
}
[Test]
public void TestGetAppVersion_LegacyTo115()
{
var l_oDict = new Dictionary<string, string> { { "AppVersion", "7.2.3.9" } };
Assert.AreEqual(new Version(7, 2, 3, 9), JsonSettingsDictionary.GetAppVersion(l_oDict));
l_oDict = new Dictionary<string, string> { { "AppVersion", "7.2.3" } };
Assert.AreEqual(new Version(7, 2, 3), JsonSettingsDictionary.GetAppVersion(l_oDict));
}
[Test]
public void TestGetAppVersion_Json()
{
var l_oDict = new Dictionary<string, string> { { "AppVersion", "\"3.1.2.117\"" } };
Assert.AreEqual(new Version(3, 1, 2, 117), JsonSettingsDictionary.GetAppVersion(l_oDict));
}
[Test]
public void TestSetAppVersion_Json()
{
var l_oDict = new Dictionary<string, string>()
.SetAppVersion(new Version(47, 12, 3));
Assert.AreEqual(new Version(47, 12, 3), JsonSettingsDictionary.GetAppVersion(l_oDict));
}
[Test]
public void TestGetShowWhatsNew_FirstInstall()
{
var l_oDict = new Dictionary<string, string>();
Assert.IsNull(JsonSettingsDictionary.GetWhatsNew(l_oDict));
}
[Test]
public void TestGetShowWhatsNew_Json()
{
var l_oDict = new Dictionary<string, string> { { "ShowWhatsNew", "\"3.1.2.117\"" } };
Assert.AreEqual(new Version(3, 1, 2, 117), JsonSettingsDictionary.GetWhatsNew(l_oDict));
l_oDict = new Dictionary<string, string> { { "ShowWhatsNew", "\"3.1.2\"" } };
Assert.AreEqual(new Version(3, 1, 2), JsonSettingsDictionary.GetWhatsNew(l_oDict));
}
[Test]
public void TestSetShowWhats_Json()
{
var l_oDict = new Dictionary<string, string>()
.SetWhatsNew(new Version(47, 12, 3));
Assert.AreEqual(new Version(47, 12, 3), JsonSettingsDictionary.GetWhatsNew(l_oDict));
}
[Test]
public void TestGetEntryTNoLegacySettingsKeyNull() => Assert.That(
JsonSettingsDictionary.GetEntry<string>(null, new Dictionary<string, string>()),
Is.Null);
[Test]
public void TestGetEntryTNoLegacySettingsNull() => Assert.That(
JsonSettingsDictionary.GetEntry<string>("Hi", null),
Is.Null);
[Test]
public void TestGetEntryTNoLegacyEntryNotFound() => Assert.That(
JsonSettingsDictionary.GetEntry<string>("Hi", new Dictionary<string, string> { { "Ho", @"""Hu""" } }),
Is.Null);
[Test]
public void TestGetEntryTNoLegacyEntryFound() => Assert.That(
JsonSettingsDictionary.GetEntry<string>("Hi", new Dictionary<string, string> { { "Hi", @"""Ho""" } }),
Is.EqualTo("Ho"));
[Test]
public void TestGetEntryT() => Assert.That(
JsonSettingsDictionary.GetEntry<string>("Hi", new Dictionary<string, string> { { "Hi", @"""Ho""" } }, (value) => @"""Hey"""),
Is.EqualTo("Hey"));
[Test]
public void TestGetActiveTheme() => Assert.That(
JsonSettingsDictionary.GetActiveTheme(new Dictionary<string, string> { { "Theme", @"""Konrad""" } }),
Is.EqualTo(typeof(TINK.Themes.Konrad).Name));
[Test]
public void TestGetActiveThemeLegacy() => Assert.That(
JsonSettingsDictionary.GetActiveTheme(new Dictionary<string, string> { { "Theme", @"""TINK.Themes.Konrad""" } }),
Is.EqualTo(typeof(TINK.Themes.Konrad).Name));
[Test]
public void TestSetActiveTheme()
{
var settings = JsonSettingsDictionary.SetActiveTheme(new Dictionary<string, string>(), @"Konrad");
Assert.That(
settings,
Contains.Key("Theme"));
settings = JsonSettingsDictionary.SetActiveTheme(new Dictionary<string, string>(), @"Konrad");
Assert.That(
settings["Theme"],
Is.EqualTo(JsonConvert.SerializeObject(typeof(TINK.Themes.Konrad).Name)));
}
}
}

View file

@ -1,8 +1,7 @@
using Newtonsoft.Json;
using System;
using Newtonsoft.Json;
using NUnit.Framework;
using System;
using TestFramework;
using TestShareeLib;
using TINK.Model.State;
@ -30,8 +29,8 @@ namespace TestTINKLib.Fixtures.Bike
""Code"":""17 xxb""
}";
Assert.AreEqual(
TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty)),
TestHelper.PrepareXmlForStringCompare(l_oDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)));
TestHelper.PrepareXmlForStringCompare(EXPECTED.Replace("\n", string.Empty).Replace("\r", string.Empty)),
TestHelper.PrepareXmlForStringCompare(l_oDetected.Replace("\n", string.Empty).Replace("\r", string.Empty)));
// Deserialize object and verify.
var l_oInfoTarget = JsonConvert.DeserializeObject<StateOccupiedInfo>(l_oDetected);

View file

@ -1,7 +1,4 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
namespace TestShareeLib.Model.Station
{

View file

@ -1,8 +1,10 @@
using NUnit.Framework;
using System;
using System;
using System.Collections.Generic;
using NUnit.Framework;
using TINK.Model;
using TINK.Model.Bike;
using TINK.Model.Bikes;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
namespace TestTINKLib.Fixtures.ObjectTests.Bike
{
@ -13,11 +15,11 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
public void TestGetAtStation()
{
var coll = new BikeCollection(
new Dictionary<string, TINK.Model.Bike.BC.BikeInfo>
new Dictionary<string, TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo>
{
{"3", new TINK.Model.Bike.BC.BikeInfo("7", LockModel.ILockIt, "3" /* Stadion id */) },
{"7", new TINK.Model.Bike.BC.BikeInfo("8", LockModel.ILockIt, "12" /* Stadion id */) },
{"12", new TINK.Model.Bike.BC.BikeInfo("33", LockModel.ILockIt, "12" /* Stadion id */) }
{"3", new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("7", LockModel.ILockIt), new Drive(), "3" /* Stadion id */) },
{"7", new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("8", LockModel.ILockIt), new Drive(), "12" /* Stadion id */) },
{"12", new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("33", LockModel.ILockIt), new Drive(), "12" /* Stadion id */) }
});
Assert.AreEqual(
@ -54,10 +56,10 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
{
// Holds no LockIt bikes
var coll = new BikeCollection(
new Dictionary<string, TINK.Model.Bike.BC.BikeInfo>
new Dictionary<string, TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo>
{
{"7", new TINK.Model.Bike.BC.BikeInfo("8", LockModel.ILockIt, "12" /* Stadion id */) },
{"12", new TINK.Model.Bike.BC.BikeInfo("33", LockModel.ILockIt, "12" /* Stadion id */) }
{"7", new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("8", LockModel.ILockIt), new Drive(), "12" /* Stadion id */) },
{"12", new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("33", LockModel.ILockIt), new Drive(), "12" /* Stadion id */) }
});
Assert.AreEqual(
@ -65,22 +67,22 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike
coll.GetLockIt().Count);
}
[Test]
public void TestGetLockIt()
{
[Test]
public void TestGetLockIt()
{
// Holds no LockIt bike with matching station number.
var coll = new BikeCollection(
new Dictionary<string, TINK.Model.Bike.BC.BikeInfo>
{
{"7", new TINK.Model.Bike.BC.BikeInfo("8", LockModel.ILockIt, "12" /* Stadion id */) },
{"11", new TINK.Model.Bike.BluetoothLock.BikeInfo("33", 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "12" /* Stadion id */) },
{"12", new TINK.Model.Bike.BC.BikeInfo("33", LockModel.ILockIt, "12" /* Stadion id */) }
});
// Holds no LockIt bike with matching station number.
var coll = new BikeCollection(
new Dictionary<string, TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo>
{
{"7", new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("8", LockModel.ILockIt), new Drive(), "12" /* Stadion id */) },
{"11", new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("33", LockModel.ILockIt), new Drive(), 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "12" /* Stadion id */) },
{"12", new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("33", LockModel.ILockIt), new Drive(), "12" /* Stadion id */) }
});
Assert.AreEqual(
1,
coll.GetLockIt().Count);
Assert.AreEqual(
1,
coll.GetLockIt().Count);
}
}
}

View file

@ -4,7 +4,7 @@ using TINK.Model;
namespace TestShareeLib.Model
{
[TestFixture]
public class TestBookingFinishedModel
public class TestBookingFinishedModel
{
[Test]
public void TestCtor()

View file

@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Serilog.Events;
using TINK.Model.Settings;
using TINK.Settings;
namespace TestTINKLib.Fixtures.ObjectTests
{
[TestFixture]
public class TestJsonSettingsDictionary
{
/// <summary> Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.</summary>
[Test]
public void TestGetCopriHostUri_NoFile()
{
Assert.IsNull(JsonSettingsDictionary.GetCopriHostUri(new Dictionary<string, string>()));
}
/// <summary> Verifies that empty log file leads to expected default value and doesn not throw exceptions.</summary>
[Test]
public void TestGetPolling()
{
// Serialize parameters.
var l_oDict = new Dictionary<string, string>()
.SetPollingParameters(new PollingParameters(new TimeSpan(0, 0, 0, 15, 0), false));
// Deserialize parameters.
Assert.AreEqual(
new PollingParameters(new TimeSpan(0, 0, 0, 15, 0), false),
l_oDict.GetPollingParameters());
}
/// <summary> Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.</summary>
[Test]
public void TestGetPolling_NoFile()
{
Assert.IsNull(JsonSettingsDictionary.GetPollingParameters(new Dictionary<string, string>()));
}
[Test]
public void TestGetGetCopriHostUri()
{
var l_oDict = new Dictionary<string, string>()
.SetCopriHostUri("http://1.2.3.4");
Assert.AreEqual(
new Uri("http://1.2.3.4"),
JsonSettingsDictionary.GetCopriHostUri(l_oDict));
}
/// <summary> Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.</summary>
[Test]
public void TestGetLoggingLevel()
{
var l_oDictionary = new Dictionary<string, string>()
.SetMinimumLoggingLevel(0); // Verbose = 0
Assert.AreEqual(
LogEventLevel.Verbose,
JsonSettingsDictionary.GetMinimumLoggingLevel(l_oDictionary)); // LogEventLevel.Error = 4
}
/// <summary> Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.</summary>
[Test]
public void TestGetLoggingLevel_NoFile()
{
Assert.IsNull(JsonSettingsDictionary.GetMinimumLoggingLevel(new Dictionary<string, string>()));
}
[Test]
public void TestGetAppVersion_FirstInstall()
{
var l_oDict = new Dictionary<string, string>();
Assert.IsNull(JsonSettingsDictionary.GetAppVersion(l_oDict));
}
[Test]
public void TestGetAppVersion_LegacyTo115()
{
var l_oDict = new Dictionary<string, string> { { "AppVersion", "7.2.3.9" } };
Assert.AreEqual(new Version(7, 2, 3, 9), JsonSettingsDictionary.GetAppVersion(l_oDict));
l_oDict = new Dictionary<string, string> { { "AppVersion", "7.2.3" } };
Assert.AreEqual(new Version(7, 2, 3), JsonSettingsDictionary.GetAppVersion(l_oDict));
}
[Test]
public void TestGetAppVersion_Json()
{
var l_oDict = new Dictionary<string, string> { { "AppVersion", "\"3.1.2.117\"" } };
Assert.AreEqual(new Version(3, 1, 2, 117), JsonSettingsDictionary.GetAppVersion(l_oDict));
}
[Test]
public void TestSetAppVersion_Json()
{
var l_oDict = new Dictionary<string, string>()
.SetAppVersion(new Version(47, 12, 3));
Assert.AreEqual(new Version(47, 12, 3), JsonSettingsDictionary.GetAppVersion(l_oDict));
}
[Test]
public void TestGetShowWhatsNew_FirstInstall()
{
var l_oDict = new Dictionary<string, string>();
Assert.IsNull(JsonSettingsDictionary.GetWhatsNew(l_oDict));
}
[Test]
public void TestGetShowWhatsNew_Json()
{
var l_oDict = new Dictionary<string, string> { { "ShowWhatsNew", "\"3.1.2.117\"" } };
Assert.AreEqual(new Version(3, 1, 2, 117), JsonSettingsDictionary.GetWhatsNew(l_oDict));
l_oDict = new Dictionary<string, string> { { "ShowWhatsNew", "\"3.1.2\"" } };
Assert.AreEqual(new Version(3, 1, 2), JsonSettingsDictionary.GetWhatsNew(l_oDict));
}
[Test]
public void TestSetShowWhats_Json()
{
var l_oDict = new Dictionary<string, string>()
.SetWhatsNew(new Version(47, 12, 3));
Assert.AreEqual(new Version(47, 12, 3), JsonSettingsDictionary.GetWhatsNew(l_oDict));
}
}
}

View file

@ -11,7 +11,7 @@ namespace TestShareeLib.Model
{
var positon = PositionFactory.Create();
Assert.That(positon.GetType(), Is.EqualTo(typeof(NullPostion)), "Object under test is not of expected type.");
Assert.That(
positon.IsValid,
Is.False);

View file

@ -1,7 +1,4 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
using TINK.Model;
namespace TestShareeLib.Model

View file

@ -1,18 +1,18 @@
using NUnit.Framework;
using System;
using System;
using NSubstitute;
using NUnit.Framework;
using Plugin.BLE.Abstractions.Contracts;
using TestFramework.Repository;
using TINK.Model;
using TINK.Model.Connector;
using TINK.Model.Services.CopriApi.ServerUris;
using TINK.Services;
using NSubstitute;
using TINK.Services.Geolocation;
using TINK.Services.BluetoothLock;
using TINK.Model.Device;
using TINK.Model.Services.CopriApi.ServerUris;
using TINK.Model.User.Account;
using TestFramework.Repository;
using TINK.Repository;
using TINK.Services;
using TINK.Services.BluetoothLock;
using TINK.Services.Geolocation;
using TINK.Services.Permissions;
using Plugin.BLE.Abstractions.Contracts;
namespace TestTINKLib.Fixtures.UseCases.Logout
{
@ -43,8 +43,8 @@ namespace TestTINKLib.Fixtures.UseCases.Logout
accountStore,
isConnectedFunc: () => true,
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => string.IsNullOrEmpty(sessionCookie)
? new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), sessionCookie, mail, new CopriCallsMemory001())
: new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), sessionCookie, mail, new CopriCallsMemory001(sessionCookie)),
? new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, new CopriCallsMemory001())
: new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, new CopriCallsMemory001(sessionCookie)),
merchantId: "MyMerchId",
bluetoothService: Substitute.For<IBluetoothLE>(),
locationPermissionsService: permissions,
@ -53,31 +53,32 @@ namespace TestTINKLib.Fixtures.UseCases.Logout
device: device,
specialFolder: specialFolder,
cipher: null,
theme: null,
currentVersion: new Version(3, 2, 0, 115),
lastVersion: new Version(3, 0, 173)); // Current app version. Must be larger or equal 3.0.173 to
Assert.IsTrue(l_oTinkApp.ActiveUser.IsLoggedIn);
// There are 6 bikes available and 2, one reserved and one rented by javaminsiter.
Assert.AreEqual(
10,
l_oTinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count,
10,
l_oTinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count,
"Sum of bikes is 6 occupied plus 2 occupied.");
Assert.AreEqual(2,
Assert.AreEqual(2,
l_oTinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count,
"Javaminster occupies 2 bikes.");
Assert.AreEqual("6103_112e96b36ba33de245943c5ffaf369cd_", l_oTinkApp.GetConnector(true).Command.SessionCookie);
// Log user out.
l_oTinkApp.GetConnector(true).Command.DoLogout().Wait();
l_oTinkApp.GetConnector(true).Command.DoLogout().Wait();
l_oTinkApp.ActiveUser.Logout();
Assert.IsFalse(l_oTinkApp.ActiveUser.IsLoggedIn);
Assert.AreEqual(
8,
8,
l_oTinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count,
"Sum of bikes is 6 occupied, no one occupied because no user is logged in");
Assert.AreEqual(
0,
0,
l_oTinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count,
"If no user is logged in no occupied bikes are shown.");
Assert.IsNull(l_oTinkApp.GetConnector(true).Command.SessionCookie);

View file

@ -1,19 +1,19 @@
using NUnit.Framework;
using System;
using System;
using System.Threading.Tasks;
using NSubstitute;
using NUnit.Framework;
using Plugin.BLE.Abstractions.Contracts;
using TestFramework.Repository;
using TINK.Model;
using TINK.Model.Connector;
using TINK.Model.Services.CopriApi.ServerUris;
using TINK.Services;
using NSubstitute;
using TINK.Services.Geolocation;
using TINK.Services.BluetoothLock;
using TINK.Model.Device;
using TINK.Model.Services.CopriApi.ServerUris;
using TINK.Model.User.Account;
using System.Threading.Tasks;
using TestFramework.Repository;
using TINK.Repository;
using TINK.Services;
using TINK.Services.BluetoothLock;
using TINK.Services.Geolocation;
using TINK.Services.Permissions;
using Plugin.BLE.Abstractions.Contracts;
namespace TestShareeLib.UseCases.Login
{
@ -38,8 +38,8 @@ namespace TestShareeLib.UseCases.Login
accountStore,
isConnectedFunc: () => true,
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => string.IsNullOrEmpty(sessionCookie)
? new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), sessionCookie, mail, new CopriCallsMemory001())
: new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), sessionCookie, mail, new CopriCallsMemory001(sessionCookie)),
? new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, new CopriCallsMemory001())
: new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, new CopriCallsMemory001(sessionCookie)),
merchantId: "MyMerchId",
bluetoothService: Substitute.For<IBluetoothLE>(),
locationPermissionsService: permissions,
@ -48,32 +48,33 @@ namespace TestShareeLib.UseCases.Login
device: device,
specialFolder: specialFolder,
cipher: null,
theme: null,
currentVersion: new Version(3, 2, 0, 115),
lastVersion: new Version(3, 0, 173) /* Current app version. Must be larger or equal 3.0.173 to lastVersion*/);
// Verifiy initial state.
Assert.IsFalse(tinkApp.ActiveUser.IsLoggedIn);
Assert.AreEqual(
8,
8,
tinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count,
"Sum of bikes is 6 occupied, no one occupied because no user is logged in");
Assert.AreEqual(
0,
0,
tinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count,
"If no user is logged in no occupied bikes are shown.");
Assert.IsNull(tinkApp.GetConnector(true).Command.SessionCookie);
// Log in user.
var account = tinkApp.GetConnector(true).Command.DoLogin("javaminister@gmail.com", "*********", "HwId1000000000000").Result;
await tinkApp.ActiveUser.Login(account);
Assert.IsTrue(tinkApp.ActiveUser.IsLoggedIn);
Assert.AreEqual(
10,
10,
tinkApp.GetConnector(true).Query.GetBikesAsync().Result.Response.Count,
"Sum of bikes is 6 occupied plus 2 occupied.");
Assert.AreEqual(
2,
2,
tinkApp.GetConnector(true).Query.GetBikesOccupiedAsync().Result.Response.Count,
"Javaminster occupies 2 bikes.");
Assert.AreEqual("6103_112e96b36ba33de245943c5ffaf369cd_oiF2kahH", tinkApp.GetConnector(true).Command.SessionCookie);

View file

@ -0,0 +1,188 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using TINK.Model;
using TINK.ViewModel.WhatsNew;
using Xamarin.Essentials;
namespace TestTINKLib.Fixtures.ObjectTests
{
[TestFixture]
public class TestWhatsNew
{
[Test]
public void TestIsMessagesConsistent()
{
foreach (AppFlavor app in Enum.GetValues(typeof(AppFlavor)))
{
foreach (DevicePlatform platform in new List<DevicePlatform> { DevicePlatform.iOS, DevicePlatform.Android })
Assert.That(
() => new WhatsNew(
WhatsNew.AllFlavorsAndPlatformMessages[WhatsNew.AllFlavorsAndPlatformMessages.Count - 1].Version,
WhatsNew.AllFlavorsAndPlatformMessages[0].Version,
WhatsNew.AllFlavorsAndPlatformMessages[0].Version,
app,
platform).WhatsNewText,
Throws.Nothing,
"Invalid entries detected.");
}
}
[Test]
public void TestIsShowRequired_CleanInstall()
{
Assert.IsFalse(new WhatsNew(
new Version(2, 4), /* Current version */
null, // last version
null, /* Whats new was never shown */
AppFlavor.ShareeBike,
DevicePlatform.Android).IsShowRequired);
}
/// <summary>
/// This test verified old implementedation which worked with the different versions to determine whenther whats new has to be shown or not.
/// Test updated to new implmentedation (based on filtering of AllFlavorsAndPlatformMessages)
/// </summary>
[Test]
public void TestIsShowRequired_Update_VersionWhichSupporsWhatsNew()
{
Assert.IsTrue(
new WhatsNew(
new Version(3, 0, 335), /* Current version */
new Version(3, 0, 333), /* last version */
new Version(3, 0, 111), /* Version when whats new was shown */
AppFlavor.ShareeBike,
DevicePlatform.Android).IsShowRequired,
"If whats new was last shonw for version 3.0.111 and current version is 2.0.335 info must be shown");
}
/// <summary>
/// This test verified old implementedation which worked with the different versions to determine whenther whats new has to be shown or not.
/// Test updated to new implmentedation (based on filtering of AllFlavorsAndPlatformMessages)
/// </summary>
[Test]
public void TestIsShowRequired_Update_VersionWithoutWhatsNew()
{
Assert.IsTrue(
new WhatsNew(
new Version(3, 0, 335), /* Current version */
new Version(3, 0, 333), /* last version */
null, /* Whats new was never shown */
AppFlavor.ShareeBike,
DevicePlatform.Android).IsShowRequired,
"If whats new was never shown but last version was 3.0.333 (not clean install) info must be shown");
}
[Test]
public void TestIsShowRequired_False()
{
Assert.IsFalse(
new WhatsNew(new Version(2, 5), new Version(2, 5), new Version(2, 5), AppFlavor.ShareeBike, DevicePlatform.Android).IsShowRequired,
"Whats new must never be presented twice.");
}
[Test]
public void TestIsShowRequired_False_Errors()
{
Assert.IsFalse(new WhatsNew(null, new Version(2, 6), new Version(2, 5), AppFlavor.ShareeBike, DevicePlatform.Android).IsShowRequired);
Assert.IsFalse(new WhatsNew(new Version(2, 6), null, new Version(2, 5), AppFlavor.ShareeBike, DevicePlatform.Android).IsShowRequired);
Assert.IsFalse(new WhatsNew(null, null, new Version(2, 5), AppFlavor.ShareeBike, DevicePlatform.Android).IsShowRequired);
}
[Test]
public void TestWhatsNewText_MajorUpdate()
{
Assert.AreEqual(
"<p><b>3.0.0.115</b><br/>Benutzeroberfläche verbessert.\r\n\r\n" +
"</p><p><b>3.0.120</b><br/>Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\nOfflineanzeige Stationen/ Räderinfo.\r\n\r\n</p>",
WhatsNewViewModel.GetWhatNextHtmlText(new WhatsNew(new Version(3, 0, 120), new Version(3, 0, 0, 114), new Version(3, 0, 0, 114), AppFlavor.ShareeBike, DevicePlatform.Android).WhatsNewText),
"Current version is 30.0.120, last whats new was shown in version 3.0.0.114: Two changes to be notified about.");
}
[Test]
public void TestWhatsNewText_MinorUpdate()
{
Assert.AreEqual(
"<p><b>3.0.120</b><br/>Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\nOfflineanzeige Stationen/ Räderinfo.\r\n\r\n</p>",
WhatsNewViewModel.GetWhatNextHtmlText(new WhatsNew(new Version(3, 0, 120), new Version(3, 0, 0, 115), new Version(3, 0, 0, 115), AppFlavor.ShareeBike, DevicePlatform.Android).WhatsNewText));
}
[Test]
public void TestWhatsNewGetFileredMessages_GeneralMessage()
{
Assert.That(
new WhatsNew(new Version(3, 0, 335), new Version(3, 0), new Version(3, 0), AppFlavor.ShareeBike, DevicePlatform.iOS, new WhatsNewMessages
{
{
new Version(3, 0, 0, 115),
"Benutzeroberfläche verbessert.\r\n\r\n"
}
}).WhatsNewText.Count(),
Is.EqualTo(1));
}
[Test]
public void TestWhatsNewGetFileredMessages_MeinKonradOnly_Included()
{
Assert.That(
new WhatsNew(new Version(3, 0, 335), new Version(3, 0), new Version(3, 0), AppFlavor.MeinKonrad, DevicePlatform.iOS, new WhatsNewMessages
{
{
new Version(3, 0, 0, 115),
"Benutzeroberfläche verbessert.\r\n\r\n",
new List<AppFlavor> {AppFlavor.MeinKonrad}
}
}).WhatsNewText.Count(),
Is.EqualTo(1));
}
[Test]
public void TestWhatsNewGetFileredMessages_MeinKonradOnly_Excluded()
{
Assert.That(
new WhatsNew(new Version(3, 0, 335), new Version(3, 0), new Version(3, 0), AppFlavor.ShareeBike, DevicePlatform.iOS, new WhatsNewMessages
{
{
new Version(3, 0, 0, 115),
"Benutzeroberfläche verbessert.\r\n\r\n",
new List<AppFlavor> {AppFlavor.MeinKonrad}
}
}).WhatsNewText.Count(),
Is.EqualTo(0));
}
[Test]
public void TestWhatsNewGetFileredMessages_iOSOnly_Included()
{
Assert.That(
new WhatsNew(new Version(3, 0, 335), new Version(3, 0), new Version(3, 0), AppFlavor.ShareeBike, DevicePlatform.iOS, new WhatsNewMessages
{
{
new Version(3, 0, 0, 115),
"Benutzeroberfläche verbessert.\r\n\r\n",
null,
new List<DevicePlatform> {DevicePlatform.iOS}
}
}).WhatsNewText.Count(),
Is.EqualTo(1));
}
[Test]
public void TestWhatsNewGetFileredMessages_iOSOnly_Exclued()
{
Assert.That(
new WhatsNew(new Version(3, 0, 335), new Version(3, 0), new Version(3, 0), AppFlavor.ShareeBike, DevicePlatform.Android, new WhatsNewMessages
{
{
new Version(3, 0, 0, 115),
"Benutzeroberfläche verbessert.\r\n\r\n",
null,
new List<DevicePlatform> {DevicePlatform.iOS}
}
}).WhatsNewText.Count(),
Is.EqualTo(0));
}
}
}

View file

@ -0,0 +1,452 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using TINK.Model;
using TINK.ViewModel.WhatsNew;
using Xamarin.Essentials;
namespace TestShareeLib.Model
{
[TestFixture]
public class TestWhatsNewMessage
{
[Test]
public void TestAdd_Text()
{
Assert.That(
new WhatsNewMessages
{
{
new Version(3, 0, 115),
"Whats new text."
}
}[0].Message,
Is.EqualTo("Whats new text."));
}
[Test]
public void TestAdd_Text_Null()
{
Assert.That(
new WhatsNewMessages
{
{
new Version(3, 0, 115),
null
}
}.Count,
Is.EqualTo(0));
}
[Test]
public void Test_Add_Version()
{
Assert.That(
new WhatsNewMessages
{
{
new Version(3, 0, 115),
"Whats new text."
}
}[0].Version,
Is.EqualTo(new Version(3, 0, 115)));
}
[Test]
public void Test_Add_Version_Null()
{
Assert.That(
new WhatsNewMessages
{
{
null,
"Whats new text."
}
}.Count,
Is.EqualTo(0));
}
[Test]
public void Test_Add_Flavors_GeneralEntry()
{
Assert.That(
new WhatsNewMessages
{
{
new Version(3, 0, 115),
"Whats new text."
}
}[0].Flavors.Count,
Is.EqualTo(0));
}
[Test]
public void Test_Add_Flavors_ShareeBike()
{
Assert.That(
new WhatsNewMessages
{
{
new Version(3, 0, 115),
"Whats new text.",
new List<AppFlavor> { AppFlavor.MeinKonrad }
}
}[0].Flavors,
Is.EqualTo(new List<AppFlavor> { AppFlavor.MeinKonrad }));
}
[Test]
public void TestPlatforms_Add_Platform_GeneralEntry()
{
Assert.That(
new WhatsNewMessages
{
{
new Version(3, 0, 115),
"Whats new text."
}
}[0].Platforms.Count,
Is.EqualTo(0));
}
[Test]
public void TestPlatforms_Add_Platform_IOs()
{
Assert.That(
new WhatsNewMessages
{
{
new Version(3, 0, 115),
"Whats new text.",
null,
new List<DevicePlatform> { DevicePlatform.iOS }
}
}[0].Platforms,
Is.EqualTo(new List<DevicePlatform> { DevicePlatform.iOS }));
}
[Test]
public void TestWhatsNewText_MajorUpdate_Lastenradbayern_iOS()
{
var whatsNew = new WhatsNew(new Version(3, 0, 120),
new Version(3, 0, 0, 114),
new Version(3, 0, 0, 114),
AppFlavor.LastenradBayern,
DevicePlatform.iOS,
new WhatsNewMessages {
{
new Version(3, 0, 0, 113),
"3.0.0.113 verbessert.\r\n\r\n"
},
{
new Version(3, 0, 0, 115),
"Benutzeroberfläche verbessert.\r\n\r\n"
},
{
new Version(3, 0, 0, 116),
"sharee.bike und Lastenrad Bayern verbessert unter iOS und Android.\r\n\r\n",
new List<AppFlavor> {AppFlavor.ShareeBike, AppFlavor.LastenradBayern}
},
{
new Version(3, 0, 0, 117),
"iOS Implementierungen verbessert.\r\n\r\n",
null,
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 0, 118),
"iOS version Lastenrad Bayern verbessert.\r\n\r\n",
new List<AppFlavor> { AppFlavor.LastenradBayern },
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 0, 119),
"In Mein konrad unter Droid in 119 was anderes als unter iOS gemacht.\r\n\r\n",
new List<AppFlavor> { AppFlavor.MeinKonrad },
new List<DevicePlatform> { DevicePlatform.Android }
},
{
new Version(3, 0, 0, 119),
"In Mein konrad unter iOS in 119 was anderes als unter Droid gemacht.\r\n\r\n",
new List<AppFlavor> { AppFlavor.MeinKonrad },
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 120),
"Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\n" +
"Offlineanzeige Stationen/ Räderinfo.\r\n\r\n"
},
{
new Version(3, 0, 121),
"3.0.121 verbessert.\r\n\r\n"
}
});
Assert.AreEqual(
"<p><b>3.0.0.115</b><br/>Benutzeroberfläche verbessert.\r\n\r\n</p>" +
"<p><b>3.0.0.116</b><br/>sharee.bike und Lastenrad Bayern verbessert unter iOS und Android.\r\n\r\n</p>" +
"<p><b>3.0.0.117</b><br/>iOS Implementierungen verbessert.\r\n\r\n</p>" +
"<p><b>3.0.0.118</b><br/>iOS version Lastenrad Bayern verbessert.\r\n\r\n</p>" +
"<p><b>3.0.120</b><br/>Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\nOfflineanzeige Stationen/ Räderinfo.\r\n\r\n</p>",
WhatsNewViewModel.GetWhatNextHtmlText(whatsNew.WhatsNewText));
}
[Test]
public void TestWhatsNewText_MajorUpdate_ShareeBike_iOS()
{
var whatsNew = new WhatsNew(new Version(3, 0, 120),
new Version(3, 0, 0, 114),
new Version(3, 0, 0, 114),
AppFlavor.ShareeBike,
DevicePlatform.iOS,
new WhatsNewMessages {
{
new Version(3, 0, 0, 113),
"3.0.0.113 verbessert.\r\n\r\n"
},
{
new Version(3, 0, 0, 115),
"Benutzeroberfläche verbessert.\r\n\r\n"
},
{
new Version(3, 0, 0, 116),
"sharee.bike und Lastenrad Bayern verbessert unter iOS und Android.\r\n\r\n",
new List<AppFlavor> {AppFlavor.ShareeBike, AppFlavor.LastenradBayern}
},
{
new Version(3, 0, 0, 117),
"iOS Implementierungen verbessert.\r\n\r\n",
null,
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 0, 118),
"iOS version Lastenrad Bayern verbessert.\r\n\r\n",
new List<AppFlavor> { AppFlavor.LastenradBayern },
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 0, 119),
"In Mein konrad unter Droid in 119 was anderes als unter iOS gemacht.\r\n\r\n",
new List<AppFlavor> { AppFlavor.MeinKonrad },
new List<DevicePlatform> { DevicePlatform.Android }
},
{
new Version(3, 0, 0, 119),
"In Mein konrad unter iOS in 119 was anderes als unter Droid gemacht.\r\n\r\n",
new List<AppFlavor> { AppFlavor.MeinKonrad },
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 120),
"Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\n" +
"Offlineanzeige Stationen/ Räderinfo.\r\n\r\n"
},
{
new Version(3, 0, 121),
"3.0.121 verbessert.\r\n\r\n"
}
});
Assert.AreEqual(
"<p><b>3.0.0.115</b><br/>Benutzeroberfläche verbessert.\r\n\r\n</p>" +
"<p><b>3.0.0.116</b><br/>sharee.bike und Lastenrad Bayern verbessert unter iOS und Android.\r\n\r\n</p>" +
"<p><b>3.0.0.117</b><br/>iOS Implementierungen verbessert.\r\n\r\n</p>" +
"<p><b>3.0.120</b><br/>Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\nOfflineanzeige Stationen/ Räderinfo.\r\n\r\n</p>",
WhatsNewViewModel.GetWhatNextHtmlText(whatsNew.WhatsNewText));
}
[Test]
public void TestWhatsNewText_MajorUpdate_ShareeBike_Android()
{
var whatsNew = new WhatsNew(new Version(3, 0, 120),
new Version(3, 0, 0, 114),
new Version(3, 0, 0, 114),
AppFlavor.ShareeBike,
DevicePlatform.Android,
new WhatsNewMessages {
{
new Version(3, 0, 0, 113),
"3.0.0.113 verbessert.\r\n\r\n"
},
{
new Version(3, 0, 0, 115),
"Benutzeroberfläche verbessert.\r\n\r\n"
},
{
new Version(3, 0, 0, 116),
"sharee.bike und Lastenrad Bayern verbessert unter iOS und Android.\r\n\r\n",
new List<AppFlavor> {AppFlavor.ShareeBike, AppFlavor.LastenradBayern}
},
{
new Version(3, 0, 0, 117),
"iOS Implementierungen verbessert.\r\n\r\n",
null,
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 0, 118),
"iOS version Lastenrad Bayern verbessert.\r\n\r\n",
new List<AppFlavor> { AppFlavor.LastenradBayern },
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 0, 119),
"In Mein konrad unter Droid in 119 was anderes als unter iOS gemacht.\r\n\r\n",
new List<AppFlavor> { AppFlavor.MeinKonrad },
new List<DevicePlatform> { DevicePlatform.Android }
},
{
new Version(3, 0, 0, 119),
"In Mein konrad unter iOS in 119 was anderes als unter Droid gemacht.\r\n\r\n",
new List<AppFlavor> { AppFlavor.MeinKonrad },
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 120),
"Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\n" +
"Offlineanzeige Stationen/ Räderinfo.\r\n\r\n"
},
{
new Version(3, 0, 121),
"3.0.121 verbessert.\r\n\r\n"
}
});
Assert.AreEqual(
"<p><b>3.0.0.115</b><br/>Benutzeroberfläche verbessert.\r\n\r\n</p>" +
"<p><b>3.0.0.116</b><br/>sharee.bike und Lastenrad Bayern verbessert unter iOS und Android.\r\n\r\n</p>" +
"<p><b>3.0.120</b><br/>Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\nOfflineanzeige Stationen/ Räderinfo.\r\n\r\n</p>",
WhatsNewViewModel.GetWhatNextHtmlText(whatsNew.WhatsNewText));
}
[Test]
public void TestWhatsNewText_MajorUpdate_Meinkonrad_Android()
{
var whatsNew = new WhatsNew(new Version(3, 0, 120),
new Version(3, 0, 0, 114),
new Version(3, 0, 0, 114),
AppFlavor.MeinKonrad,
DevicePlatform.Android,
new WhatsNewMessages {
{
new Version(3, 0, 0, 113),
"3.0.0.113 verbessert.\r\n\r\n"
},
{
new Version(3, 0, 0, 115),
"Benutzeroberfläche verbessert.\r\n\r\n"
},
{
new Version(3, 0, 0, 116),
"sharee.bike und Lastenrad Bayern verbessert unter iOS und Android.\r\n\r\n",
new List<AppFlavor> {AppFlavor.ShareeBike, AppFlavor.LastenradBayern}
},
{
new Version(3, 0, 0, 117),
"iOS Implementierungen verbessert.\r\n\r\n",
null,
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 0, 118),
"iOS version Lastenrad Bayern verbessert.\r\n\r\n",
new List<AppFlavor> { AppFlavor.LastenradBayern },
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 0, 119),
"In Mein konrad unter Droid in 119 was anderes als unter iOS gemacht.\r\n\r\n",
new List<AppFlavor> { AppFlavor.MeinKonrad },
new List<DevicePlatform> { DevicePlatform.Android }
},
{
new Version(3, 0, 0, 119),
"In Mein konrad unter iOS in 119 was anderes als unter Droid gemacht.\r\n\r\n",
new List<AppFlavor> { AppFlavor.MeinKonrad },
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 120),
"Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\n" +
"Offlineanzeige Stationen/ Räderinfo.\r\n\r\n"
},
{
new Version(3, 0, 121),
"3.0.121 verbessert.\r\n\r\n"
} });
Assert.AreEqual(
"<p><b>3.0.0.115</b><br/>Benutzeroberfläche verbessert.\r\n\r\n</p>" +
"<p><b>3.0.0.119</b><br/>In Mein konrad unter Droid in 119 was anderes als unter iOS gemacht.\r\n\r\n</p>" +
"<p><b>3.0.120</b><br/>Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\nOfflineanzeige Stationen/ Räderinfo.\r\n\r\n</p>",
WhatsNewViewModel.GetWhatNextHtmlText(whatsNew.WhatsNewText));
}
[Test]
public void TestWhatsNewText_MajorUpdate_Meinkonrad_iOS()
{
var whatsNew = new WhatsNew(new Version(3, 0, 120),
new Version(3, 0, 0, 114),
new Version(3, 0, 0, 114),
AppFlavor.MeinKonrad,
DevicePlatform.iOS,
new WhatsNewMessages {
{
new Version(3, 0, 0, 113),
"3.0.0.113 verbessert.\r\n\r\n"
},
{
new Version(3, 0, 0, 115),
"Benutzeroberfläche verbessert.\r\n\r\n"
},
{
new Version(3, 0, 0, 116),
"sharee.bike und Lastenrad Bayern verbessert unter iOS und Android.\r\n\r\n",
new List<AppFlavor> {AppFlavor.ShareeBike, AppFlavor.LastenradBayern}
},
{
new Version(3, 0, 0, 117),
"iOS Implementierungen verbessert.\r\n\r\n",
null,
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 0, 118),
"iOS version Lastenrad Bayern verbessert.\r\n\r\n",
new List<AppFlavor> { AppFlavor.LastenradBayern },
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 0, 119),
"In Mein konrad unter Droid in 119 was anderes als unter iOS gemacht.\r\n\r\n",
new List<AppFlavor> { AppFlavor.MeinKonrad },
new List<DevicePlatform> { DevicePlatform.Android }
},
{
new Version(3, 0, 0, 119),
"In Mein konrad unter iOS in 119 was anderes als unter Droid gemacht.\r\n\r\n",
new List<AppFlavor> { AppFlavor.MeinKonrad },
new List<DevicePlatform> { DevicePlatform.iOS }
},
{
new Version(3, 0, 120),
"Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\n" +
"Offlineanzeige Stationen/ Räderinfo.\r\n\r\n"
},
{
new Version(3, 0, 121),
"3.0.121 verbessert.\r\n\r\n"
} });
Assert.AreEqual(
"<p><b>3.0.0.115</b><br/>Benutzeroberfläche verbessert.\r\n\r\n</p>" +
"<p><b>3.0.0.117</b><br/>iOS Implementierungen verbessert.\r\n\r\n</p>" +
"<p><b>3.0.0.119</b><br/>In Mein konrad unter iOS in 119 was anderes als unter Droid gemacht.\r\n\r\n</p>" +
"<p><b>3.0.120</b><br/>Verbesserung: Keine Fehler mehr beim schnellen Tippen.\r\nOfflineanzeige Stationen/ Räderinfo.\r\n\r\n</p>",
WhatsNewViewModel.GetWhatNextHtmlText(whatsNew.WhatsNewText));
}
}
}