sharee.bike-App/SharedBusinessLogic.Tests/ViewModel/Bikes/Bike/BC/TestBikeAtStationViewModel.cs

242 lines
7.3 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;
2024-04-09 12:53:23 +02:00
using SharedBusinessLogic.Tests.Framework.Model.User.Account;
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS;
using ShareeBike.Model.Device;
using ShareeBike.Model.State;
using ShareeBike.Model.User;
using ShareeBike.Model.User.Account;
using ShareeBike.ViewModel;
using ShareeBike.ViewModel.Bikes;
2022-08-30 15:42:25 +02:00
using Xamarin.Forms;
2021-07-12 21:31:46 +02:00
namespace UITest.Fixtures.ViewModel
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestBikeAtStationViewModel
{
2024-04-09 12:53:23 +02:00
private class BikeInfoMutable : ShareeBike.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
2022-09-06 16:08:19 +02:00
{
public BikeInfoMutable(
string id,
LockModel lockModel,
bool isDemo = 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),
2023-08-31 12:31:38 +02:00
new DriveMutable(),
2024-04-09 12:53:23 +02:00
ShareeBike.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
2022-09-06 16:08:19 +02:00
isDemo,
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>
[Test]
public void TestStateText_NotLoggedIn()
{
2024-04-09 12:53:23 +02:00
var l_oBike = new BikeInfoMutable("2", LockModel.ILockIt, false, new List<string> { "ShareeBike" }, WheelType.Two, TypeOfBike.Cargo);
2022-09-06 16:08:19 +02:00
var l_oStoreMock = new StoreMock(); // Account without user name, password and cookie
var l_oUser = new User(
l_oStoreMock,
l_oStoreMock.Load().Result,
"123456789"); // Device identifier
// Verify prerequisites
2024-04-09 12:53:23 +02:00
Assert.That(l_oBike.State.Value, Is.EqualTo(InUseStateEnum.Disposable));
Assert.That(l_oUser.IsLoggedIn, Is.False);
2022-09-06 16:08:19 +02:00
// Verify view model.
2024-04-09 12:53:23 +02:00
var l_oViewModel = new ShareeBike.ViewModel.Bikes.Bike.BC.BikeViewModel(
2022-09-06 16:08:19 +02:00
null,
null,
null,
null,
NSubstitute.Substitute.For<ISmartDevice>(),
null,
l_oBike,
l_oUser,
new MyBikeInUseStateInfoProvider(),
2023-03-08 13:18:54 +01:00
NSubstitute.Substitute.For<IBikesViewModel>(),
2022-09-06 16:08:19 +02:00
url => { });
2024-04-09 12:53:23 +02:00
Assert.That(l_oViewModel.Name, Is.EqualTo("2"));
Assert.That(l_oViewModel.DisplayId, Is.EqualTo(""));
Assert.That(l_oViewModel.Id, Is.EqualTo("2"));
Assert.That(l_oViewModel.StateText, Is.EqualTo("Available."));
Assert.That(l_oViewModel.StateColor, Is.EqualTo(Color.Default));
2022-09-06 16:08:19 +02:00
}
/// <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>
[Test]
public void TestStateText_LoggedIn_Reserved()
{
var l_oViewModel = TestBikeViewModel.TestStateText_LoggedIn_Reserved(
2024-04-09 12:53:23 +02:00
(bike, user) => new ShareeBike.ViewModel.Bikes.Bike.BC.BikeViewModel(
2022-09-06 16:08:19 +02:00
null,
null,
null,
null,
NSubstitute.Substitute.For<ISmartDevice>(),
null,
bike,
user,
new BikeAtStationInUseStateInfoProvider(),
2023-03-08 13:18:54 +01:00
NSubstitute.Substitute.For<IBikesViewModel>(),
2022-09-06 16:08:19 +02:00
url => { }));
2024-04-09 12:53:23 +02:00
Assert.That(l_oViewModel.StateText, Is.EqualTo("Still 15 min. reserved."));
2022-09-06 16:08:19 +02:00
}
/// <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>
[Test]
public void TestStateText_LoggedIn_ReservedWithCopriConnect()
{
var l_oViewModel = TestBikeViewModel.TestStateText_LoggedIn_ReservedWithCopriConnect(
2024-04-09 12:53:23 +02:00
(bike, user) => new ShareeBike.ViewModel.Bikes.Bike.BC.BikeViewModel(
2022-09-06 16:08:19 +02:00
null,
null,
null,
null,
NSubstitute.Substitute.For<ISmartDevice>(),
null,
bike,
user,
new BikeAtStationInUseStateInfoProvider(),
2023-03-08 13:18:54 +01:00
NSubstitute.Substitute.For<IBikesViewModel>(),
2022-09-06 16:08:19 +02:00
url => { }));
2024-04-09 12:53:23 +02:00
Assert.That(l_oViewModel.StateText, Is.EqualTo("Code 4asdfA, still 7 min. reserved."));
2022-09-06 16:08:19 +02:00
}
/// <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>
[Test]
public void TestStateText_LoggedIn_Booked()
{
var l_oViewModel = TestBikeViewModel.TestStateText_LoggedIn_Booked(
2024-04-09 12:53:23 +02:00
(bike, user) => new ShareeBike.ViewModel.Bikes.Bike.BC.BikeViewModel(
2022-09-06 16:08:19 +02:00
null,
null,
null,
null,
NSubstitute.Substitute.For<ISmartDevice>(),
null,
bike,
user,
new BikeAtStationInUseStateInfoProvider(),
2023-03-08 13:18:54 +01:00
NSubstitute.Substitute.For<IBikesViewModel>(),
2022-09-06 16:08:19 +02:00
url => { }));
2024-04-09 12:53:23 +02:00
Assert.That(
l_oViewModel.StateText, Is.EqualTo($"Code 4asdfA, rented since {new DateTime(2018, 10, 24, 21, 49, 00).ToString("dd. MMMM HH:mm")}."));
2022-09-06 16:08:19 +02:00
}
/// <summary>
2023-04-19 12:14:14 +02:00
/// Tests base class functionality by using child.
2022-09-06 16:08:19 +02:00
/// </summary>
[Test]
public void TestStateText_LoggedIn_ReservedBySomeoneElse()
{
2024-04-09 12:53:23 +02:00
var l_oBike = new BikeInfoMutable("2", LockModel.ILockIt, false, new List<string> { "ShareeBike" }, WheelType.Two, TypeOfBike.Cargo, AaRideType.NoAaRide, "Test description", "3");
2022-09-06 16:08:19 +02:00
l_oBike.State.Load(
InUseStateEnum.Reserved,
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");
2024-04-09 12:53:23 +02:00
var l_oStoreMock = new StoreMock(new Account("john@long", "123456789" /* password */, false, "987654321" /* session cookie */, new List<string> { "ShareeBike" }));
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
var l_oViewModel = new ShareeBike.ViewModel.Bikes.Bike.BC.BikeViewModel(
2022-09-06 16:08:19 +02:00
null,
null,
null,
null,
NSubstitute.Substitute.For<ISmartDevice>(),
null,
l_oBike,
new User(
l_oStoreMock,
l_oStoreMock.Load().Result,
"123456789"), // Device id
new BikeAtStationInUseStateInfoProvider(),
2023-03-08 13:18:54 +01:00
NSubstitute.Substitute.For<IBikesViewModel>(),
2022-09-06 16:08:19 +02:00
url => { });
2024-04-09 12:53:23 +02:00
Assert.That(l_oViewModel.Name, Is.EqualTo("Test description"));
Assert.That(l_oViewModel.DisplayId, Is.EqualTo("2"));
Assert.That(l_oViewModel.Id, Is.EqualTo("2"));
Assert.That(l_oViewModel.StateText, Is.EqualTo("Fahrrad bereits reserviert durch anderen Nutzer."));
Assert.That(l_oViewModel.StateColor, Is.EqualTo(Color.Red));
2022-09-06 16:08:19 +02:00
}
/// <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>
[Test]
public void TestStateText_LoggedIn_BookedBySomeoneElse()
{
2024-04-09 12:53:23 +02:00
var l_oBike = new BikeInfoMutable("2", LockModel.ILockIt, false, new List<string> { "ShareeBike" }, WheelType.Two, TypeOfBike.Cargo, AaRideType.NoAaRide, "Test description", "3");
2022-09-06 16:08:19 +02:00
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");
2024-04-09 12:53:23 +02:00
var l_oStoreMock = new StoreMock(new Account("john@long", "123456789" /* password */, false, "987654321" /* session cookie */, new List<string> { "ShareeBike" }));
2022-09-06 16:08:19 +02:00
2024-04-09 12:53:23 +02:00
var l_oViewModel = new ShareeBike.ViewModel.Bikes.Bike.BC.BikeViewModel(
2022-09-06 16:08:19 +02:00
null,
null,
null,
null,
NSubstitute.Substitute.For<ISmartDevice>(),
null,
l_oBike,
new User(
l_oStoreMock,
l_oStoreMock.Load().Result,
"123456789"),
new BikeAtStationInUseStateInfoProvider(),
2023-03-08 13:18:54 +01:00
NSubstitute.Substitute.For<IBikesViewModel>(),
2022-09-06 16:08:19 +02:00
url => { });
2024-04-09 12:53:23 +02:00
Assert.That(l_oViewModel.Name, Is.EqualTo("Test description"));
Assert.That(l_oViewModel.DisplayId, Is.EqualTo("2"));
Assert.That(l_oViewModel.Id, Is.EqualTo("2"));
Assert.That(l_oViewModel.StateText, Is.EqualTo("Fahrrad bereits gebucht durch anderen Nutzer."));
Assert.That(l_oViewModel.StateColor, Is.EqualTo(Color.Red));
2022-09-06 16:08:19 +02:00
}
}
2021-07-12 21:31:46 +02:00
}