sharee.bike-App/TestShareeLib/Model/Bikes/BikeInfoNS/BC/TestBikeViewModel.cs

167 lines
5.2 KiB
C#
Raw Normal View History

2023-01-18 14:22:51 +01:00
using System;
2022-08-30 15:42:25 +02:00
using System.Collections.Generic;
using NUnit.Framework;
using TestFramework.Model.User.Account;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.State;
2021-07-12 21:31:46 +02:00
using TINK.Model.User;
using TINK.Model.User.Account;
using TINK.Repository;
using TINK.ViewModel.Bikes.Bike;
2022-08-30 15:42:25 +02:00
using static TINK.Repository.CopriCallsMemory;
2021-07-12 21:31:46 +02:00
namespace UITest.Fixtures.ViewModel
{
2022-09-06 16:08:19 +02:00
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,
2023-04-19 12:14:14 +02:00
AaRideType? aaRideType = null,
2022-09-06 16:08:19 +02:00
string description = null,
string stationId = null,
string stationName = null,
Uri operatorUri = null,
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null) : base(
2023-04-19 12:14:14 +02:00
new Bike(id, lockModel, wheelType, typeOfBike, aaRideType, description),
2022-09-06 16:08:19 +02:00
new TINK.Model.Bikes.BikeInfoNS.DriveNS.Drive(),
2023-01-18 14:22:51 +01:00
TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
2022-09-06 16:08:19 +02:00
pisDemo,
group,
stationId,
stationName,
operatorUri,
null,
dateTimeProvider,
stateInfo)
{
}
}
/// <summary>
2023-06-06 12:00:24 +02:00
/// Tests base class functionality by using child.
2022-09-06 16:08:19 +02:00
/// </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,
2023-04-19 12:14:14 +02:00
AaRideType.NoAaRide,
2022-09-06 16:08:19 +02:00
"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.
2023-06-06 12:00:24 +02:00
TimeSpan.FromMinutes(15),
2022-09-06 16:08:19 +02:00
"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>
2023-06-06 12:00:24 +02:00
/// Tests base class functionality by using child.
2022-09-06 16:08:19 +02:00
/// </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,
2023-04-19 12:14:14 +02:00
AaRideType.NoAaRide,
2022-09-06 16:08:19 +02:00
"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),
2023-06-06 12:00:24 +02:00
TimeSpan.FromMinutes(15),
2022-09-06 16:08:19 +02:00
"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>
2023-06-06 12:00:24 +02:00
/// Tests base class functionality by using child.
2022-09-06 16:08:19 +02:00
/// </summary>
public static BikeViewModelBase TestStateText_LoggedIn_Booked(Func<TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable, User, BikeViewModelBase> p_oFactory)
{
2023-04-19 12:14:14 +02:00
var l_oBike = new BikeInfoMutable("2", LockModel.ILockIt, false, new List<string> { "TINK" }, WheelType.Two, TypeOfBike.Cargo, AaRideType.NoAaRide, "Test description", "3");
2022-09-06 16:08:19 +02:00
// Update from Copri.
l_oBike.State.Load(
InUseStateEnum.Booked,
new DateTime(2017, 10, 24, 21, 49, 3),
2023-06-06 12:00:24 +02:00
TimeSpan.FromMinutes(15),
2022-09-06 16:08:19 +02:00
"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;
}
}
2021-07-12 21:31:46 +02:00
}