mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-07-08 20:46:29 +02:00
Version 3.0.381
This commit is contained in:
parent
f963c0a219
commit
3a363acf3a
1525 changed files with 60589 additions and 125098 deletions
|
@ -0,0 +1,58 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.BC;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS;
|
||||
using ShareeBike.Model.State;
|
||||
|
||||
namespace SharedBusinessLogic.Tests.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,
|
||||
ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Bike bike,
|
||||
DriveMutable drive,
|
||||
bool? isDemo = DEFAULTVALUEISDEMO,
|
||||
IEnumerable<string> group = null,
|
||||
string stationId = null,
|
||||
Uri operatorUri = null,
|
||||
RentalDescription tariffDescription = null) : base(
|
||||
stateInfo,
|
||||
bike,
|
||||
drive,
|
||||
DataSource.Copri,
|
||||
isDemo,
|
||||
group,
|
||||
stationId,
|
||||
operatorUri,
|
||||
tariffDescription)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCtorBikeNull()
|
||||
{
|
||||
Assert.That(
|
||||
() => new TestBikeInfoSubClass(new StateInfo(), null, new DriveMutable()),
|
||||
Throws.ArgumentNullException);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCtorDriveNull()
|
||||
{
|
||||
Assert.That(
|
||||
() => new TestBikeInfoSubClass(new StateInfo(), new ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Bike(string.Empty, LockModel.ILockIt), null),
|
||||
Throws.ArgumentNullException);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using ShareeBike.Model.State;
|
||||
using IBikeInfo = ShareeBike.Model.Bikes.BikeInfoNS.BC.IBikeInfo;
|
||||
|
||||
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests.Bike
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestBikeInfoMutable
|
||||
{
|
||||
private class BikeInfoMutable : ShareeBike.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
|
||||
{
|
||||
public BikeInfoMutable(
|
||||
string id,
|
||||
LockModel lockModel,
|
||||
bool isDemo = false,
|
||||
IEnumerable<string> group = null,
|
||||
WheelType? wheelType = null,
|
||||
TypeOfBike? typeOfBike = null,
|
||||
AaRideType? aaRideType = null,
|
||||
string description = null,
|
||||
string stationId = null,
|
||||
string stationName = null,
|
||||
Uri operatorUri = null,
|
||||
RentalDescription tariffDescription = null,
|
||||
Func<DateTime> dateTimeProvider = null,
|
||||
IStateInfo stateInfo = null) : base(
|
||||
new ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Bike(id, lockModel, wheelType, typeOfBike, aaRideType, description),
|
||||
new ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.DriveMutable(),
|
||||
ShareeBike.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
|
||||
isDemo,
|
||||
group,
|
||||
stationId,
|
||||
stationName,
|
||||
operatorUri,
|
||||
tariffDescription,
|
||||
dateTimeProvider,
|
||||
stateInfo)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var l_oBikeInfo = new BikeInfoMutable("17", LockModel.ILockIt);
|
||||
Assert.That(l_oBikeInfo.Id, Is.EqualTo("17"));
|
||||
Assert.That(l_oBikeInfo.StationId, Is.Null);
|
||||
Assert.That(l_oBikeInfo.State.Value, Is.EqualTo(InUseStateEnum.Disposable));
|
||||
Assert.That(l_oBikeInfo.WheelType, Is.EqualTo(null));
|
||||
Assert.That(l_oBikeInfo.TypeOfBike, Is.EqualTo(null));
|
||||
|
||||
l_oBikeInfo = new BikeInfoMutable("22", LockModel.ILockIt, false, new List<string> { "ShareeBike" }, WheelType.Trike, TypeOfBike.Cargo, AaRideType.NoAaRide, "Test description", "23");
|
||||
Assert.That(l_oBikeInfo.Id, Is.EqualTo("22"));
|
||||
Assert.That(l_oBikeInfo.IsDemo, Is.False);
|
||||
Assert.That(l_oBikeInfo.StationId, Is.EqualTo("23"));
|
||||
Assert.That(l_oBikeInfo.State.Value, Is.EqualTo(InUseStateEnum.Disposable));
|
||||
Assert.That(l_oBikeInfo.WheelType, Is.EqualTo(WheelType.Trike));
|
||||
Assert.That(l_oBikeInfo.TypeOfBike, Is.EqualTo(TypeOfBike.Cargo));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using ShareeBike.Model.State;
|
||||
|
||||
namespace SharedBusinessLogic.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
class TestBikeMutable
|
||||
{
|
||||
private class BikeInfoMutable : ShareeBike.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
|
||||
{
|
||||
public BikeInfoMutable(
|
||||
string id,
|
||||
LockModel lockType,
|
||||
bool isDemo = false,
|
||||
IEnumerable<string> group = null,
|
||||
WheelType? wheelType = null,
|
||||
TypeOfBike? typeOfBike = null,
|
||||
AaRideType? aaRideType = null,
|
||||
string description = null,
|
||||
string stationId = null,
|
||||
string stationName = null,
|
||||
Uri operatorUri = null,
|
||||
RentalDescription tariffDescription = null,
|
||||
Func<DateTime> dateTimeProvider = null,
|
||||
IStateInfo stateInfo = null) : base(
|
||||
new Bike(id, lockType, wheelType, typeOfBike, aaRideType, description),
|
||||
new ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.DriveMutable(),
|
||||
ShareeBike.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
|
||||
isDemo,
|
||||
group,
|
||||
stationId,
|
||||
stationName,
|
||||
operatorUri,
|
||||
tariffDescription,
|
||||
dateTimeProvider,
|
||||
stateInfo)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable(
|
||||
"42",
|
||||
LockModel.ILockIt,
|
||||
false,
|
||||
new List<string> { "ShareeBike" },
|
||||
WheelType.Two,
|
||||
TypeOfBike.Cargo);
|
||||
|
||||
Assert.That(l_oBike.Id, Is.EqualTo("42"));
|
||||
Assert.That(l_oBike.IsDemo, Is.False);
|
||||
Assert.That(l_oBike.WheelType, Is.EqualTo(WheelType.Two));
|
||||
Assert.That(l_oBike.TypeOfBike, Is.EqualTo(TypeOfBike.Cargo));
|
||||
Assert.That(l_oBike.State.Value, Is.EqualTo(InUseStateEnum.Disposable));
|
||||
Assert.That(l_oBike.StationId, Is.Null);
|
||||
|
||||
l_oBike = new BikeInfoMutable(
|
||||
"17",
|
||||
LockModel.ILockIt,
|
||||
true,
|
||||
new List<string> { "ShareeBike" },
|
||||
WheelType.Mono,
|
||||
TypeOfBike.Allround,
|
||||
AaRideType.NoAaRide,
|
||||
"Test description",
|
||||
"1");
|
||||
|
||||
Assert.That(l_oBike.Id, Is.EqualTo("17"));
|
||||
Assert.That(l_oBike.IsDemo, Is.True);
|
||||
Assert.That(l_oBike.WheelType, Is.EqualTo(WheelType.Mono));
|
||||
Assert.That(l_oBike.TypeOfBike, Is.EqualTo(TypeOfBike.Allround));
|
||||
Assert.That(l_oBike.State.Value, Is.EqualTo(InUseStateEnum.Disposable));
|
||||
Assert.That(l_oBike.StationId, Is.EqualTo("1"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestToString()
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable("3", LockModel.ILockIt, false, new List<string> { "ShareeBike" }, WheelType.Two, TypeOfBike.Cargo, dateTimeProvider: () => new DateTime(1970, 1, 1));
|
||||
|
||||
Assert.That(
|
||||
l_oBike.ToString(), Is.EqualTo("Id=3, wheel(s)=Two, type=Cargo, demo=False, state=Disposable, location=On the road."));
|
||||
|
||||
l_oBike = new BikeInfoMutable("3", LockModel.ILockIt, true, new List<string> { "ShareeBike" }, WheelType.Trike, TypeOfBike.Allround, AaRideType.NoAaRide, "Test description", "5", dateTimeProvider: () => new DateTime(1970, 1, 1));
|
||||
Assert.That(
|
||||
l_oBike.ToString(), Is.EqualTo("Id=3, wheel(s)=Trike, type=Allround, demo=True, state=Disposable, location=Station 5."));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ShareeBike.Model.Bike;
|
||||
using ShareeBike.Model.State;
|
||||
|
||||
using BikeInfoMutable = ShareeBike.Model.Bike.BC.BikeInfoMutable;
|
||||
|
||||
namespace SharedBusinessLogic.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Exclude from build beause serialization... see below.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class TestBikeSerializeJSON
|
||||
{
|
||||
[Test, Ignore("Disabled because serialization does no more work due to inheritance since commit ec14b93b.")]
|
||||
public void TestConstruct_SerializeJSON_Disposable()
|
||||
{
|
||||
// Create object to test.
|
||||
var l_oBikeSource = new BikeInfoMutable(3, false, new List<string> { "ShareeBike" }, WheelType.Two, TypeOfBike.Cargo, p_oDateTimeProvider: () => new DateTime(1970, 1, 1));
|
||||
|
||||
// Verify prerequisites
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeSource.State.Value);
|
||||
Assert.IsNull(l_oBikeSource.State.MailAddress);
|
||||
Assert.IsNull(l_oBikeSource.State.Code);
|
||||
Assert.IsNull(l_oBikeSource.State.From);
|
||||
|
||||
// Serialize object and verify.
|
||||
var l_oDetected = JsonConvert.SerializeObject(l_oBikeSource, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
|
||||
const string EXPECTED = @"
|
||||
{
|
||||
""Id"": 3,
|
||||
""CurrentStation"": null,
|
||||
""WheelType"": 1,
|
||||
""TypeOfBike"": 1,
|
||||
""State"": {
|
||||
""StateInfoObject"": {
|
||||
""$type"": ""ShareeBike.Model.State.StateAvailableInfo, SharedBusinessLogic""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
Assert.AreEqual(
|
||||
TestHelper.PrepareXmlForStringCompare(EXPECTED),
|
||||
TestHelper.PrepareXmlForStringCompare(l_oDetected));
|
||||
|
||||
// Deserialize object.
|
||||
var l_oBikeTarget = JsonConvert.DeserializeObject<BikeInfoMutable>(l_oDetected, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
|
||||
|
||||
// Verify state.
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, l_oBikeTarget.State.Value);
|
||||
Assert.IsNull(l_oBikeTarget.State.MailAddress);
|
||||
Assert.IsNull(l_oBikeTarget.State.Code);
|
||||
Assert.IsNull(l_oBikeTarget.State.From);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using SharedBusinessLogic.Tests.Framework.Model.User.Account;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using ShareeBike.Model.State;
|
||||
using ShareeBike.Model.User;
|
||||
using ShareeBike.Model.User.Account;
|
||||
using ShareeBike.Repository;
|
||||
using ShareeBike.ViewModel.Bikes.Bike;
|
||||
using static ShareeBike.Repository.CopriCallsMemory;
|
||||
|
||||
namespace UITest.Fixtures.ViewModel
|
||||
{
|
||||
public class TestBikeViewModel
|
||||
{
|
||||
private class BikeInfoMutable : ShareeBike.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable
|
||||
{
|
||||
public BikeInfoMutable(
|
||||
string id,
|
||||
LockModel lockModel,
|
||||
bool pisDemo = false,
|
||||
IEnumerable<string> group = null,
|
||||
WheelType? wheelType = null,
|
||||
TypeOfBike? typeOfBike = null,
|
||||
AaRideType? aaRideType = 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, aaRideType, description),
|
||||
new ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.DriveMutable(),
|
||||
ShareeBike.Model.Bikes.BikeInfoNS.BC.DataSource.Copri,
|
||||
pisDemo,
|
||||
group,
|
||||
stationId,
|
||||
stationName,
|
||||
operatorUri,
|
||||
null,
|
||||
dateTimeProvider,
|
||||
stateInfo)
|
||||
{
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Tests base class functionality by using child.
|
||||
/// </summary>
|
||||
public static BikeViewModelBase TestStateText_LoggedIn_Reserved(Func<ShareeBike.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable, User, BikeViewModelBase> p_oFactory)
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable(
|
||||
"2",
|
||||
LockModel.ILockIt,
|
||||
false,
|
||||
new List<string> { "ShareeBike" },
|
||||
WheelType.Trike,
|
||||
TypeOfBike.Cargo,
|
||||
AaRideType.NoAaRide,
|
||||
"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.
|
||||
TimeSpan.FromMinutes(15),
|
||||
"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> { "ShareeBike" }));
|
||||
var l_oUser = new User(
|
||||
l_oStoreMock,
|
||||
l_oStoreMock.Load().Result,
|
||||
"123456789");
|
||||
|
||||
// Verify prerequisites
|
||||
Assert.That(l_oBike.State.Value, Is.EqualTo(InUseStateEnum.Reserved));
|
||||
Assert.That(l_oUser.IsLoggedIn, Is.True);
|
||||
Assert.That(l_oUser.Mail, Is.EqualTo(l_oBike.State.MailAddress));
|
||||
|
||||
// Do not update from Copri
|
||||
var l_oViewModel = p_oFactory(l_oBike, l_oUser);
|
||||
|
||||
return l_oViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests base class functionality by using child.
|
||||
/// </summary>
|
||||
public static BikeViewModelBase TestStateText_LoggedIn_ReservedWithCopriConnect(Func<ShareeBike.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable, User, BikeViewModelBase> p_oFactory)
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable(
|
||||
"2",
|
||||
LockModel.ILockIt,
|
||||
false,
|
||||
new List<string> { "ShareeBike" },
|
||||
WheelType.Trike,
|
||||
TypeOfBike.Cargo,
|
||||
AaRideType.NoAaRide,
|
||||
"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),
|
||||
TimeSpan.FromMinutes(15),
|
||||
"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> { "ShareeBike" }));
|
||||
var l_oUser = new User(
|
||||
l_oStoreMock, // Mocks account store functionality.
|
||||
l_oStoreMock.Load().Result,
|
||||
"123456789");
|
||||
|
||||
// Verify prerequisites
|
||||
Assert.That(l_oBike.State.Value, Is.EqualTo(InUseStateEnum.Reserved));
|
||||
Assert.That(l_oUser.IsLoggedIn, Is.True);
|
||||
Assert.That(l_oUser.Mail, Is.EqualTo(l_oBike.State.MailAddress));
|
||||
|
||||
var l_oViewModel = p_oFactory(l_oBike, l_oUser); // Bikes collection mock.
|
||||
|
||||
return l_oViewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests base class functionality by using child.
|
||||
/// </summary>
|
||||
public static BikeViewModelBase TestStateText_LoggedIn_Booked(Func<ShareeBike.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable, User, BikeViewModelBase> p_oFactory)
|
||||
{
|
||||
var l_oBike = new BikeInfoMutable("2", LockModel.ILockIt, false, new List<string> { "ShareeBike" }, WheelType.Two, TypeOfBike.Cargo, AaRideType.NoAaRide, "Test description", "3");
|
||||
|
||||
// Update from Copri.
|
||||
l_oBike.State.Load(
|
||||
InUseStateEnum.Booked,
|
||||
new DateTime(2017, 10, 24, 21, 49, 3),
|
||||
TimeSpan.FromMinutes(15),
|
||||
"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> { "ShareeBike" }));
|
||||
var l_oUser = new User(
|
||||
l_oStoreMock,
|
||||
l_oStoreMock.Load().Result,
|
||||
"123456789"); // Device id
|
||||
|
||||
// Verify prerequisites
|
||||
Assert.That(l_oBike.State.Value, Is.EqualTo(InUseStateEnum.Booked));
|
||||
Assert.That(l_oUser.IsLoggedIn, Is.True);
|
||||
Assert.That(l_oUser.Mail, Is.EqualTo(l_oBike.State.MailAddress));
|
||||
|
||||
var l_oViewModel = p_oFactory(l_oBike, l_oUser);
|
||||
|
||||
return l_oViewModel;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue