Version 3.0.362

This commit is contained in:
Anja 2023-04-05 15:02:10 +02:00
parent cba4da9357
commit 4ff3307997
128 changed files with 3954 additions and 3193 deletions

View file

@ -0,0 +1,160 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using TestFramework.Model.User.Account;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.State;
using TINK.Model.User;
using TINK.Model.User.Account;
using TINK.Repository;
using TINK.ViewModel.Bikes.Bike;
using static TINK.Repository.CopriCallsMemory;
namespace UITest.Fixtures.ViewModel
{
public class TestBikeViewModel
{
private class BikeInfoMutable : TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
{
public BikeInfoMutable(
string id,
LockModel lockModel,
bool pisDemo = false,
IEnumerable<string> group = null,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null,
string stationId = null,
string stationName = null,
Uri operatorUri = null,
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null) : base(
new Bike(id, lockModel, wheelType, typeOfBike, description),
new TINK.Model.Bikes.BikeInfoNS.DriveNS.Drive(),
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
pisDemo,
group,
stationId,
stationName,
operatorUri,
null,
dateTimeProvider,
stateInfo)
{
}
}
/// <summary>
/// Tests base class functionaltiy by using child.
/// </summary>
public static BikeViewModelBase TestStateText_LoggedIn_Reserved(Func<TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable, User, BikeViewModelBase> p_oFactory)
{
var l_oBike = new BikeInfoMutable(
"2",
LockModel.ILockIt,
false,
new List<string> { "TINK" },
WheelType.Trike,
TypeOfBike.Cargo,
"Test description",
"3",
"Radstation",
null,
() => new DateTime(1980, 1, 1)); // Now time stamp
// Update state from Copri.
l_oBike.State.Load(
InUseStateEnum.Reserved, // Copri acknowledges state reserved.
new DateTime(1980, 1, 1), // Date when bike was booked.
"ragu@gnu-systems.de"); // Owner from Copri.
var l_oStoreMock = new StoreMock(new Account("ragu@gnu-systems.de", "123456789" /* password */, false, "987654321" /* session cookie */, new List<string> { "TINK" }));
var l_oUser = new User(
l_oStoreMock,
l_oStoreMock.Load().Result,
"123456789");
// Verify prerequisites
Assert.AreEqual(InUseStateEnum.Reserved, l_oBike.State.Value);
Assert.IsTrue(l_oUser.IsLoggedIn);
Assert.AreEqual(l_oBike.State.MailAddress, l_oUser.Mail);
// Do not update from Copri
var l_oViewModel = p_oFactory(l_oBike, l_oUser);
return l_oViewModel;
}
/// <summary>
/// Tests base class functionaltiy by using child.
/// </summary>
public static BikeViewModelBase TestStateText_LoggedIn_ReservedWithCopriConnect(Func<TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable, User, BikeViewModelBase> p_oFactory)
{
var l_oBike = new BikeInfoMutable(
"2",
LockModel.ILockIt,
false,
new List<string> { "TINK" },
WheelType.Trike,
TypeOfBike.Cargo,
"Test description",
"3",
"Radstation",
null,
() => (new DateTime(1980, 1, 1)).Add(new TimeSpan(0, 8, 0)));
// Update state from Copri.
l_oBike.State.Load(
InUseStateEnum.Reserved, // Copri acknowledges state reserved.
new DateTime(1980, 1, 1),
"ragu@gnu-systems.de", // Owner from Copri.
"4asdfA"); // Reservation code from Copri
var l_oStoreMock = new StoreMock(new Account("ragu@gnu-systems.de", "123456789" /* password */, false, "987654321" /* session cookie */, new List<string> { "TINK" }));
var l_oUser = new User(
l_oStoreMock, // Mocks account store functionality.
l_oStoreMock.Load().Result,
"123456789");
// Verify prerequisites
Assert.AreEqual(InUseStateEnum.Reserved, l_oBike.State.Value);
Assert.IsTrue(l_oUser.IsLoggedIn);
Assert.AreEqual(l_oBike.State.MailAddress, l_oUser.Mail);
var l_oViewModel = p_oFactory(l_oBike, l_oUser); // Bikes collection mock.
return l_oViewModel;
}
/// <summary>
/// Tests base class functionaltiy by using child.
/// </summary>
public static BikeViewModelBase TestStateText_LoggedIn_Booked(Func<TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable, User, BikeViewModelBase> p_oFactory)
{
var l_oBike = new BikeInfoMutable("2", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Cargo, "Test description", "3");
// Update from Copri.
l_oBike.State.Load(
InUseStateEnum.Booked,
new DateTime(2017, 10, 24, 21, 49, 3),
"ragu@gnu-systems.de",
"4asdfA");
var l_oCopriServer = new CopriCallsMemory("MyMerchId", SampleSets.Set1, 1);
var l_oStoreMock = new StoreMock(new Account("ragu@gnu-systems.de", "123456789" /* password */, false, "987654321" /* session cookie */, new List<string> { "TINK" }));
var l_oUser = new User(
l_oStoreMock,
l_oStoreMock.Load().Result,
"123456789"); // Device id
// Verify prerequisites
Assert.AreEqual(InUseStateEnum.Booked, l_oBike.State.Value);
Assert.IsTrue(l_oUser.IsLoggedIn);
Assert.AreEqual(l_oBike.State.MailAddress, l_oUser.Mail);
var l_oViewModel = p_oFactory(l_oBike, l_oUser);
return l_oViewModel;
}
}
}

View file

@ -1,7 +1,8 @@
using System;
using System;
using System.Linq;
using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
using TINK.Services.Geolocation;
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
{
@ -62,5 +63,60 @@ namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
Assert.IsTrue((new byte[] { 1, 12 }).SequenceEqual(lockInfo.Seed));
Assert.AreEqual(LockingState.Closed, lockInfo.State);
}
[Test]
public void TestLastLockingStateChange()
=> Assert.That(
new LockInfoMutable(1, new Guid(), null, null, null, LockingState.Open, () => new DateTime(2023, 03, 13)).LastLockingStateChange,
Is.Null);
[Test]
public void TestLastLockingStateChangeCangeCtor()
{
var lockInfo = new LockInfoMutable(1, new Guid(), null, null, null, LockingState.Open, () => new DateTime(2023, 03, 13));
lockInfo.State = LockingState.Closed;
Assert.That(
lockInfo.LastLockingStateChange,
Is.EqualTo(new DateTime(2023, 03, 13)));
}
[Test]
public void TestLocationCtor()
=> Assert.That(
new LockInfoMutable(1, new Guid(), null, null, null, LockingState.Open, () => new DateTime(2023, 03, 13)).Location,
Is.Null);
[Test]
public void TestLocation()
{
var lockInfo = new LockInfoMutable(1, new Guid(), null, null, null, LockingState.Open, () => new DateTime(2023, 03, 13));
lockInfo.Location = new Geolocation.Builder { Latitude = 47.99, Longitude = 7.78}.Build();
// Veryfy that location is kept because bike might be returned later.
Assert.That(
lockInfo.Location.Latitude,
Is.EqualTo(47.99).Within(0.001));
Assert.That(
lockInfo.Location.Longitude,
Is.EqualTo(7.78).Within(0.001));
}
[Test]
public void TestLocationStateChange()
{
var lockInfo = new LockInfoMutable(1, new Guid(), null, null, null, LockingState.Open, () => new DateTime(2023, 03, 13));
lockInfo.Location = new Geolocation.Builder { Latitude = 47.99, Longitude = 7.78 }.Build();
lockInfo.State = LockingState.Closed;
// Veryfy that location is kept because bike might be returned later.
Assert.That(
lockInfo.Location,
Is.Null);
}
}
}