Version 3.0.361

This commit is contained in:
Anja 2023-03-08 13:18:54 +01:00
parent faf68061f4
commit cba4da9357
88 changed files with 1119 additions and 1502 deletions

View file

@ -1,162 +0,0 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Rhino.Mocks;
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 */ ,
MockRepository.GenerateStub<IBikesViewModel>(),
MockRepository.GenerateStub<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 */,
MockRepository.GenerateStub<IBikesViewModel>(),
MockRepository.GenerateStub<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 */,
MockRepository.GenerateStub<IBikesViewModel>(),
MockRepository.GenerateStub<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 */,
MockRepository.GenerateStub<IBikesViewModel>(),
MockRepository.GenerateStub<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 */,
MockRepository.GenerateStub<IBikesViewModel>(),
MockRepository.GenerateStub<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 */,
MockRepository.GenerateStub<IBikesViewModel>(),
MockRepository.GenerateStub<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 */,
MockRepository.GenerateStub<IBikesViewModel>(),
MockRepository.GenerateStub<IUser>()).GetType());
}
}
}

View file

@ -1,23 +0,0 @@
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) => { });
}
}
}

View file

@ -1,595 +0,0 @@
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();
}
}
}
}

View file

@ -1,110 +0,0 @@
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.");
}
}
}

View file

@ -1,27 +0,0 @@
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."));
}
}
}

View file

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Rhino.Mocks;
using TestFramework.Model.User.Account;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
@ -78,7 +77,7 @@ namespace UITest.Fixtures.ViewModel
l_oBike,
l_oUser,
new MyBikeInUseStateInfoProvider(),
MockRepository.GenerateStub<IBikesViewModel>(),
NSubstitute.Substitute.For<IBikesViewModel>(),
url => { });
Assert.AreEqual("2", l_oViewModel.Name);
@ -105,7 +104,7 @@ namespace UITest.Fixtures.ViewModel
bike,
user,
new BikeAtStationInUseStateInfoProvider(),
MockRepository.GenerateStub<IBikesViewModel>(),
NSubstitute.Substitute.For<IBikesViewModel>(),
url => { }));
Assert.AreEqual("Still 15 min. reserved.", l_oViewModel.StateText);
@ -128,7 +127,7 @@ namespace UITest.Fixtures.ViewModel
bike,
user,
new BikeAtStationInUseStateInfoProvider(),
MockRepository.GenerateStub<IBikesViewModel>(),
NSubstitute.Substitute.For<IBikesViewModel>(),
url => { }));
Assert.AreEqual("Code 4asdfA, still 7 min. reserved.", l_oViewModel.StateText);
@ -151,7 +150,7 @@ namespace UITest.Fixtures.ViewModel
bike,
user,
new BikeAtStationInUseStateInfoProvider(),
MockRepository.GenerateStub<IBikesViewModel>(),
NSubstitute.Substitute.For<IBikesViewModel>(),
url => { }));
Assert.AreEqual(
@ -188,7 +187,7 @@ namespace UITest.Fixtures.ViewModel
l_oStoreMock.Load().Result,
"123456789"), // Device id
new BikeAtStationInUseStateInfoProvider(),
MockRepository.GenerateStub<IBikesViewModel>(),
NSubstitute.Substitute.For<IBikesViewModel>(),
url => { });
Assert.AreEqual("Test description", l_oViewModel.Name);
@ -227,7 +226,7 @@ namespace UITest.Fixtures.ViewModel
l_oStoreMock.Load().Result,
"123456789"),
new BikeAtStationInUseStateInfoProvider(),
MockRepository.GenerateStub<IBikesViewModel>(),
NSubstitute.Substitute.For<IBikesViewModel>(),
url => { });
Assert.AreEqual("Test description", l_oViewModel.Name);

View file

@ -1,83 +0,0 @@
using System;
using NUnit.Framework;
using Rhino.Mocks;
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"),
MockRepository.GenerateStub<IUser>(), // user
MockRepository.GenerateStub<IInUseStateInfoProvider>(),
MockRepository.GenerateStub<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"),
MockRepository.GenerateStub<IUser>(), // user
MockRepository.GenerateStub<IInUseStateInfoProvider>(),
MockRepository.GenerateStub<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"),
MockRepository.GenerateStub<IUser>(), // user
MockRepository.GenerateStub<IInUseStateInfoProvider>(),
MockRepository.GenerateStub<IBikesViewModel>(),
url => { }),
Is.Null);
}
}
}

View file

@ -1,31 +0,0 @@
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."));
}
}
}

View file

@ -1,84 +0,0 @@
using NUnit.Framework;
using Rhino.Mocks;
using TINK.Model.Bikes.BikeInfoNS.BC;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.ViewModel;
namespace UITest.Fixtures.ObjectTests.ViewModel
{
[TestFixture]
public class TestViewModelHelper
{
[Test]
public void TestGetDisplayName_DefinedTypes()
{
var l_oBike = MockRepository.GenerateStub<IBikeInfoMutable>();
l_oBike.Stub(x => x.WheelType).Return(WheelType.Two);
l_oBike.Stub(x => x.TypeOfBike).Return(TypeOfBike.City);
l_oBike.Stub(x => x.Description).Return("MeinStadtrad");
l_oBike.Stub(x => x.Id).Return("22");
Assert.AreEqual(
"MeinStadtrad",
l_oBike.GetDisplayName());
Assert.AreEqual(
"22",
l_oBike.GetDisplayId());
l_oBike = MockRepository.GenerateStub<IBikeInfoMutable>();
l_oBike.Stub(x => x.WheelType).Return(WheelType.Two);
l_oBike.Stub(x => x.TypeOfBike).Return(TypeOfBike.City);
l_oBike.Stub(x => x.Id).Return("22");
l_oBike.Stub(x => x.IsDemo).Return(true);
l_oBike.Stub(x => x.Description).Return("MeinStadtrad");
Assert.AreEqual(
"MeinStadtrad",
l_oBike.GetDisplayName());
Assert.AreEqual(
"22",
l_oBike.GetDisplayId());
l_oBike = MockRepository.GenerateStub<IBikeInfoMutable>();
l_oBike.Stub(x => x.WheelType).Return(WheelType.Trike);
l_oBike.Stub(x => x.TypeOfBike).Return(TypeOfBike.Cargo);
l_oBike.Stub(x => x.Description).Return("MeinCargoDreiradl");
l_oBike.Stub(x => x.Id).Return("22");
Assert.AreEqual(
"MeinCargoDreiradl",
l_oBike.GetDisplayName());
Assert.AreEqual(
"22",
l_oBike.GetDisplayId());
l_oBike = MockRepository.GenerateStub<IBikeInfoMutable>();
l_oBike.Stub(x => x.WheelType).Return(WheelType.Two);
l_oBike.Stub(x => x.TypeOfBike).Return(TypeOfBike.Cargo);
l_oBike.Stub(x => x.Description).Return("MeinCargoALololong");
l_oBike.Stub(x => x.Id).Return("22");
Assert.AreEqual(
"MeinCargoALololong",
l_oBike.GetDisplayName());
Assert.AreEqual(
"22",
l_oBike.GetDisplayId());
}
[Test]
public void TestGetDisplayName_UndefinedTypes()
{
var l_oBike = MockRepository.GenerateStub<IBikeInfoMutable>();
l_oBike.Stub(x => x.WheelType).Return(WheelType.Mono);
l_oBike.Stub(x => x.TypeOfBike).Return(TypeOfBike.Cargo);
l_oBike.Stub(x => x.Description).Return("SuperCargo");
l_oBike.Stub(x => x.Id).Return("22");
Assert.AreEqual(
"SuperCargo",
l_oBike.GetDisplayName());
Assert.AreEqual(
"22",
l_oBike.GetDisplayId());
}
}
}