2022-08-30 15:42:25 +02:00
|
|
|
|
using System;
|
2021-05-13 20:09:46 +02:00
|
|
|
|
using System.Collections.Generic;
|
2022-08-30 15:42:25 +02:00
|
|
|
|
using NUnit.Framework;
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
|
|
|
|
namespace TINK.ViewModel.Settings
|
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[TestFixture]
|
|
|
|
|
public class TestServicesViewModel
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestCtor()
|
|
|
|
|
{
|
|
|
|
|
var servicesViewModel = new ServicesViewModel(
|
|
|
|
|
new List<string> {
|
|
|
|
|
"ServiceA",
|
|
|
|
|
"ServiceB",
|
|
|
|
|
"ServiceB", // Dupes are removed
|
2021-05-13 20:09:46 +02:00
|
|
|
|
"ServiceC" },
|
2022-09-06 16:08:19 +02:00
|
|
|
|
new Dictionary<string, string> {
|
|
|
|
|
{ "ServiceA", "Top service of type A" },
|
|
|
|
|
{ "ServiceB", "Supertop service of type B" },
|
|
|
|
|
{ "OldsService", "This entry is discarded" }},
|
|
|
|
|
"ServiceB");
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
servicesViewModel.ServicesTextList,
|
|
|
|
|
Is.EqualTo(new List<string> {
|
|
|
|
|
"ServiceC",
|
|
|
|
|
"Supertop service of type B",
|
|
|
|
|
"Top service of type A" }).AsCollection);
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
servicesViewModel.Active,
|
|
|
|
|
Is.EqualTo("ServiceB"));
|
|
|
|
|
}
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestCtorInvalidActive()
|
|
|
|
|
{
|
|
|
|
|
Assert.That(
|
|
|
|
|
() => new ServicesViewModel(
|
|
|
|
|
new List<string> { "ServiceA", "ServiceB", "ServiceB", "ServiceC" },
|
|
|
|
|
new Dictionary<string, string> { { "ServiceA", "Top service of type A" }, { "ServiceB", "Supertop service of type B" } },
|
|
|
|
|
"ServiceX"),
|
|
|
|
|
Throws.TypeOf<ArgumentException>());
|
|
|
|
|
}
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestCtorInvalidServiceNames()
|
|
|
|
|
{
|
|
|
|
|
Assert.That(
|
|
|
|
|
() => new ServicesViewModel(
|
|
|
|
|
new List<string> { "ServiceA", "ServiceB", "ServiceC" },
|
|
|
|
|
new Dictionary<string, string> { { "ServiceA", "Top fast" }, { "ServiceB", "Top fast" } },
|
|
|
|
|
"ServiceB"),
|
|
|
|
|
Throws.TypeOf<ArgumentException>());
|
|
|
|
|
}
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetActiveTextDisplayTextAvailable()
|
|
|
|
|
{
|
|
|
|
|
var servicesViewModel = new ServicesViewModel(
|
|
|
|
|
new List<string> {
|
|
|
|
|
"ServiceB"},
|
|
|
|
|
new Dictionary<string, string> {
|
|
|
|
|
{ "ServiceB", "Supertop service of type B" }},
|
|
|
|
|
"ServiceB");
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
servicesViewModel.ActiveText,
|
|
|
|
|
Is.EqualTo("Supertop service of type B"));
|
|
|
|
|
}
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetActiveTextNoDisplayText()
|
|
|
|
|
{
|
|
|
|
|
var servicesViewModel = new ServicesViewModel(
|
|
|
|
|
new List<string> {
|
|
|
|
|
"ServiceB"},
|
|
|
|
|
new Dictionary<string, string>(),
|
|
|
|
|
"ServiceB");
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
servicesViewModel.ActiveText,
|
|
|
|
|
Is.EqualTo("ServiceB"));
|
|
|
|
|
}
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestSetActiveText()
|
|
|
|
|
{
|
|
|
|
|
var servicesViewModel = new ServicesViewModel(
|
|
|
|
|
new List<string> {
|
|
|
|
|
"ServiceA",
|
|
|
|
|
"ServiceB" },
|
|
|
|
|
new Dictionary<string, string>(),
|
|
|
|
|
"ServiceB")
|
|
|
|
|
{
|
|
|
|
|
ActiveText = "ServiceA"
|
|
|
|
|
};
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
servicesViewModel.ActiveText,
|
|
|
|
|
Is.EqualTo("ServiceA"));
|
|
|
|
|
}
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestSetActiveTextInvalid()
|
|
|
|
|
{
|
|
|
|
|
var servicesViewModel = new ServicesViewModel(
|
|
|
|
|
new List<string> {
|
|
|
|
|
"ServiceA",
|
|
|
|
|
"ServiceB" },
|
|
|
|
|
new Dictionary<string, string>(),
|
|
|
|
|
"ServiceB");
|
2021-05-13 20:09:46 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
() => servicesViewModel.ActiveText = "ServiceX",
|
|
|
|
|
Throws.InstanceOf<ArgumentException>());
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-13 20:09:46 +02:00
|
|
|
|
}
|