2023-03-08 13:18:54 +01:00
|
|
|
using System;
|
2022-08-30 15:42:25 +02:00
|
|
|
using NSubstitute;
|
2021-06-26 20:57:55 +02:00
|
|
|
using NUnit.Framework;
|
2024-04-09 12:53:23 +02:00
|
|
|
using ShareeBike.Model.Bikes.BikeInfoNS.BC;
|
|
|
|
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
|
|
|
|
using ShareeBike.ViewModel;
|
2021-06-26 20:57:55 +02:00
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
namespace SharedBusinessLogic.Tests.ViewModel
|
2021-06-26 20:57:55 +02:00
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
[TestFixture]
|
|
|
|
public class TestViewModelHelper
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestGetFullDisplayName()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
bike.Description.Returns("MyStation");
|
|
|
|
bike.Id.Returns("MyId");
|
|
|
|
|
|
|
|
Assert.That(
|
|
|
|
bike.GetFullDisplayName(),
|
|
|
|
Is.EqualTo("MyStation, Nr. MyId"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetFullDisplayNameIdEmpty()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
bike.Description.Returns("MyStation");
|
|
|
|
bike.Id.Returns("");
|
|
|
|
|
|
|
|
Assert.That(
|
|
|
|
bike.GetFullDisplayName(),
|
|
|
|
Is.EqualTo("MyStation, Nr. "));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetFullDisplayNameEmpty()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
bike.Description.Returns("");
|
|
|
|
bike.Id.Returns("Id33");
|
|
|
|
|
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayName(),
|
|
|
|
Is.EqualTo("Id33"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetDisplayName()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
bike.Description.Returns("MyStation");
|
|
|
|
bike.Id.Returns("Id33");
|
|
|
|
|
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayName(),
|
|
|
|
Is.EqualTo("MyStation"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetDisplayNameEmpty()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
bike.Description.Returns("");
|
|
|
|
bike.Id.Returns("Id33");
|
|
|
|
|
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayName(),
|
|
|
|
Is.EqualTo("Id33"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetDisplayId()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
bike.Description.Returns("ValidName");
|
|
|
|
bike.Id.Returns("Id33");
|
|
|
|
|
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayId(),
|
|
|
|
Is.EqualTo("Id33"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetDisplayIdNameEmpty()
|
|
|
|
{
|
|
|
|
var bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
bike.Description.Returns("");
|
|
|
|
bike.Id.Returns("Id33");
|
|
|
|
|
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayId(),
|
|
|
|
Is.EqualTo(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetErrorMessage_Null()
|
|
|
|
{
|
|
|
|
Assert.That(
|
|
|
|
ViewModelHelper.GetErrorMessage(null),
|
|
|
|
Is.Empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetErrorMessage_Ex()
|
|
|
|
{
|
|
|
|
Assert.That(
|
|
|
|
new Exception("Ja toll").GetErrorMessage(),
|
|
|
|
Is.EqualTo("Ja toll"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetErrorMessage_Aggregate_One()
|
|
|
|
{
|
|
|
|
Assert.That(
|
|
|
|
new AggregateException(new Exception("Oh yes")).GetErrorMessage(),
|
|
|
|
Is.EqualTo("Oh yes"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetErrorMessage_Aggregate_Two()
|
|
|
|
{
|
|
|
|
Assert.That(
|
|
|
|
new AggregateException(new Exception("Oh yes"), new Exception("Oh no")).GetErrorMessage(),
|
|
|
|
Is.EqualTo("One or more errors occurred.\r\nOh yes\r\nOh no"));
|
|
|
|
}
|
2023-03-08 13:18:54 +01:00
|
|
|
|
|
|
|
[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");
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayName(), Is.EqualTo("MeinStadtrad"));
|
2023-03-08 13:18:54 +01:00
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayId(), Is.EqualTo("22"));
|
2023-03-08 13:18:54 +01:00
|
|
|
|
|
|
|
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");
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayName(), Is.EqualTo("MeinStadtrad"));
|
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayId(), Is.EqualTo("22"));
|
2023-03-08 13:18:54 +01:00
|
|
|
|
|
|
|
bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
bike.WheelType.Returns(WheelType.Trike);
|
|
|
|
bike.TypeOfBike.Returns(TypeOfBike.Cargo);
|
|
|
|
bike.Description.Returns("MeinCargoDreiradl");
|
|
|
|
bike.Id.Returns("22");
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayName(), Is.EqualTo("MeinCargoDreiradl"));
|
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayId(), Is.EqualTo("22"));
|
2023-03-08 13:18:54 +01:00
|
|
|
|
|
|
|
bike = Substitute.For<IBikeInfoMutable>();
|
|
|
|
bike.WheelType.Returns(WheelType.Two);
|
|
|
|
bike.TypeOfBike.Returns(TypeOfBike.Cargo);
|
|
|
|
bike.Description.Returns("MeinCargoALololong");
|
|
|
|
bike.Id.Returns("22");
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayName(), Is.EqualTo("MeinCargoALololong"));
|
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayId(), Is.EqualTo("22"));
|
2023-03-08 13:18:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
[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");
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayName(), Is.EqualTo("SuperCargo"));
|
2023-03-08 13:18:54 +01:00
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(
|
|
|
|
bike.GetDisplayId(), Is.EqualTo("22"));
|
2023-03-08 13:18:54 +01:00
|
|
|
}
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
2021-06-26 20:57:55 +02:00
|
|
|
}
|