using System;
using System.Collections.Generic;
using NUnit.Framework;
using Serilog.Events;
using ShareeBike.Model.Settings;
using ShareeBike.Settings;
namespace SharedBusinessLogic.Tests.Fixtures.ObjectTests
{
[TestFixture]
public class TestJsonSettingsDictionary
{
/// Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.
[Test]
public void TestGetCopriHostUri_NoFile()
{
Assert.That(JsonSettingsDictionary.GetCopriHostUri(new Dictionary()), Is.Null);
}
/// Verifies that empty log file leads to expected default value and doesn not throw exceptions.
[Test]
public void TestGetPolling()
{
// Serialize parameters.
var l_oDict = new Dictionary()
.SetPollingParameters(new PollingParameters(new TimeSpan(0, 0, 0, 15, 0), false));
// Deserialize parameters.
Assert.That(
l_oDict.GetPollingParameters(), Is.EqualTo(new PollingParameters(new TimeSpan(0, 0, 0, 15, 0), false)));
}
/// Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.
[Test]
public void TestGetPolling_NoFile()
{
Assert.That(JsonSettingsDictionary.GetPollingParameters(new Dictionary()), Is.Null);
}
[Test]
public void TestGetGetCopriHostUri()
{
var l_oDict = new Dictionary()
.SetCopriHostUri("http://1.2.3.4");
Assert.That(
JsonSettingsDictionary.GetCopriHostUri(l_oDict), Is.EqualTo(new Uri("http://1.2.3.4")));
}
/// Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.
[Test]
public void TestGetLoggingLevel()
{
var l_oDictionary = new Dictionary()
.SetMinimumLoggingLevel(0); // Verbose = 0
Assert.That(
JsonSettingsDictionary.GetMinimumLoggingLevel(l_oDictionary), Is.EqualTo(LogEventLevel.Verbose)); // LogEventLevel.Error = 4
}
/// Verifies that empty log fiel leads to expected default value and doesn not throw exceptions.
[Test]
public void TestGetLoggingLevel_NoFile()
{
Assert.That(JsonSettingsDictionary.GetMinimumLoggingLevel(new Dictionary()), Is.Null);
}
[Test]
public void TestGetAppVersion_FirstInstall()
{
var l_oDict = new Dictionary();
Assert.That(JsonSettingsDictionary.GetAppVersion(l_oDict), Is.Null);
}
[Test]
public void TestGetAppVersion_LegacyTo115()
{
var l_oDict = new Dictionary { { "AppVersion", "7.2.3.9" } };
Assert.That(JsonSettingsDictionary.GetAppVersion(l_oDict), Is.EqualTo(new Version(7, 2, 3, 9)));
l_oDict = new Dictionary { { "AppVersion", "7.2.3" } };
Assert.That(JsonSettingsDictionary.GetAppVersion(l_oDict), Is.EqualTo(new Version(7, 2, 3)));
}
[Test]
public void TestGetAppVersion_Json()
{
var l_oDict = new Dictionary { { "AppVersion", "\"3.1.2.117\"" } };
Assert.That(JsonSettingsDictionary.GetAppVersion(l_oDict), Is.EqualTo(new Version(3, 1, 2, 117)));
}
[Test]
public void TestSetAppVersion_Json()
{
var l_oDict = new Dictionary()
.SetAppVersion(new Version(47, 12, 3));
Assert.That(JsonSettingsDictionary.GetAppVersion(l_oDict), Is.EqualTo(new Version(47, 12, 3)));
}
[Test]
public void TestGetShowWhatsNew_FirstInstall()
{
var l_oDict = new Dictionary();
Assert.That(JsonSettingsDictionary.GetWhatsNew(l_oDict), Is.Null);
}
[Test]
public void TestGetShowWhatsNew_Json()
{
var l_oDict = new Dictionary { { "ShowWhatsNew", "\"3.1.2.117\"" } };
Assert.That(JsonSettingsDictionary.GetWhatsNew(l_oDict), Is.EqualTo(new Version(3, 1, 2, 117)));
l_oDict = new Dictionary { { "ShowWhatsNew", "\"3.1.2\"" } };
Assert.That(JsonSettingsDictionary.GetWhatsNew(l_oDict), Is.EqualTo(new Version(3, 1, 2)));
}
[Test]
public void TestSetShowWhats_Json()
{
var l_oDict = new Dictionary()
.SetWhatsNew(new Version(47, 12, 3));
Assert.That(JsonSettingsDictionary.GetWhatsNew(l_oDict), Is.EqualTo(new Version(47, 12, 3)));
}
}
}