2022-10-17 18:45:38 +02:00
|
|
|
using System;
|
2021-07-12 21:31:46 +02:00
|
|
|
using System.Collections.Generic;
|
2022-08-30 15:42:25 +02:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using Serilog.Events;
|
2024-04-09 12:53:23 +02:00
|
|
|
using ShareeBike.Model.Settings;
|
|
|
|
using ShareeBike.Settings;
|
2021-07-12 21:31:46 +02:00
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
namespace SharedBusinessLogic.Tests.Model.Settings
|
2021-07-12 21:31:46 +02:00
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
[TestFixture]
|
|
|
|
public class TestJsonSettingsDictionary
|
|
|
|
{
|
|
|
|
/// <summary> Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.</summary>
|
|
|
|
[Test]
|
|
|
|
public void TestGetCopriHostUri_NoFile()
|
|
|
|
{
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(JsonSettingsDictionary.GetCopriHostUri(new Dictionary<string, string>()), Is.Null);
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary> Verifies that empty log file leads to expected default value and doesn not throw exceptions.</summary>
|
|
|
|
[Test]
|
|
|
|
public void TestGetPolling()
|
|
|
|
{
|
|
|
|
// Serialize parameters.
|
2023-02-22 14:03:35 +01:00
|
|
|
var dict = new Dictionary<string, string>()
|
2022-09-06 16:08:19 +02:00
|
|
|
.SetPollingParameters(new PollingParameters(new TimeSpan(0, 0, 0, 15, 0), false));
|
|
|
|
|
|
|
|
// Deserialize parameters.
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(
|
|
|
|
dict.GetPollingParameters(), Is.EqualTo(new PollingParameters(new TimeSpan(0, 0, 0, 15, 0), false)));
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary> Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.</summary>
|
|
|
|
[Test]
|
|
|
|
public void TestGetPolling_NoFile()
|
|
|
|
{
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(JsonSettingsDictionary.GetPollingParameters(new Dictionary<string, string>()), Is.Null);
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetGetCopriHostUri()
|
|
|
|
{
|
2023-02-22 14:03:35 +01:00
|
|
|
var dict = new Dictionary<string, string>()
|
2022-09-06 16:08:19 +02:00
|
|
|
.SetCopriHostUri("http://1.2.3.4");
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(
|
|
|
|
JsonSettingsDictionary.GetCopriHostUri(dict), Is.EqualTo(new Uri("http://1.2.3.4")));
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary> Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.</summary>
|
|
|
|
[Test]
|
|
|
|
public void TestGetLoggingLevel()
|
|
|
|
{
|
2023-02-22 14:03:35 +01:00
|
|
|
var dict = new Dictionary<string, string>()
|
2022-09-06 16:08:19 +02:00
|
|
|
.SetMinimumLoggingLevel(0); // Verbose = 0
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(
|
|
|
|
JsonSettingsDictionary.GetMinimumLoggingLevel(dict), Is.EqualTo(LogEventLevel.Verbose)); // LogEventLevel.Error = 4
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary> Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.</summary>
|
|
|
|
[Test]
|
|
|
|
public void TestGetLoggingLevel_NoFile()
|
|
|
|
{
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(JsonSettingsDictionary.GetMinimumLoggingLevel(new Dictionary<string, string>()), Is.Null);
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetAppVersion_FirstInstall()
|
|
|
|
{
|
2023-02-22 14:03:35 +01:00
|
|
|
var dict = new Dictionary<string, string>();
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(JsonSettingsDictionary.GetAppVersion(dict), Is.Null);
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetAppVersion_LegacyTo115()
|
|
|
|
{
|
2023-02-22 14:03:35 +01:00
|
|
|
var dict = new Dictionary<string, string> { { "AppVersion", "7.2.3.9" } };
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(JsonSettingsDictionary.GetAppVersion(dict), Is.EqualTo(new Version(7, 2, 3, 9)));
|
2022-09-06 16:08:19 +02:00
|
|
|
|
2023-02-22 14:03:35 +01:00
|
|
|
dict = new Dictionary<string, string> { { "AppVersion", "7.2.3" } };
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(JsonSettingsDictionary.GetAppVersion(dict), Is.EqualTo(new Version(7, 2, 3)));
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetAppVersion_Json()
|
|
|
|
{
|
2023-02-22 14:03:35 +01:00
|
|
|
var dict = new Dictionary<string, string> { { "AppVersion", "\"3.1.2.117\"" } };
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(JsonSettingsDictionary.GetAppVersion(dict), Is.EqualTo(new Version(3, 1, 2, 117)));
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestSetAppVersion_Json()
|
|
|
|
{
|
2023-02-22 14:03:35 +01:00
|
|
|
var dict = new Dictionary<string, string>()
|
2022-09-06 16:08:19 +02:00
|
|
|
.SetAppVersion(new Version(47, 12, 3));
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(JsonSettingsDictionary.GetAppVersion(dict), Is.EqualTo(new Version(47, 12, 3)));
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetShowWhatsNew_FirstInstall()
|
|
|
|
{
|
2023-02-22 14:03:35 +01:00
|
|
|
var dict = new Dictionary<string, string>();
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(JsonSettingsDictionary.GetWhatsNew(dict), Is.Null);
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetShowWhatsNew_Json()
|
|
|
|
{
|
2023-02-22 14:03:35 +01:00
|
|
|
var dict = new Dictionary<string, string> { { "ShowWhatsNew", "\"3.1.2.117\"" } };
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(JsonSettingsDictionary.GetWhatsNew(dict), Is.EqualTo(new Version(3, 1, 2, 117)));
|
2022-09-06 16:08:19 +02:00
|
|
|
|
2023-02-22 14:03:35 +01:00
|
|
|
dict = new Dictionary<string, string> { { "ShowWhatsNew", "\"3.1.2\"" } };
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(JsonSettingsDictionary.GetWhatsNew(dict), Is.EqualTo(new Version(3, 1, 2)));
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestSetShowWhats_Json()
|
|
|
|
{
|
2023-02-22 14:03:35 +01:00
|
|
|
var dict = new Dictionary<string, string>()
|
2022-09-06 16:08:19 +02:00
|
|
|
.SetWhatsNew(new Version(47, 12, 3));
|
2024-04-09 12:53:23 +02:00
|
|
|
Assert.That(JsonSettingsDictionary.GetWhatsNew(dict), Is.EqualTo(new Version(47, 12, 3)));
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetEntryTNoLegacySettingsKeyNull() => Assert.That(
|
|
|
|
JsonSettingsDictionary.GetEntry<string>(null, new Dictionary<string, string>()),
|
|
|
|
Is.Null);
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetEntryTNoLegacySettingsNull() => Assert.That(
|
|
|
|
JsonSettingsDictionary.GetEntry<string>("Hi", null),
|
|
|
|
Is.Null);
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetEntryTNoLegacyEntryNotFound() => Assert.That(
|
|
|
|
JsonSettingsDictionary.GetEntry<string>("Hi", new Dictionary<string, string> { { "Ho", @"""Hu""" } }),
|
|
|
|
Is.Null);
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetEntryTNoLegacyEntryFound() => Assert.That(
|
|
|
|
JsonSettingsDictionary.GetEntry<string>("Hi", new Dictionary<string, string> { { "Hi", @"""Ho""" } }),
|
|
|
|
Is.EqualTo("Ho"));
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetEntryT() => Assert.That(
|
|
|
|
JsonSettingsDictionary.GetEntry<string>("Hi", new Dictionary<string, string> { { "Hi", @"""Ho""" } }, (value) => @"""Hey"""),
|
|
|
|
Is.EqualTo("Hey"));
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetActiveTheme() => Assert.That(
|
2024-04-09 12:53:23 +02:00
|
|
|
JsonSettingsDictionary.GetActiveTheme(new Dictionary<string, string> { { "Theme", @"""LastenradBayern""" } }),
|
|
|
|
Is.EqualTo(typeof(ShareeBike.Themes.LastenradBayern).Name));
|
2022-09-06 16:08:19 +02:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetActiveThemeLegacy() => Assert.That(
|
2024-04-09 12:53:23 +02:00
|
|
|
JsonSettingsDictionary.GetActiveTheme(new Dictionary<string, string> { { "Theme", @"""ShareeBike.Themes.LastenradBayern""" } }),
|
|
|
|
Is.EqualTo(typeof(ShareeBike.Themes.LastenradBayern).Name));
|
2022-09-06 16:08:19 +02:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestSetActiveTheme()
|
|
|
|
{
|
2024-04-09 12:53:23 +02:00
|
|
|
var settings = JsonSettingsDictionary.SetActiveTheme(new Dictionary<string, string>(), @"LastenradBayern");
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
settings,
|
|
|
|
Contains.Key("Theme"));
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
settings = JsonSettingsDictionary.SetActiveTheme(new Dictionary<string, string>(), @"LastenradBayern");
|
2022-09-06 16:08:19 +02:00
|
|
|
Assert.That(
|
|
|
|
settings["Theme"],
|
2024-04-09 12:53:23 +02:00
|
|
|
Is.EqualTo(JsonConvert.SerializeObject(typeof(ShareeBike.Themes.LastenradBayern).Name)));
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
2022-10-17 18:45:38 +02:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetStartupSettingsStartupPage() => Assert.That(
|
|
|
|
JsonSettingsDictionary.GetStartupSettings(new Dictionary<string, string> {
|
|
|
|
{
|
|
|
|
"StartupSettings",
|
2024-04-09 12:53:23 +02:00
|
|
|
JsonConvert.SerializeObject(new StartupSettings { StartupPage = ShareeBike.ViewTypes.ContactPage})
|
2022-10-17 18:45:38 +02:00
|
|
|
}
|
|
|
|
}).StartupPage,
|
2024-04-09 12:53:23 +02:00
|
|
|
Is.EqualTo(ShareeBike.ViewTypes.ContactPage));
|
2022-10-17 18:45:38 +02:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestSetStartupSettingsStartupPage()
|
|
|
|
{
|
|
|
|
var settings = JsonSettingsDictionary.SetStartupSettings(
|
|
|
|
new Dictionary<string, string>(),
|
2024-04-09 12:53:23 +02:00
|
|
|
new StartupSettings { StartupPage = ShareeBike.ViewTypes.ContactPage });
|
2022-10-17 18:45:38 +02:00
|
|
|
|
|
|
|
Assert.That(
|
|
|
|
settings,
|
|
|
|
Contains.Key("StartupSettings"));
|
|
|
|
|
|
|
|
Assert.That(
|
|
|
|
settings["StartupSettings"],
|
2024-04-09 12:53:23 +02:00
|
|
|
Is.EqualTo(JsonConvert.SerializeObject(new StartupSettings { StartupPage = ShareeBike.ViewTypes.ContactPage })));
|
2022-10-17 18:45:38 +02:00
|
|
|
}
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
}
|