using NUnit.Framework; using Serilog.Events; using System; using System.Collections.Generic; using TINK.Model.Settings; using TINK.Settings; namespace TestTINKLib.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.IsNull(JsonSettingsDictionary.GetCopriHostUri(new Dictionary())); } /// 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.AreEqual( new PollingParameters(new TimeSpan(0, 0, 0, 15, 0), false), l_oDict.GetPollingParameters()); } /// Verifies that empty log fiel leads to expected default value and doesn not throw exceptions. [Test] public void TestGetPolling_NoFile() { Assert.IsNull(JsonSettingsDictionary.GetPollingParameters(new Dictionary())); } [Test] public void TestGetGetCopriHostUri() { var l_oDict = new Dictionary() .SetCopriHostUri("http://1.2.3.4"); Assert.AreEqual( new Uri("http://1.2.3.4"), JsonSettingsDictionary.GetCopriHostUri(l_oDict)); } /// 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.AreEqual( LogEventLevel.Verbose, JsonSettingsDictionary.GetMinimumLoggingLevel(l_oDictionary)); // LogEventLevel.Error = 4 } /// Verifies that empty log fiel leads to expected default value and doesn not throw exceptions. [Test] public void TestGetLoggingLevel_NoFile() { Assert.IsNull(JsonSettingsDictionary.GetMinimumLoggingLevel(new Dictionary())); } [Test] public void TestGetAppVersion_FirstInstall() { var l_oDict = new Dictionary (); Assert.IsNull(JsonSettingsDictionary.GetAppVersion(l_oDict)); } [Test] public void TestGetAppVersion_LegacyTo115() { var l_oDict = new Dictionary { { "AppVersion", "7.2.3.9" } }; Assert.AreEqual(new Version(7,2,3,9), JsonSettingsDictionary.GetAppVersion(l_oDict)); l_oDict = new Dictionary { { "AppVersion", "7.2.3" } }; Assert.AreEqual(new Version(7, 2, 3), JsonSettingsDictionary.GetAppVersion(l_oDict)); } [Test] public void TestGetAppVersion_Json() { var l_oDict = new Dictionary { { "AppVersion", "\"3.1.2.117\"" } }; Assert.AreEqual(new Version(3, 1, 2, 117), JsonSettingsDictionary.GetAppVersion(l_oDict)); } [Test] public void TestSetAppVersion_Json() { var l_oDict = new Dictionary() .SetAppVersion(new Version(47, 12, 3)); Assert.AreEqual(new Version(47, 12, 3), JsonSettingsDictionary.GetAppVersion(l_oDict)); } [Test] public void TestGetShowWhatsNew_FirstInstall() { var l_oDict = new Dictionary(); Assert.IsNull(JsonSettingsDictionary.GetWhatsNew(l_oDict)); } [Test] public void TestGetShowWhatsNew_Json() { var l_oDict = new Dictionary { { "ShowWhatsNew", "\"3.1.2.117\"" } }; Assert.AreEqual(new Version(3, 1, 2, 117), JsonSettingsDictionary.GetWhatsNew(l_oDict)); l_oDict = new Dictionary { { "ShowWhatsNew", "\"3.1.2\"" } }; Assert.AreEqual(new Version(3, 1, 2), JsonSettingsDictionary.GetWhatsNew(l_oDict)); } [Test] public void TestSetShowWhats_Json() { var l_oDict = new Dictionary() .SetWhatsNew(new Version(47, 12, 3)); Assert.AreEqual(new Version(47, 12, 3), JsonSettingsDictionary.GetWhatsNew(l_oDict)); } } }