mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-21 21:46:27 +02:00
Version 3.0.361
This commit is contained in:
parent
faf68061f4
commit
cba4da9357
88 changed files with 1119 additions and 1502 deletions
|
@ -0,0 +1,161 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using TestFramework.Model.Services.Geolocation;
|
||||
using TestFramework.Services.BluetoothLock;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
|
||||
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
|
||||
using TINK.Model.Device;
|
||||
using TINK.Model.State;
|
||||
using TINK.Model.User;
|
||||
using TINK.ViewModel.Bikes;
|
||||
using TINK.ViewModel.Bikes.Bike.BluetoothLock;
|
||||
using TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.Bike.BluetoothLock
|
||||
{
|
||||
/// <summary>
|
||||
/// Moved to TestShareeLib (.Net Core)
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class TestRequestHandlerFactory
|
||||
{
|
||||
[Test]
|
||||
public void TestCreate()
|
||||
{
|
||||
// Verify handler for disposable bike.
|
||||
var bike = new BikeInfoMutable(
|
||||
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "12"),
|
||||
"My Station Name");
|
||||
Assert.AreEqual(InUseStateEnum.Disposable, bike.State.Value);
|
||||
Assert.AreEqual(LockingState.UnknownDisconnected, bike.LockInfo.State);
|
||||
Assert.AreEqual(
|
||||
typeof(DisposableDisconnected),
|
||||
RequestHandlerFactory.Create(
|
||||
bike,
|
||||
() => false, // isConnectedDelegate
|
||||
(connected) => null, // connectorFactory
|
||||
new GeolocationMock(), // geolocation
|
||||
new LocksServiceMock(), // LockService
|
||||
null, // viewUpdateManager
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null /* viewService */ ,
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
NSubstitute.Substitute.For<IUser>()).GetType());
|
||||
|
||||
// Verify handler for requested bike with state unknown.
|
||||
bike = new BikeInfoMutable(
|
||||
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 0 /* lock Id */, new Guid(), /*K User*/ null, /*K Admin*/ null, /*K Seed*/ null, new DateTime(2020, 1, 1), "a@b.com", "12", null, null, () => new DateTime(2020, 1, 1), false, new List<string>()),
|
||||
"My Station Name");
|
||||
Assert.AreEqual(
|
||||
typeof(ReservedDisconnected),
|
||||
RequestHandlerFactory.Create(
|
||||
bike,
|
||||
() => false, // isConnectedDelegate
|
||||
(connected) => null, // connectorFactory
|
||||
new GeolocationMock(), // geolocation
|
||||
new LocksServiceMock(), // LockService
|
||||
null, // viewUpdateManager
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null /* viewService */,
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
NSubstitute.Substitute.For<IUser>()).GetType());
|
||||
|
||||
// Verify handler for requested bike with state closed.
|
||||
bike = new BikeInfoMutable(
|
||||
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 0 /* lock Id*/, new Guid(), null, null, null, new DateTime(2020, 1, 1), "a@b.com", "12", null, null, () => new DateTime(2020, 1, 1), false, new List<string>()),
|
||||
"My Station Name");
|
||||
bike.LockInfo.State = LockingState.Closed;
|
||||
Assert.AreEqual(
|
||||
typeof(ReservedClosed),
|
||||
RequestHandlerFactory.Create(
|
||||
bike,
|
||||
() => false, // isConnectedDelegate
|
||||
(connected) => null, // connectorFactory
|
||||
new GeolocationMock(), // geolocation
|
||||
new LocksServiceMock(), // LockService
|
||||
null, // viewUpdateManager
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null /* viewService */,
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
NSubstitute.Substitute.For<IUser>()).GetType());
|
||||
|
||||
// Verify handler for requested bike with state open.
|
||||
bike = new BikeInfoMutable(
|
||||
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 0 /* lock Id*/, new Guid(), null /* user key */, null, null, new DateTime(2020, 1, 1), "a@b.com", "12", null, null, () => new DateTime(2020, 1, 1), false, new List<string>()),
|
||||
"My Station Name");
|
||||
bike.LockInfo.State = LockingState.Open;
|
||||
Assert.AreEqual(
|
||||
typeof(ReservedOpen),
|
||||
RequestHandlerFactory.Create(
|
||||
bike,
|
||||
() => false, // isConnectedDelegate
|
||||
(connected) => null, // connectorFactory
|
||||
new GeolocationMock(), // geolocation
|
||||
new LocksServiceMock(), // LockService
|
||||
null, // viewUpdateManager
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null /* viewService */,
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
NSubstitute.Substitute.For<IUser>()).GetType());
|
||||
|
||||
// Verify handler for booked bike with state closed.
|
||||
bike = new BikeInfoMutable(
|
||||
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 0 /* lock Id*/, new Guid(), null, null, null, new System.DateTime(2020, 1, 1), "a@b.com", "12", null /*operator uri*/, null, false, new List<string>()),
|
||||
"My Station Name");
|
||||
bike.LockInfo.State = LockingState.Closed;
|
||||
Assert.AreEqual(
|
||||
typeof(BookedClosed),
|
||||
RequestHandlerFactory.Create(
|
||||
bike,
|
||||
() => false, // isConnectedDelegate
|
||||
(connected) => null, // connectorFactory
|
||||
new GeolocationMock(), // geolocation
|
||||
new LocksServiceMock(), // LockService
|
||||
null, // viewUpdateManager
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null /* viewService */,
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
NSubstitute.Substitute.For<IUser>()).GetType());
|
||||
|
||||
// Verify handler for booked bike with state open.
|
||||
bike = new BikeInfoMutable(
|
||||
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 0 /* lock Id*/, new Guid(), null, null, null, new System.DateTime(2020, 1, 1), "a@b.com", "12", null /*operator uri*/, null, false, new List<string>()),
|
||||
"My Station Name");
|
||||
bike.LockInfo.State = LockingState.Open;
|
||||
Assert.AreEqual(
|
||||
typeof(BookedOpen),
|
||||
RequestHandlerFactory.Create(
|
||||
bike,
|
||||
() => false, // isConnectedDelegate
|
||||
(connected) => null, // connectorFactory
|
||||
new GeolocationMock(), // geolocation
|
||||
new LocksServiceMock(), // LockService
|
||||
null, // viewUpdateManager
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null /* viewService */,
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
NSubstitute.Substitute.For<IUser>()).GetType());
|
||||
|
||||
// Verify handler for booked bike with state unknown.
|
||||
bike = new BikeInfoMutable(
|
||||
new BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("22", LockModel.ILockIt, WheelType.Mono, TypeOfBike.Allround), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 0 /* lock Id*/, new Guid(), null, null, null, new System.DateTime(2020, 1, 1), "a@b.com", "12", null /*operator uri*/, null, false, new List<string>()),
|
||||
"My Station Name");
|
||||
|
||||
Assert.AreEqual(
|
||||
typeof(BookedDisconnected),
|
||||
RequestHandlerFactory.Create(
|
||||
bike,
|
||||
() => false, // isConnectedDelegate
|
||||
(connected) => null, // connectorFactory
|
||||
new GeolocationMock(), // geolocation
|
||||
new LocksServiceMock(), // LockService
|
||||
null, // viewUpdateManager
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null /* viewService */,
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
NSubstitute.Substitute.For<IUser>()).GetType());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using TestFramework.Model.Services.Geolocation;
|
||||
using TestFramework.Services.BluetoothLock;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BC;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
|
||||
using TINK.Model.Device;
|
||||
using TINK.Model.User;
|
||||
using TINK.ViewModel;
|
||||
using TINK.ViewModel.Bikes;
|
||||
using TINK.ViewModel.Bikes.Bike;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.ViewModel
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestBikeViewModelFactory
|
||||
{
|
||||
[Test]
|
||||
public void TestCreateBluetoothLock()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
typeof(TINK.ViewModel.Bikes.Bike.BluetoothLock.BikeViewModel),
|
||||
BikeViewModelFactory.Create(
|
||||
() => false, // Is connected delegate,
|
||||
(isconnected) => null, // connectorFactory
|
||||
new GeolocationMock(), // geolocation
|
||||
new LocksServiceMock(), // lock service
|
||||
(index) => { }, // bikeRemoveDelegate
|
||||
null, // viewUpdateManager
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null, // viewService
|
||||
new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfoMutable(new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("42", LockModel.ILockIt), new Drive(), DataSource.Copri, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "42"), "My Station Name"),
|
||||
NSubstitute.Substitute.For<IUser>(), // user
|
||||
NSubstitute.Substitute.For<IInUseStateInfoProvider>(),
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
url => { }).GetType()); // stateInfoProvider
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateCopri()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
typeof(TINK.ViewModel.Bikes.Bike.CopriLock.BikeViewModel),
|
||||
BikeViewModelFactory.Create(
|
||||
() => false, // Is connected delegate,
|
||||
(isconnected) => null, // connectorFactory
|
||||
new GeolocationMock(), // geolocation
|
||||
new LocksServiceMock(), // lock service
|
||||
(index) => { }, // bikeRemoveDelegate
|
||||
null, // viewUpdateManager
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null, // viewService
|
||||
new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfoMutable(new TINK.Model.Bikes.BikeInfoNS.CopriLock.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("42", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, "17", new TINK.Model.Bikes.BikeInfoNS.CopriLock.LockInfo.Builder { State = TINK.Model.Bikes.BikeInfoNS.CopriLock.LockingState.Closed }.Build()), "My Station Name"),
|
||||
NSubstitute.Substitute.For<IUser>(), // user
|
||||
NSubstitute.Substitute.For<IInUseStateInfoProvider>(),
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
url => { }).GetType()); // stateInfoProvider
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateUnsupported()
|
||||
{
|
||||
Assert.That(
|
||||
BikeViewModelFactory.Create(
|
||||
() => false, // Is connected delegate,
|
||||
(isconnected) => null, // connectorFactory
|
||||
new GeolocationMock(), // geolocation
|
||||
new LocksServiceMock(), // lock service
|
||||
(index) => { }, // bikeRemoveDelegate
|
||||
null, // viewUpdateManager
|
||||
NSubstitute.Substitute.For<ISmartDevice>(),
|
||||
null, // viewService
|
||||
new TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable(new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("42", TINK.Model.Bikes.BikeInfoNS.BikeNS.LockModel.ILockIt), new Drive(), DataSource.Copri, 5200544, new Guid("00000000-0000-0000-0000-000000000001"), "42"), "My Station Name"),
|
||||
NSubstitute.Substitute.For<IUser>(), // user
|
||||
NSubstitute.Substitute.For<IInUseStateInfoProvider>(),
|
||||
NSubstitute.Substitute.For<IBikesViewModel>(),
|
||||
url => { }),
|
||||
Is.Null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1109,7 +1109,7 @@ namespace TestTINKLib.Fixtures.ObjectTests.ViewModel
|
|||
|
||||
await bikesAtStation.OnAppearingOrRefresh();
|
||||
|
||||
//Assert.AreEqual("Offline.", bikesAtStation.StatusInfoText);
|
||||
Assert.AreEqual("Offline.", bikesAtStation.StatusInfoText);
|
||||
|
||||
// Verify list of bikes
|
||||
Assert.AreEqual(2, bikesAtStation.Count); // Count of bikes was 3. There is no more bike with id 26.
|
||||
|
|
23
TestShareeLib/ViewModel/Info/TestInfoViewModel.cs
Normal file
23
TestShareeLib/ViewModel/Info/TestInfoViewModel.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using NUnit.Framework;
|
||||
using TINK.ViewModel.Info;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.ViewModel.Info
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestInfoViewModel
|
||||
{
|
||||
[Test]
|
||||
public void TestOnAppearing()
|
||||
{
|
||||
var viewModel = new InfoPageViewModel(
|
||||
"Hosti",
|
||||
"agbResourcePath",
|
||||
"privacyResourcePath",
|
||||
"impressResourcePath",
|
||||
false,
|
||||
(url) => string.Empty,
|
||||
() => null,
|
||||
(resourceUrls) => { });
|
||||
}
|
||||
}
|
||||
}
|
26
TestShareeLib/ViewModel/Map/TestFilterCollection.cs
Normal file
26
TestShareeLib/ViewModel/Map/TestFilterCollection.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model;
|
||||
using TINK.ViewModel.Map;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestFilterCollection
|
||||
{
|
||||
[Test]
|
||||
public void TestGetGroup()
|
||||
{
|
||||
var l_oFilterColl = new GroupFilterMapPage(new Dictionary<string, FilterState>
|
||||
{
|
||||
{ "TINK", FilterState.On },
|
||||
{ "Konrad", FilterState.On }
|
||||
});
|
||||
|
||||
var l_oFilterGroup = l_oFilterColl.GetGroup();
|
||||
Assert.AreEqual(2, l_oFilterGroup.Count);
|
||||
Assert.AreEqual("TINK", l_oFilterGroup[0]);
|
||||
Assert.AreEqual("Konrad", l_oFilterGroup[1]);
|
||||
}
|
||||
}
|
||||
}
|
43
TestShareeLib/ViewModel/Map/TestMapPageFilter.cs
Normal file
43
TestShareeLib/ViewModel/Map/TestMapPageFilter.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.ViewModel.Map;
|
||||
|
||||
namespace UITest.Fixtures.ObjectTests.Map
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestMapPageFilter
|
||||
{
|
||||
[Test]
|
||||
public void TestCurrentFilter_Empty()
|
||||
{
|
||||
var l_oFilter = new TinkKonradToggleViewModel(null);
|
||||
Assert.IsEmpty(l_oFilter.CurrentFilter);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCurrentFilter()
|
||||
{
|
||||
var l_oFilter = new TinkKonradToggleViewModel(new GroupFilterMapPage(new Dictionary<string, FilterState> { { $"HOM_{FilterHelper.CARGOBIKE}", FilterState.On }, { "Konrad", FilterState.Off } }));
|
||||
|
||||
Assert.AreEqual($"HOM_{FilterHelper.CARGOBIKE}", l_oFilter.CurrentFilter);
|
||||
|
||||
l_oFilter = new TinkKonradToggleViewModel(new GroupFilterMapPage(new Dictionary<string, FilterState> { { $"HOM_{FilterHelper.CARGOBIKE}", FilterState.Off }, { $"HOM_{FilterHelper.CITYBIKE}", FilterState.On } }));
|
||||
|
||||
Assert.AreEqual($"HOM_{FilterHelper.CITYBIKE}", l_oFilter.CurrentFilter);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIsToggleVisible()
|
||||
{
|
||||
var l_oFilter = new TinkKonradToggleViewModel(new GroupFilterMapPage(new Dictionary<string, FilterState> { { $"HOM_{FilterHelper.CARGOBIKE}", FilterState.On } }));
|
||||
|
||||
Assert.IsFalse(l_oFilter.IsToggleVisible);
|
||||
|
||||
l_oFilter = new TinkKonradToggleViewModel(new GroupFilterMapPage(new Dictionary<string, FilterState> { { $"HOM_{FilterHelper.CARGOBIKE}", FilterState.Off }, { $"HOM_{FilterHelper.CITYBIKE}", FilterState.On } }));
|
||||
|
||||
Assert.IsTrue(l_oFilter.IsToggleVisible);
|
||||
}
|
||||
}
|
||||
}
|
595
TestShareeLib/ViewModel/Map/TestMapPageViewModel.cs
Normal file
595
TestShareeLib/ViewModel/Map/TestMapPageViewModel.cs
Normal file
|
@ -0,0 +1,595 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using Plugin.BLE.Abstractions.Contracts;
|
||||
using TestFramework.Model.Device;
|
||||
using TestFramework.Model.Services.Geolocation;
|
||||
using TestFramework.Model.User.Account;
|
||||
using TestFramework.Repository;
|
||||
using TestFramework.Services.BluetoothLock;
|
||||
using TestFramework.Services.CopriApi.Connector;
|
||||
using TINK.Model;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Model.Settings;
|
||||
using TINK.Repository;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Services;
|
||||
using TINK.Services.Geolocation;
|
||||
using TINK.Services.Permissions;
|
||||
using TINK.View;
|
||||
using TINK.ViewModel.Map;
|
||||
using TINK.ViewModel.Settings;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace TestShareeLib.UseCases.Startup
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestMapPageViewModel
|
||||
{
|
||||
[Test]
|
||||
public async Task TestConstruct()
|
||||
{
|
||||
var tinkApp = new TinkApp(
|
||||
new Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.CARGOBIKE, FilterState.On }, { FilterHelper.CITYBIKE, FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.CARGOBIKE, FilterState.On }, { FilterHelper.CITYBIKE, FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://tinkwwp.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: typeof(LocksServiceMock).FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory001(sessionCookie)),
|
||||
merchantId: "MyMerchId",
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var navigationService = Substitute.For<INavigation>();
|
||||
var locationPermission = Substitute.For<ILocationPermission>();
|
||||
|
||||
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
||||
|
||||
var viewModel = new MapPageViewModel(
|
||||
tinkApp,
|
||||
locationPermission,
|
||||
Substitute.For<IBluetoothLE>(),
|
||||
Substitute.For<IGeolocation>(),
|
||||
(mapspan) => { },
|
||||
viewService,
|
||||
navigationService);
|
||||
|
||||
try
|
||||
{
|
||||
await viewModel.OnAppearing(); // Is called when page shows.
|
||||
|
||||
Assert.IsNull(viewModel.Exception);
|
||||
|
||||
// Verify pins on map
|
||||
Assert.AreEqual(27, viewModel.Pins.Count); // Were 8 pins when loading from CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)
|
||||
Assert.That(
|
||||
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Green")).Tag,
|
||||
Is.EqualTo("FR101"),
|
||||
"Station FR105 must be marked green because there is are bike.");
|
||||
Assert.That(
|
||||
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Red")).Tag,
|
||||
Is.EqualTo("KN12"),
|
||||
"Station KN12 must be marked red because there is no bike."); // Was station id 31
|
||||
|
||||
// Verify buttons
|
||||
Assert.IsTrue(viewModel.IsToggleVisible, "TINK and Konrad are activated in settings.");
|
||||
Assert.AreEqual(Color.White, viewModel.TinkColor, "TINK bikes are shown.");
|
||||
|
||||
Assert.AreEqual(Color.FromRgba(0, 0, 0, 0), viewModel.KonradColor, "Konrad bikes are hidden.");
|
||||
|
||||
var statusInfoText = viewModel.StatusInfoText;
|
||||
Assert.That(
|
||||
statusInfoText,
|
||||
Does.Contain("Updating...").Or.Contain(""),
|
||||
$"Unexpected text {statusInfoText} detected.",
|
||||
"Text might be \"Updating...\" or empty depending on acivity of update thread.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
await viewModel.OnDisappearing();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_KonradActive()
|
||||
{
|
||||
var tinkApp = new TinkApp(
|
||||
new Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.CARGOBIKE, FilterState.Off }, { FilterHelper.CITYBIKE, FilterState.On } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.CARGOBIKE, FilterState.On }, { FilterHelper.CITYBIKE, FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://tinkwwp.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: typeof(LocksServiceMock).FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory001(sessionCookie)),
|
||||
merchantId: "MyMerchId",
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
postAction: (d, obj) => d(obj),
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173), // Current app version. Must be larger or equal 3.0.173 to
|
||||
whatsNewShownInVersion: null); // Whats new page was never shown.
|
||||
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var navigationService = Substitute.For<INavigation>();
|
||||
var locationPermission = Substitute.For<ILocationPermission>();
|
||||
|
||||
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
||||
|
||||
var viewModel = new MapPageViewModel(
|
||||
tinkApp,
|
||||
locationPermission,
|
||||
NSubstitute.Substitute.For<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(),
|
||||
NSubstitute.Substitute.For<IGeolocation>(),
|
||||
(mapspan) => { },
|
||||
viewService,
|
||||
navigationService);
|
||||
|
||||
try
|
||||
{
|
||||
await viewModel.OnAppearing(); // Is called when page shows.
|
||||
|
||||
Assert.IsNull(viewModel.Exception);
|
||||
|
||||
// Verify pins on map
|
||||
Assert.AreEqual(21, viewModel.Pins.Count); // Were 2 pins when loading from CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)
|
||||
Assert.That(
|
||||
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Green")).Tag, // Was station 5
|
||||
Is.EqualTo("FR103"),
|
||||
"Station FR101 must be marked green because there is are bike.");
|
||||
Assert.That(
|
||||
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Red")).Tag, // Was station 14
|
||||
Is.EqualTo("KN12"),
|
||||
"Station KN12 must be marked red because there is no bike.");
|
||||
|
||||
// Verify buttons
|
||||
Assert.IsTrue(viewModel.IsToggleVisible, "TINK and Konrad are activated in settings.");
|
||||
Assert.AreEqual(Color.FromRgba(0, 0, 0, 0), viewModel.TinkColor, "TINK bikes are hidden.");
|
||||
|
||||
Assert.AreEqual(Color.White, viewModel.KonradColor, "Konrad bikes are shown.");
|
||||
|
||||
Assert.IsTrue(
|
||||
new[] { "Updating...", "" }.Contains(viewModel.StatusInfoText),
|
||||
"Text might be \"Updating...\" or empty depending on acivity of update thread.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
await viewModel.OnDisappearing();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_KonradOnly()
|
||||
{
|
||||
var tinkApp = new TinkApp(
|
||||
new Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.CITYBIKE, FilterState.On } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.CARGOBIKE, FilterState.Off }, { FilterHelper.CITYBIKE, FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://tinkwwp.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: typeof(LocksServiceMock).FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory001(sessionCookie)),
|
||||
merchantId: "MyMerchId",
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173)); // Current app version. Must be larger or equal 3.0.173 to
|
||||
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var navigationService = Substitute.For<INavigation>();
|
||||
var locationPermission = Substitute.For<ILocationPermission>();
|
||||
|
||||
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
||||
|
||||
var viewModel = new MapPageViewModel(
|
||||
tinkApp,
|
||||
locationPermission,
|
||||
Substitute.For<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(),
|
||||
Substitute.For<IGeolocation>(),
|
||||
(mapspan) => { },
|
||||
viewService,
|
||||
navigationService);
|
||||
|
||||
try
|
||||
{
|
||||
await viewModel.OnAppearing(); // Is called when page shows.
|
||||
|
||||
Assert.IsNull(viewModel.Exception);
|
||||
|
||||
// Verify pins on map
|
||||
Assert.AreEqual(21, viewModel.Pins.Count); // Were 2 when loading from CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)
|
||||
Assert.That(
|
||||
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Green")).Tag, // Was station id 31
|
||||
Is.EqualTo("FR103"),
|
||||
"Station FR101 must be marked green because there is are bike.");
|
||||
Assert.That(
|
||||
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Red")).Tag, // Was 14
|
||||
Is.EqualTo("KN12"),
|
||||
"Station KN12 must be marked red because there is no bike.");
|
||||
|
||||
// Verify buttons
|
||||
Assert.IsFalse(viewModel.IsToggleVisible, "TINK and Konrad is deactivated from settings.");
|
||||
|
||||
Assert.IsTrue(
|
||||
new[] { "Updating...", "" }.Contains(viewModel.StatusInfoText),
|
||||
"Text might be \"Updating...\" or empty depending on acivity of update thread.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
await viewModel.OnDisappearing();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_TinkOnly()
|
||||
{
|
||||
var tinkApp = new TinkApp(
|
||||
new Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.CARGOBIKE, FilterState.On } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.CARGOBIKE, FilterState.On }, { FilterHelper.CITYBIKE, FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://tinkwwp.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: typeof(LocksServiceMock).FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(),
|
||||
isConnectedFunc: () => true,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory001(sessionCookie)),
|
||||
merchantId: "MyMerchId",
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173));
|
||||
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var navigationService = Substitute.For<INavigation>();
|
||||
var locationPermission = Substitute.For<ILocationPermission>();
|
||||
|
||||
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
||||
|
||||
var viewModel = new MapPageViewModel(
|
||||
tinkApp,
|
||||
locationPermission,
|
||||
Substitute.For<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(),
|
||||
Substitute.For<IGeolocation>(),
|
||||
(mapspan) => { },
|
||||
viewService,
|
||||
navigationService);
|
||||
|
||||
try
|
||||
{
|
||||
await viewModel.OnAppearing(); // Is called when page shows.
|
||||
|
||||
Assert.IsNull(viewModel.Exception);
|
||||
|
||||
// Verify pins on map
|
||||
Assert.AreEqual(27, viewModel.Pins.Count); // Were 8 pin when loading from CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)
|
||||
Assert.That(
|
||||
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Green")).Tag,
|
||||
Is.EqualTo("FR101"), // Was station id 4
|
||||
"Station FR101 must be marked green because there is are bike.");
|
||||
Assert.That(
|
||||
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Red")).Tag, // Was 31
|
||||
Is.EqualTo("KN12"), // Was station id 31
|
||||
"Station KN12 must be marked red because there is no bike.");
|
||||
|
||||
// Verify buttons
|
||||
Assert.IsFalse(viewModel.IsToggleVisible, "TINK and Konrad is deactivated from settings.");
|
||||
|
||||
Assert.IsTrue(
|
||||
new[] { "Updating...", "" }.Contains(viewModel.StatusInfoText),
|
||||
"Text might be \"Updating...\" or empty depending on acivity of update thread.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
await viewModel.OnDisappearing();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_Offline()
|
||||
{
|
||||
var tinkApp = new TinkApp(
|
||||
new Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.CARGOBIKE, FilterState.On }, { FilterHelper.CITYBIKE, FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.CARGOBIKE, FilterState.On }, { FilterHelper.CITYBIKE, FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://tinkwwp.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
activeLockService: typeof(LocksServiceMock).FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(),
|
||||
isConnectedFunc: () => false,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new ConnectorCache(new AppContextInfo("MyMerchId", "MyApp", new Version(1, 2)), null /*UI language */, sessionCookie, mail, server: new CopriCallsMemory001(sessionCookie)),
|
||||
merchantId: "MyMerchId",
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173)); // Current app version. Must be larger or equal 3.0.173 to
|
||||
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var navigationService = Substitute.For<INavigation>();
|
||||
var locationPermission = Substitute.For<ILocationPermission>();
|
||||
|
||||
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
||||
|
||||
var viewModel = new MapPageViewModel(
|
||||
tinkApp,
|
||||
locationPermission,
|
||||
Substitute.For<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(),
|
||||
Substitute.For<IGeolocation>(),
|
||||
(mapspan) => { },
|
||||
viewService,
|
||||
navigationService);
|
||||
|
||||
try
|
||||
{
|
||||
await viewModel.OnAppearing(); // Is called when page shows.
|
||||
|
||||
Assert.IsNull(viewModel.Exception);
|
||||
|
||||
// Verify pins on map
|
||||
Assert.AreEqual(27, viewModel.Pins.Count); // Were 8 pins when loading from CopriCallsMemory(SampleSets.Set2, 1, sessionCookie)
|
||||
Assert.That(
|
||||
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Green")).Tag, // Was station id 4
|
||||
Is.EqualTo("FR101"),
|
||||
"Station FR101 must be marked green because there is are bike.");
|
||||
Assert.That(
|
||||
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Red")).Tag, // Was 31
|
||||
Is.EqualTo("KN12"),
|
||||
"Station KN12 must be marked red because there is no bike.");
|
||||
|
||||
// Verify buttons
|
||||
Assert.IsTrue(viewModel.IsToggleVisible, "TINK and Konrad are activated in settings.");
|
||||
Assert.AreEqual(Color.White, viewModel.TinkColor, "TINK bikes are hidden.");
|
||||
|
||||
Assert.AreEqual(Color.FromRgba(0, 0, 0, 0), viewModel.KonradColor, "Konrad bikes are shown.");
|
||||
|
||||
|
||||
Assert.AreEqual("Offline.", viewModel.StatusInfoText);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await viewModel.OnDisappearing();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_WebConnectCommunicationError()
|
||||
{
|
||||
var tinkApp = new TinkApp(
|
||||
new Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.CARGOBIKE, FilterState.On }, { FilterHelper.CITYBIKE, FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.CARGOBIKE, FilterState.On }, { FilterHelper.CITYBIKE, FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://tinkwwp.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
true /* IsReportLevelVerbose */,
|
||||
activeLockService: typeof(LocksServiceMock).FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(),
|
||||
isConnectedFunc: () => false,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new Connector(
|
||||
uri,
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
sessionCookie,
|
||||
mail,
|
||||
server: new CopriProviderHttps(
|
||||
uri,
|
||||
TinkApp.MerchantId,
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
sessionCookie: sessionCookie,
|
||||
cacheServer: new CopriCallsCacheMemory001(sessionCookie: sessionCookie),
|
||||
httpsServer: new ExceptionServer((msg) => new WebConnectFailureException(msg, new Exception("Source expection."))))),
|
||||
merchantId: "MyMerchId",
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173)); // Current app version. Must be larger or equal 3.0.173 to
|
||||
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var navigationService = Substitute.For<INavigation>();
|
||||
var locationPermission = Substitute.For<ILocationPermission>();
|
||||
|
||||
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
||||
|
||||
var viewModel = new MapPageViewModel(
|
||||
tinkApp,
|
||||
locationPermission,
|
||||
Substitute.For<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(),
|
||||
Substitute.For<IGeolocation>(),
|
||||
(mapspan) => { },
|
||||
viewService,
|
||||
navigationService);
|
||||
|
||||
try
|
||||
{
|
||||
await viewModel.OnAppearing(); // Is called when page shows.
|
||||
|
||||
Assert.AreEqual(
|
||||
"Simulated error thrown at GetStationsAsync.",
|
||||
viewModel.Exception.Message);
|
||||
|
||||
// Verify pins on map
|
||||
Assert.AreEqual(27, viewModel.Pins.Count);
|
||||
Assert.That(
|
||||
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Green")).Tag, // Was station id 4
|
||||
Is.EqualTo("FR101"),
|
||||
"Station FR101 must be marked green because there is are bike.");
|
||||
Assert.That(
|
||||
viewModel.Pins.FirstOrDefault(pin => pin.Icon.Id.Contains("Open_Red")).Tag, // Was 31
|
||||
Is.EqualTo("KN12"),
|
||||
"Station KN12 must be marked red because there is no bike.");
|
||||
|
||||
// Verify buttons
|
||||
Assert.IsTrue(viewModel.IsToggleVisible, "TINK and Konrad are activated in settings.");
|
||||
Assert.AreEqual(Color.White, viewModel.TinkColor, "TINK bikes are hidden.");
|
||||
|
||||
Assert.AreEqual(Color.FromRgba(0, 0, 0, 0), viewModel.KonradColor, "Konrad bikes are shown.");
|
||||
|
||||
Assert.AreEqual("Connection interrupted, server unreachable.", viewModel.StatusInfoText);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await viewModel.OnDisappearing();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestConstruct_GeneralPurposeCommunicationError()
|
||||
{
|
||||
var tinkApp = new TinkApp(
|
||||
new Settings(
|
||||
new GroupFilterMapPage(new Dictionary<string, FilterState> { { FilterHelper.CARGOBIKE, FilterState.On }, { FilterHelper.CITYBIKE, FilterState.Off } }),
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> { { FilterHelper.CARGOBIKE, FilterState.On }, { FilterHelper.CITYBIKE, FilterState.On } }),
|
||||
new StartupSettings(),
|
||||
new Uri("https://tinkwwp.copri-bike.de/APIjsonserver"),
|
||||
new TINK.Settings.PollingParameters(new TimeSpan(10000), true),
|
||||
Serilog.Events.LogEventLevel.Error,
|
||||
true /* IsReportLevelVerbose */,
|
||||
activeLockService: typeof(LocksServiceMock).FullName,
|
||||
activeGeolocationService: typeof(GeolocationMock).FullName),
|
||||
new StoreMock(),
|
||||
isConnectedFunc: () => false,
|
||||
connectorFactory: (isConnected, uri, sessionCookie, mail, expiresAfter) => new Connector(
|
||||
uri,
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
sessionCookie,
|
||||
mail,
|
||||
server: new CopriProviderHttps(
|
||||
uri,
|
||||
TinkApp.MerchantId,
|
||||
new AppContextInfo("oiF2kahH", "sharee.bike.test", new Version(3, 0, 267)),
|
||||
null /*UI language */,
|
||||
sessionCookie: sessionCookie,
|
||||
cacheServer: new CopriCallsCacheMemory001(sessionCookie: sessionCookie),
|
||||
httpsServer: new ExceptionServer((msg) => new Exception(msg)))),
|
||||
merchantId: "MyMerchId",
|
||||
bluetoothService: Substitute.For<IBluetoothLE>(),
|
||||
locationPermissionsService: Substitute.For<ILocationPermission>(),
|
||||
locationServicesContainer: Substitute.For<IServicesContainer<IGeolocation>>(),
|
||||
locksService: new LocksServiceMock(), // Cipher
|
||||
device: new DeviceMock(),
|
||||
specialFolder: new SpecialFolderMock(),
|
||||
cipher: null,
|
||||
theme: null,
|
||||
currentVersion: new Version(3, 2, 0, 115), // Current app version
|
||||
lastVersion: new Version(3, 0, 173)); // Current app version. Must be larger or equal 3.0.173 to
|
||||
|
||||
|
||||
var viewService = Substitute.For<IViewService>();
|
||||
var navigationService = Substitute.For<INavigation>();
|
||||
var locationPermission = Substitute.For<ILocationPermission>();
|
||||
|
||||
locationPermission.CheckStatusAsync().Returns(Status.Granted);
|
||||
|
||||
var viewModel = new MapPageViewModel(
|
||||
tinkApp,
|
||||
locationPermission,
|
||||
Substitute.For<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(),
|
||||
Substitute.For<IGeolocation>(),
|
||||
(mapspan) => { },
|
||||
viewService,
|
||||
navigationService);
|
||||
|
||||
try
|
||||
{
|
||||
await viewModel.OnAppearing(); // Is called when page shows.
|
||||
|
||||
Assert.AreEqual(
|
||||
"Simulated error thrown at GetStationsAsync.",
|
||||
viewModel.Exception.Message);
|
||||
|
||||
// Verify pins on map
|
||||
Assert.AreEqual(27, viewModel.Pins.Count);
|
||||
Assert.That(
|
||||
viewModel.Pins.Where(pin => pin.Icon.Id.Contains("Open_Green")).Select(pin => pin.Tag.ToString()),
|
||||
Does.Contain("FR101"), // Was station id 4
|
||||
"Station FR103 must be marked green because there is are bike.");
|
||||
Assert.That(
|
||||
viewModel.Pins.Where(pin => pin.Icon.Id.Contains("Open_Red")).Select(pin => pin.Tag.ToString()),
|
||||
Does.Contain("KN12"), // Was station id 31
|
||||
"Station 31 must be marked red because there is no bike.");
|
||||
|
||||
// Verify buttons
|
||||
Assert.IsTrue(viewModel.IsToggleVisible, "TINK and Konrad are activated in settings.");
|
||||
Assert.AreEqual(Color.White, viewModel.TinkColor, "TINK bikes are hidden.");
|
||||
|
||||
Assert.AreEqual(Color.FromRgba(0, 0, 0, 0), viewModel.KonradColor, "Konrad bikes are shown.");
|
||||
|
||||
Assert.AreEqual("Connection interrupted.", viewModel.StatusInfoText);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await viewModel.OnDisappearing();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
110
TestShareeLib/ViewModel/Settings/TestFilterCollectionMutable.cs
Normal file
110
TestShareeLib/ViewModel/Settings/TestFilterCollectionMutable.cs
Normal file
|
@ -0,0 +1,110 @@
|
|||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model;
|
||||
using TINK.ViewModel.Settings;
|
||||
|
||||
|
||||
namespace UITest.Fixtures.ObjectTests.ViewModel.Settings
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class TestFilterCollectionMutable
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct_NoConradAccount()
|
||||
{
|
||||
var l_oColl = new SettingsBikeFilterViewModel(
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> {
|
||||
{"TINK", FilterState.On },
|
||||
{"Konrad", FilterState.On}
|
||||
}),
|
||||
new List<string> { "TINK" });
|
||||
|
||||
Assert.AreEqual("TINK", l_oColl[0].Key);
|
||||
Assert.IsTrue(l_oColl[0].IsActivated);
|
||||
Assert.IsTrue(l_oColl[0].IsEnabled);
|
||||
|
||||
Assert.AreEqual("Konrad", l_oColl[1].Key);
|
||||
Assert.IsFalse(l_oColl[1].IsActivated, "Konrad must be off if user is not part of group.");
|
||||
Assert.IsFalse(l_oColl[1].IsEnabled, "Konrad must be disabled if user is not part of group.");
|
||||
|
||||
Assert.AreEqual(FilterState.On, l_oColl.FilterCollection["TINK"]);
|
||||
Assert.AreEqual(FilterState.On, l_oColl.FilterCollection["Konrad"], "Filter state must be preserved.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_ConradAccount()
|
||||
{
|
||||
var l_oColl = new SettingsBikeFilterViewModel(
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> {
|
||||
{"TINK", FilterState.On },
|
||||
{"Konrad", FilterState.On}
|
||||
}),
|
||||
new List<string> { "TINK", "Konrad" });
|
||||
|
||||
Assert.AreEqual("TINK", l_oColl[0].Key);
|
||||
Assert.IsTrue(l_oColl[0].IsActivated);
|
||||
Assert.IsTrue(l_oColl[0].IsEnabled);
|
||||
|
||||
Assert.AreEqual("Konrad", l_oColl[1].Key);
|
||||
Assert.IsTrue(l_oColl[1].IsActivated);
|
||||
Assert.IsTrue(l_oColl[1].IsEnabled);
|
||||
|
||||
Assert.AreEqual(FilterState.On, l_oColl.FilterCollection["TINK"]);
|
||||
Assert.AreEqual(FilterState.On, l_oColl.FilterCollection["Konrad"], "Filter state must be preserved.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_TurnOff()
|
||||
{
|
||||
var l_oColl = new SettingsBikeFilterViewModel(
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> {
|
||||
{"TINK", FilterState.On },
|
||||
{"Konrad", FilterState.On}
|
||||
}),
|
||||
new List<string> { "TINK", "Konrad" });
|
||||
|
||||
// Check prerequisites.
|
||||
Assert.AreEqual("TINK", l_oColl[0].Key);
|
||||
Assert.IsTrue(l_oColl[0].IsActivated);
|
||||
Assert.IsTrue(l_oColl[0].IsEnabled);
|
||||
|
||||
Assert.AreEqual("Konrad", l_oColl[1].Key);
|
||||
Assert.IsTrue(l_oColl[1].IsActivated);
|
||||
Assert.IsTrue(l_oColl[1].IsEnabled);
|
||||
|
||||
Assert.AreEqual(FilterState.On, l_oColl.FilterCollection["TINK"]);
|
||||
Assert.AreEqual(FilterState.On, l_oColl.FilterCollection["Konrad"], "Filter state must be preserved.");
|
||||
|
||||
// Turn filter konrad off.
|
||||
l_oColl[1].IsActivated = false;
|
||||
|
||||
// Verify changes.
|
||||
Assert.AreEqual(FilterState.On, l_oColl.FilterCollection["TINK"]);
|
||||
Assert.AreEqual(FilterState.Off, l_oColl.FilterCollection["Konrad"], "Filter state must be preserved.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConstruct_NoUserLoggedIn()
|
||||
{
|
||||
var l_oColl = new SettingsBikeFilterViewModel(
|
||||
new GroupFilterSettings(new Dictionary<string, FilterState> {
|
||||
{"TINK", FilterState.On },
|
||||
{"Konrad", FilterState.On}
|
||||
}),
|
||||
null);
|
||||
|
||||
// Check prerequisites.
|
||||
Assert.AreEqual("TINK", l_oColl[0].Key);
|
||||
Assert.IsTrue(l_oColl[0].IsActivated);
|
||||
Assert.IsTrue(l_oColl[0].IsEnabled);
|
||||
|
||||
Assert.AreEqual("Konrad", l_oColl[1].Key);
|
||||
Assert.IsTrue(l_oColl[1].IsActivated);
|
||||
Assert.IsTrue(l_oColl[1].IsEnabled);
|
||||
|
||||
Assert.AreEqual(FilterState.On, l_oColl.FilterCollection["TINK"]);
|
||||
Assert.AreEqual(FilterState.On, l_oColl.FilterCollection["Konrad"], "Filter state must be preserved.");
|
||||
}
|
||||
}
|
||||
}
|
24
TestShareeLib/ViewModel/Settings/TestGroupFilterSettings.cs
Normal file
24
TestShareeLib/ViewModel/Settings/TestGroupFilterSettings.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.ViewModel.Settings;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.SettingsNS
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestGroupFilterSettings
|
||||
{
|
||||
[Test]
|
||||
public void TestDoFilter()
|
||||
{
|
||||
var l_oFilter = new GroupFilterSettings(new Dictionary<string, FilterState> { { $"HOM_{FilterHelper.CITYBIKE}", FilterState.Off }, { $"HOM_{FilterHelper.CARGOBIKE}", FilterState.On }, { "HOM_117025", FilterState.On } });
|
||||
|
||||
var l_oResult = l_oFilter.DoFilter(new List<string> { $"HOM_{FilterHelper.CITYBIKE}", $"HOM_{FilterHelper.CARGOBIKE}" });
|
||||
|
||||
Assert.AreEqual(1, l_oResult.ToList().Count);
|
||||
Assert.AreEqual($"HOM_{FilterHelper.CARGOBIKE}", l_oResult.ToList()[0]);
|
||||
}
|
||||
}
|
||||
}
|
41
TestShareeLib/ViewModel/Settings/TestPollingParameters.cs
Normal file
41
TestShareeLib/ViewModel/Settings/TestPollingParameters.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using TINK.Settings;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.SettingsNS
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestPollingParameters
|
||||
{
|
||||
[Test]
|
||||
public void TestConstruct()
|
||||
{
|
||||
Assert.IsTrue(new PollingParameters(new TimeSpan(0, 0, 11), true).IsActivated);
|
||||
Assert.AreEqual(11, (new PollingParameters(new TimeSpan(0, 0, 11), true).Periode.TotalSeconds));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEquals()
|
||||
{
|
||||
Assert.IsTrue((new PollingParameters(new TimeSpan(0, 0, 11), true)) == (new PollingParameters(new TimeSpan(0, 0, 11), true)));
|
||||
Assert.IsFalse((new PollingParameters(new TimeSpan(0, 0, 11), false)) == (new PollingParameters(new TimeSpan(0, 0, 11), true)));
|
||||
Assert.IsFalse((new PollingParameters(new TimeSpan(0, 0, 12), true)) == (new PollingParameters(new TimeSpan(0, 0, 11), true)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUnequals()
|
||||
{
|
||||
Assert.IsFalse((new PollingParameters(new TimeSpan(0, 0, 11), true)) != (new PollingParameters(new TimeSpan(0, 0, 11), true)));
|
||||
Assert.IsTrue((new PollingParameters(new TimeSpan(0, 0, 11), false)) != (new PollingParameters(new TimeSpan(0, 0, 11), true)));
|
||||
Assert.IsTrue((new PollingParameters(new TimeSpan(0, 0, 12), true)) != (new PollingParameters(new TimeSpan(0, 0, 11), true)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestToString()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
"Polling is on=True, polling interval=11[sec].",
|
||||
(new PollingParameters(new TimeSpan(0, 0, 11), true).ToString()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using TINK.ViewModel;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.ViewModel
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestBikeAtStationInUseStateInfoProvider
|
||||
{
|
||||
[Test]
|
||||
public void TestGetReservedInfo()
|
||||
{
|
||||
Assert.That(new BikeAtStationInUseStateInfoProvider().GetReservedInfo(null), Is.EqualTo("Max. reservation time of 15 min. expired."));
|
||||
Assert.That(new BikeAtStationInUseStateInfoProvider().GetReservedInfo(null, code: "Code123"), Is.Not.Null);
|
||||
Assert.That(new BikeAtStationInUseStateInfoProvider().GetReservedInfo(TimeSpan.FromSeconds(3), code: "Code123"), Is.Not.Null);
|
||||
Assert.That(new BikeAtStationInUseStateInfoProvider().GetReservedInfo(TimeSpan.FromSeconds(60)), Is.EqualTo("Still 1 min. reserved."));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test()
|
||||
{
|
||||
Assert.That(new BikeAtStationInUseStateInfoProvider().GetBookedInfo(null), Is.EqualTo("Bike is rented."));
|
||||
Assert.That(new BikeAtStationInUseStateInfoProvider().GetBookedInfo(DateTime.Parse("2020-12-19 0:22"), code: "Code123"), Is.Not.Null);
|
||||
Assert.That(new BikeAtStationInUseStateInfoProvider().GetBookedInfo(DateTime.Parse("2020-12-19 0:22"), code: "Code123"), Is.EqualTo("Code Code123, rented since 19. December 00:22."));
|
||||
}
|
||||
}
|
||||
}
|
31
TestShareeLib/ViewModel/TestMyBikeInUseStateInfoProvider.cs
Normal file
31
TestShareeLib/ViewModel/TestMyBikeInUseStateInfoProvider.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using TINK.ViewModel;
|
||||
|
||||
namespace TestTINKLib.Fixtures.ObjectTests.ViewModel
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestMyBikeInUseStateInfoProvider
|
||||
{
|
||||
[Test]
|
||||
public void TestGetReservedInfo()
|
||||
{
|
||||
Assert.That(new MyBikeInUseStateInfoProvider().GetReservedInfo(null), Is.EqualTo("Max. reservation time of 15 min. expired."));
|
||||
Assert.That(new MyBikeInUseStateInfoProvider().GetReservedInfo(null, code: "Code12"), Is.Not.Null);
|
||||
Assert.That(new MyBikeInUseStateInfoProvider().GetReservedInfo(null, "12"), Is.EqualTo("Location 12, max. reservation time of 15 min. expired."));
|
||||
Assert.That(new MyBikeInUseStateInfoProvider().GetReservedInfo(null, "12", "Code12"), Is.Not.Null);
|
||||
Assert.That(new MyBikeInUseStateInfoProvider().GetReservedInfo(TimeSpan.FromSeconds(10)), Is.Not.Null);
|
||||
Assert.That(new MyBikeInUseStateInfoProvider().GetReservedInfo(TimeSpan.FromSeconds(10), "123"), Is.EqualTo("Location Station 123, still 0 min. reserved."));
|
||||
Assert.That(new MyBikeInUseStateInfoProvider().GetReservedInfo(TimeSpan.FromSeconds(10), "123", "code123"), Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetBookedInfoInfo()
|
||||
{
|
||||
Assert.That(new MyBikeInUseStateInfoProvider().GetBookedInfo(null), Is.EqualTo("Bike is rented."));
|
||||
Assert.That(new MyBikeInUseStateInfoProvider().GetBookedInfo(DateTime.Now, "123", "Code123"), Is.Not.Null);
|
||||
Assert.That(new MyBikeInUseStateInfoProvider().GetBookedInfo(DateTime.Now, code: "Code123"), Is.Not.Null);
|
||||
Assert.That(new MyBikeInUseStateInfoProvider().GetBookedInfo(DateTime.Parse("2020-12-19 0:22"), "123"), Is.EqualTo("Rented since 19. December 00:22."));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
using System;
|
||||
using System;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BC;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using TINK.ViewModel;
|
||||
|
||||
namespace TestShareeLib.ViewModel
|
||||
|
@ -124,5 +125,76 @@ namespace TestShareeLib.ViewModel
|
|||
new AggregateException(new Exception("Oh yes"), new Exception("Oh no")).GetErrorMessage(),
|
||||
Is.EqualTo("One or more errors occurred.\r\nOh yes\r\nOh no"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetDisplayName_DefinedTypes()
|
||||
{
|
||||
var bike = Substitute.For<IBikeInfoMutable>();
|
||||
bike.WheelType.Returns(WheelType.Two);
|
||||
bike.TypeOfBike.Returns(TypeOfBike.City);
|
||||
bike.Description.Returns("MeinStadtrad");
|
||||
bike.Id.Returns("22");
|
||||
Assert.AreEqual(
|
||||
"MeinStadtrad",
|
||||
bike.GetDisplayName());
|
||||
|
||||
Assert.AreEqual(
|
||||
"22",
|
||||
bike.GetDisplayId());
|
||||
|
||||
bike = Substitute.For<IBikeInfoMutable>();
|
||||
bike.WheelType.Returns(WheelType.Two);
|
||||
bike.TypeOfBike.Returns(TypeOfBike.City);
|
||||
bike.Id.Returns("22");
|
||||
bike.IsDemo.Returns(true);
|
||||
bike.Description.Returns("MeinStadtrad");
|
||||
Assert.AreEqual(
|
||||
"MeinStadtrad",
|
||||
bike.GetDisplayName());
|
||||
Assert.AreEqual(
|
||||
"22",
|
||||
bike.GetDisplayId());
|
||||
|
||||
bike = Substitute.For<IBikeInfoMutable>();
|
||||
bike.WheelType.Returns(WheelType.Trike);
|
||||
bike.TypeOfBike.Returns(TypeOfBike.Cargo);
|
||||
bike.Description.Returns("MeinCargoDreiradl");
|
||||
bike.Id.Returns("22");
|
||||
Assert.AreEqual(
|
||||
"MeinCargoDreiradl",
|
||||
bike.GetDisplayName());
|
||||
Assert.AreEqual(
|
||||
"22",
|
||||
bike.GetDisplayId());
|
||||
|
||||
bike = Substitute.For<IBikeInfoMutable>();
|
||||
bike.WheelType.Returns(WheelType.Two);
|
||||
bike.TypeOfBike.Returns(TypeOfBike.Cargo);
|
||||
bike.Description.Returns("MeinCargoALololong");
|
||||
bike.Id.Returns("22");
|
||||
Assert.AreEqual(
|
||||
"MeinCargoALololong",
|
||||
bike.GetDisplayName());
|
||||
Assert.AreEqual(
|
||||
"22",
|
||||
bike.GetDisplayId());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetDisplayName_UndefinedTypes()
|
||||
{
|
||||
var bike = Substitute.For<IBikeInfoMutable>();
|
||||
bike.WheelType.Returns(WheelType.Mono);
|
||||
bike.TypeOfBike.Returns(TypeOfBike.Cargo);
|
||||
bike.Description.Returns("SuperCargo");
|
||||
bike.Id.Returns("22");
|
||||
Assert.AreEqual(
|
||||
"SuperCargo",
|
||||
bike.GetDisplayName());
|
||||
|
||||
Assert.AreEqual(
|
||||
"22",
|
||||
bike.GetDisplayId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue