2022-08-30 15:42:25 +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 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.Fixtures.ObjectTests
|
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.
|
|
|
|
|
var l_oDict = new Dictionary<string, string>()
|
|
|
|
|
.SetPollingParameters(new PollingParameters(new TimeSpan(0, 0, 0, 15, 0), false));
|
|
|
|
|
|
|
|
|
|
// Deserialize parameters.
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
l_oDict.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()
|
|
|
|
|
{
|
|
|
|
|
var l_oDict = new Dictionary<string, string>()
|
|
|
|
|
.SetCopriHostUri("http://1.2.3.4");
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
JsonSettingsDictionary.GetCopriHostUri(l_oDict), 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()
|
|
|
|
|
{
|
|
|
|
|
var l_oDictionary = new Dictionary<string, string>()
|
|
|
|
|
.SetMinimumLoggingLevel(0); // Verbose = 0
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(
|
|
|
|
|
JsonSettingsDictionary.GetMinimumLoggingLevel(l_oDictionary), 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()
|
|
|
|
|
{
|
|
|
|
|
var l_oDict = new Dictionary<string, string>();
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(JsonSettingsDictionary.GetAppVersion(l_oDict), Is.Null);
|
2022-09-06 16:08:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetAppVersion_LegacyTo115()
|
|
|
|
|
{
|
|
|
|
|
var l_oDict = new Dictionary<string, string> { { "AppVersion", "7.2.3.9" } };
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(JsonSettingsDictionary.GetAppVersion(l_oDict), Is.EqualTo(new Version(7, 2, 3, 9)));
|
2022-09-06 16:08:19 +02:00
|
|
|
|
|
|
|
|
|
l_oDict = new Dictionary<string, string> { { "AppVersion", "7.2.3" } };
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(JsonSettingsDictionary.GetAppVersion(l_oDict), Is.EqualTo(new Version(7, 2, 3)));
|
2022-09-06 16:08:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetAppVersion_Json()
|
|
|
|
|
{
|
|
|
|
|
var l_oDict = new Dictionary<string, string> { { "AppVersion", "\"3.1.2.117\"" } };
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(JsonSettingsDictionary.GetAppVersion(l_oDict), Is.EqualTo(new Version(3, 1, 2, 117)));
|
2022-09-06 16:08:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestSetAppVersion_Json()
|
|
|
|
|
{
|
|
|
|
|
var l_oDict = new Dictionary<string, string>()
|
|
|
|
|
.SetAppVersion(new Version(47, 12, 3));
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(JsonSettingsDictionary.GetAppVersion(l_oDict), Is.EqualTo(new Version(47, 12, 3)));
|
2022-09-06 16:08:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetShowWhatsNew_FirstInstall()
|
|
|
|
|
{
|
|
|
|
|
var l_oDict = new Dictionary<string, string>();
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(JsonSettingsDictionary.GetWhatsNew(l_oDict), Is.Null);
|
2022-09-06 16:08:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestGetShowWhatsNew_Json()
|
|
|
|
|
{
|
|
|
|
|
var l_oDict = new Dictionary<string, string> { { "ShowWhatsNew", "\"3.1.2.117\"" } };
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(JsonSettingsDictionary.GetWhatsNew(l_oDict), Is.EqualTo(new Version(3, 1, 2, 117)));
|
2022-09-06 16:08:19 +02:00
|
|
|
|
|
|
|
|
|
l_oDict = new Dictionary<string, string> { { "ShowWhatsNew", "\"3.1.2\"" } };
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(JsonSettingsDictionary.GetWhatsNew(l_oDict), Is.EqualTo(new Version(3, 1, 2)));
|
2022-09-06 16:08:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestSetShowWhats_Json()
|
|
|
|
|
{
|
|
|
|
|
var l_oDict = new Dictionary<string, string>()
|
|
|
|
|
.SetWhatsNew(new Version(47, 12, 3));
|
2024-04-09 12:53:23 +02:00
|
|
|
|
Assert.That(JsonSettingsDictionary.GetWhatsNew(l_oDict), Is.EqualTo(new Version(47, 12, 3)));
|
2022-09-06 16:08:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-12 21:31:46 +02:00
|
|
|
|
}
|