sharee.bike-App/TestShareeLib/Model/Settings/TestJsonSettingsDictionary.cs

203 lines
6.5 KiB
C#
Raw Normal View History

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;
2021-07-12 21:31:46 +02:00
using TINK.Model.Settings;
using TINK.Settings;
2022-08-30 15:42:25 +02:00
namespace TestTINKLib.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()
{
Assert.IsNull(JsonSettingsDictionary.GetCopriHostUri(new Dictionary<string, string>()));
}
/// <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.
Assert.AreEqual(
new PollingParameters(new TimeSpan(0, 0, 0, 15, 0), false),
2023-02-22 14:03:35 +01:00
dict.GetPollingParameters());
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()
{
Assert.IsNull(JsonSettingsDictionary.GetPollingParameters(new Dictionary<string, string>()));
}
[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");
Assert.AreEqual(
new Uri("http://1.2.3.4"),
2023-02-22 14:03:35 +01:00
JsonSettingsDictionary.GetCopriHostUri(dict));
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
Assert.AreEqual(
LogEventLevel.Verbose,
2023-02-22 14:03:35 +01:00
JsonSettingsDictionary.GetMinimumLoggingLevel(dict)); // 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()
{
Assert.IsNull(JsonSettingsDictionary.GetMinimumLoggingLevel(new Dictionary<string, string>()));
}
[Test]
public void TestGetAppVersion_FirstInstall()
{
2023-02-22 14:03:35 +01:00
var dict = new Dictionary<string, string>();
Assert.IsNull(JsonSettingsDictionary.GetAppVersion(dict));
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" } };
Assert.AreEqual(new Version(7, 2, 3, 9), JsonSettingsDictionary.GetAppVersion(dict));
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" } };
Assert.AreEqual(new Version(7, 2, 3), JsonSettingsDictionary.GetAppVersion(dict));
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\"" } };
Assert.AreEqual(new Version(3, 1, 2, 117), JsonSettingsDictionary.GetAppVersion(dict));
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));
2023-02-22 14:03:35 +01:00
Assert.AreEqual(new Version(47, 12, 3), JsonSettingsDictionary.GetAppVersion(dict));
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>();
Assert.IsNull(JsonSettingsDictionary.GetWhatsNew(dict));
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\"" } };
Assert.AreEqual(new Version(3, 1, 2, 117), JsonSettingsDictionary.GetWhatsNew(dict));
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\"" } };
Assert.AreEqual(new Version(3, 1, 2), JsonSettingsDictionary.GetWhatsNew(dict));
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));
2023-02-22 14:03:35 +01:00
Assert.AreEqual(new Version(47, 12, 3), JsonSettingsDictionary.GetWhatsNew(dict));
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(
JsonSettingsDictionary.GetActiveTheme(new Dictionary<string, string> { { "Theme", @"""Konrad""" } }),
Is.EqualTo(typeof(TINK.Themes.Konrad).Name));
[Test]
public void TestGetActiveThemeLegacy() => Assert.That(
JsonSettingsDictionary.GetActiveTheme(new Dictionary<string, string> { { "Theme", @"""TINK.Themes.Konrad""" } }),
Is.EqualTo(typeof(TINK.Themes.Konrad).Name));
[Test]
public void TestSetActiveTheme()
{
var settings = JsonSettingsDictionary.SetActiveTheme(new Dictionary<string, string>(), @"Konrad");
Assert.That(
settings,
Contains.Key("Theme"));
settings = JsonSettingsDictionary.SetActiveTheme(new Dictionary<string, string>(), @"Konrad");
Assert.That(
settings["Theme"],
Is.EqualTo(JsonConvert.SerializeObject(typeof(TINK.Themes.Konrad).Name)));
}
2022-10-17 18:45:38 +02:00
[Test]
public void TestGetStartupSettingsStartupPage() => Assert.That(
JsonSettingsDictionary.GetStartupSettings(new Dictionary<string, string> {
{
"StartupSettings",
JsonConvert.SerializeObject(new StartupSettings { StartupPage = TINK.ViewTypes.ContactPage})
}
}).StartupPage,
Is.EqualTo(TINK.ViewTypes.ContactPage));
[Test]
public void TestSetStartupSettingsStartupPage()
{
var settings = JsonSettingsDictionary.SetStartupSettings(
new Dictionary<string, string>(),
new StartupSettings { StartupPage = TINK.ViewTypes.ContactPage });
Assert.That(
settings,
Contains.Key("StartupSettings"));
Assert.That(
settings["StartupSettings"],
Is.EqualTo(JsonConvert.SerializeObject(new StartupSettings { StartupPage = TINK.ViewTypes.ContactPage })));
}
2022-09-06 16:08:19 +02:00
}
2021-07-12 21:31:46 +02:00
}