diff --git a/Classifier.Outlook/core/Options.cs b/Classifier.Outlook/core/Options.cs index bf58bf0..e636166 100644 --- a/Classifier.Outlook/core/Options.cs +++ b/Classifier.Outlook/core/Options.cs @@ -5,6 +5,9 @@ namespace myoddweb.classifier.core { public sealed class Options : IOptions { + /// + /// The configuration insterface. + /// private readonly IConfig _config; private bool? _reAutomaticallyTrainMagnetMessages; @@ -45,12 +48,12 @@ public uint MinPercentage get { return (uint)(_minPercentage ?? - (_minPercentage = (Convert.ToUInt32(_config?.GetConfigWithDefault("Option.MinPercentage", Convert.ToString((uint)DefaultOptions.MinPercentage)))))); + (_minPercentage = (Convert.ToUInt32(_config.GetConfigWithDefault("Option.MinPercentage", Convert.ToString((uint)DefaultOptions.MinPercentage)))))); } set { _minPercentage = value; - _config?.SetConfig("Option.MinPercentage", Convert.ToString(value)); + _config.SetConfig("Option.MinPercentage", Convert.ToString(value)); } } @@ -63,12 +66,12 @@ public uint ClassifyDelaySeconds get { return (uint)(_classifyDelaySeconds ?? - (_classifyDelaySeconds = (Convert.ToUInt32(_config?.GetConfigWithDefault("Option.ClassifyDelaySeconds", "1"))))); + (_classifyDelaySeconds = (Convert.ToUInt32(_config.GetConfigWithDefault("Option.ClassifyDelaySeconds", "1"))))); } set { _classifyDelaySeconds = value; - _config?.SetConfig("Option.ClassifyDelaySeconds", Convert.ToString(value)); + _config.SetConfig("Option.ClassifyDelaySeconds", Convert.ToString(value)); } } @@ -86,12 +89,12 @@ public bool ReCheckCategories { get { return (bool) (_reCheckCategories ?? - (_reCheckCategories = ("1" == _config?.GetConfigWithDefault("Option.ReCheckCategories", "1")))); + (_reCheckCategories = ("1" == _config.GetConfigWithDefault("Option.ReCheckCategories", "1")))); } set { _reCheckCategories = value; - _config?.SetConfig("Option.ReCheckCategories", (value ? "1" : "0") ); + _config.SetConfig("Option.ReCheckCategories", (value ? "1" : "0") ); } } @@ -103,12 +106,12 @@ public bool ReAutomaticallyTrainMagnetMessages get { return (bool)(_reAutomaticallyTrainMagnetMessages ?? - (_reAutomaticallyTrainMagnetMessages = ("1" == _config?.GetConfigWithDefault("Option.ReAutomaticallyTrainMagnetMessages", "1")))); + (_reAutomaticallyTrainMagnetMessages = ("1" == _config.GetConfigWithDefault("Option.ReAutomaticallyTrainMagnetMessages", "1")))); } set { _reAutomaticallyTrainMagnetMessages = value; - _config?.SetConfig("Option.ReAutomaticallyTrainMagnetMessages", (value ? "1" : "0")); + _config.SetConfig("Option.ReAutomaticallyTrainMagnetMessages", (value ? "1" : "0")); } } @@ -122,12 +125,12 @@ public bool ReAutomaticallyTrainMessages get { return (bool)(_reAutomaticallyTrainMessages ?? - (_reAutomaticallyTrainMessages = ("1" == _config?.GetConfigWithDefault("Option.ReAutomaticallyTrainMessages", "0")))); + (_reAutomaticallyTrainMessages = ("1" == _config.GetConfigWithDefault("Option.ReAutomaticallyTrainMessages", "0")))); } set { _reAutomaticallyTrainMessages = value; - _config?.SetConfig("Option.ReAutomaticallyTrainMessages", (value ? "1" : "0")); + _config.SetConfig("Option.ReAutomaticallyTrainMessages", (value ? "1" : "0")); } } @@ -140,12 +143,12 @@ public bool ReCheckIfCtrlKeyIsDown get { return (bool)(_reCheckIfCtrlIsDown ?? - (_reCheckIfCtrlIsDown = ("1" == _config?.GetConfigWithDefault("Option.ReCheckIfCtrlKeyIsDown", "1")))); + (_reCheckIfCtrlIsDown = ("1" == _config.GetConfigWithDefault("Option.ReCheckIfCtrlKeyIsDown", "1")))); } set { _reCheckIfCtrlIsDown = value; - _config?.SetConfig("Option.ReCheckIfCtrlKeyIsDown", (value ? "1" : "0")); + _config.SetConfig("Option.ReCheckIfCtrlKeyIsDown", (value ? "1" : "0")); } } @@ -157,12 +160,12 @@ public uint MagnetsWeight get { return (uint)(_magnetsWeight ?? - (_magnetsWeight = (Convert.ToUInt32(_config?.GetConfigWithDefault("Option.MagnetsWeight", Convert.ToString( (uint)DefaultOptions.MagnetsWeight)))))); + (_magnetsWeight = (Convert.ToUInt32(_config.GetConfigWithDefault("Option.MagnetsWeight", Convert.ToString( (uint)DefaultOptions.MagnetsWeight)))))); } set { _magnetsWeight = value; - _config?.SetConfig("Option.MagnetsWeight", Convert.ToString(value)); + _config.SetConfig("Option.MagnetsWeight", Convert.ToString(value)); } } @@ -174,12 +177,12 @@ public uint UserWeight get { return (uint)(_userWeight ?? - (_userWeight = (Convert.ToUInt32(_config?.GetConfigWithDefault("Option.UserWeight", Convert.ToString( (uint)DefaultOptions.UserWeight)))))); + (_userWeight = (Convert.ToUInt32(_config.GetConfigWithDefault("Option.UserWeight", Convert.ToString( (uint)DefaultOptions.UserWeight)))))); } set { _userWeight = value; - _config?.SetConfig("Option.UserWeight", Convert.ToString(value)); + _config.SetConfig("Option.UserWeight", Convert.ToString(value)); } } @@ -191,12 +194,12 @@ public uint LogRetention get { return (uint)(_logRetention ?? - (_logRetention = Convert.ToUInt32(_config?.GetConfigWithDefault("Option.LogRetention", Convert.ToString((uint)DefaultOptions.LogRetention))))); + (_logRetention = Convert.ToUInt32(_config.GetConfigWithDefault("Option.LogRetention", Convert.ToString((uint)DefaultOptions.LogRetention))))); } set { _logRetention = value; - _config?.SetConfig("Option.LogRetention", Convert.ToString(value)); + _config.SetConfig("Option.LogRetention", Convert.ToString(value)); } } @@ -208,12 +211,12 @@ public uint LogDisplaySize get { return (uint)( _logDisplaySize ?? - (_logDisplaySize = Convert.ToUInt32(_config?.GetConfigWithDefault("Option.LogDisplaySize", Convert.ToString((uint)DefaultOptions.LogDisplaySize))))); + (_logDisplaySize = Convert.ToUInt32(_config.GetConfigWithDefault("Option.LogDisplaySize", Convert.ToString((uint)DefaultOptions.LogDisplaySize))))); } set { _logDisplaySize = value; - _config?.SetConfig("Option.LogDisplaySize", Convert.ToString(value)); + _config.SetConfig("Option.LogDisplaySize", Convert.ToString(value)); } } @@ -225,12 +228,12 @@ public LogLevels LogLevel get { return (LogLevels)(_logLevel ?? - (_logLevel = (LogLevels)(int.Parse(_config?.GetConfigWithDefault("Option.LogLevels", $"{(uint)DefaultOptions.LogLevel}"))))); + (_logLevel = (LogLevels)(int.Parse(_config.GetConfigWithDefault("Option.LogLevels", $"{(uint)DefaultOptions.LogLevel}"))))); } set { _logLevel = value; - _config?.SetConfig("Option.LogLevels", Convert.ToString( (int)value)); + _config.SetConfig("Option.LogLevels", Convert.ToString( (int)value)); } } @@ -243,12 +246,12 @@ public bool CheckUnProcessedEmailsOnStartUp get { return (bool)(_checkUnProcessedEmailsOnStartUp ?? - (_checkUnProcessedEmailsOnStartUp = ("1" == _config?.GetConfigWithDefault("Option.CheckUnProcessedEmailsOnStartUp", "1")))); + (_checkUnProcessedEmailsOnStartUp = ("1" == _config.GetConfigWithDefault("Option.CheckUnProcessedEmailsOnStartUp", "1")))); } set { _checkUnProcessedEmailsOnStartUp = value; - _config?.SetConfig("Option.CheckUnProcessedEmailsOnStartUp", (value ? "1" : "0")); + _config.SetConfig("Option.CheckUnProcessedEmailsOnStartUp", (value ? "1" : "0")); } } @@ -261,12 +264,12 @@ public bool CheckIfUnKnownCategory get { return (bool)(_checkIfUnknownCategory ?? - (_checkIfUnknownCategory = ("1" == _config?.GetConfigWithDefault("Option.CheckIfUnKnownCategory", "1")))); + (_checkIfUnknownCategory = ("1" == _config.GetConfigWithDefault("Option.CheckIfUnKnownCategory", "1")))); } set { _checkIfUnknownCategory = value; - _config?.SetConfig("Option.CheckIfUnKnownCategory", (value ? "1" : "0")); + _config.SetConfig("Option.CheckIfUnKnownCategory", (value ? "1" : "0")); } } @@ -275,12 +278,12 @@ public uint CommonWordsMinPercent get { return (uint)(_commonWordsMinPercent ?? - (_commonWordsMinPercent = Convert.ToUInt32(_config?.GetConfigWithDefault("Option.CommonWordsMinPercent", Convert.ToString((uint)DefaultOptions.CommonWordsMinPercent))))); + (_commonWordsMinPercent = Convert.ToUInt32(_config.GetConfigWithDefault("Option.CommonWordsMinPercent", Convert.ToString((uint)DefaultOptions.CommonWordsMinPercent))))); } set { _commonWordsMinPercent = value; - _config?.SetConfig("Option.CommonWordsMinPercent", Convert.ToString(value)); + _config.SetConfig("Option.CommonWordsMinPercent", Convert.ToString(value)); } } @@ -303,6 +306,11 @@ public bool CanLog(LogLevels level) public Options(IConfig config) { + // cannot be null. + if (config == null) + { + throw new ArgumentNullException(nameof(config)); + } _config = config; } } diff --git a/Classifier.Outlook/interfaces/IOptions.cs b/Classifier.Outlook/interfaces/IOptions.cs index 3486e5e..a1d8134 100644 --- a/Classifier.Outlook/interfaces/IOptions.cs +++ b/Classifier.Outlook/interfaces/IOptions.cs @@ -9,7 +9,13 @@ public enum DefaultOptions LogLevel = LogLevels.Error, LogRetention = 30, LogDisplaySize = 100, - ClassifyDelaySeconds = 1 + ClassifyDelaySeconds = 1, + ReCheckCategories = 1, + ReAutomaticallyTrainMagnetMessages = 1, + ReAutomaticallyTrainMessages = 0, + ReCheckIfCtrlKeyIsDown = 1, + CheckUnProcessedEmailsOnStartUp = 1, + CheckIfUnKnownCategory = 1 } public interface IOptions diff --git a/common/myoddweb.classifierUnitTest/TestOptions.cs b/common/myoddweb.classifierUnitTest/TestOptions.cs new file mode 100644 index 0000000..0587f1f --- /dev/null +++ b/common/myoddweb.classifierUnitTest/TestOptions.cs @@ -0,0 +1,518 @@ +using System; +using myoddweb.classifier.core; +using myoddweb.classifier.interfaces; +using Moq; +using NUnit.Framework; + +namespace myoddweb.classifierUnitTest +{ + [TestFixture] + public class TestOptions + { + [Test] + public void ctor_configCannotBeNull() + { + Assert.Throws(() => new Options(null) ); + } + + protected Mock CreateDefaultMock() + { + var config = new Mock(); + config.Setup(c => c.GetConfigWithDefault(It.IsAny(), It.IsAny())).Returns( + (string configName, string defaultValue) => defaultValue + ); + return config; + } + + protected Mock CreateDefaultMockWithReturn( string value ) + { + var config = new Mock(); + config.Setup(c => c.GetConfigWithDefault(It.IsAny(), It.IsAny())).Returns( + (string configName, string defaultValue) => value + ); + return config; + } + + protected Mock CreateSetMock(string value) + { + var config = new Mock(); + config.Setup(c => c.SetConfig(It.IsAny(), It.IsAny())).Returns( + (string configName, string defaultValue) => true + ); + return config; + } + + [Test] + public void MinPercentage_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options( config.Object ); + Assert.That( options.MinPercentage == (uint)DefaultOptions.MinPercentage ); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.MinPercentage", It.IsAny()), Times.Once); + } + + [Test] + [TestCase("10")] + [TestCase("100")] + [TestCase("200")] + public void MinPercentage_SetValue(string value) + { + var config = CreateSetMock(value); + var options = new Options(config.Object) + { + MinPercentage = Convert.ToUInt32(value) + }; + + // check that we only called the function once + config.Verify(h => h.SetConfig(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.SetConfig("Option.MinPercentage", value), Times.Once); + } + + [Test] + public void ClassifyDelaySeconds_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.ClassifyDelaySeconds == (uint)DefaultOptions.ClassifyDelaySeconds); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.ClassifyDelaySeconds", It.IsAny()), Times.Once); + } + + [Test] + [TestCase("10")] + [TestCase("100")] + [TestCase("200")] + public void ClassifyDelaySeconds_SetValue(string value) + { + var config = CreateSetMock( value ); + var options = new Options(config.Object) + { + ClassifyDelaySeconds = Convert.ToUInt32(value) + }; + + // check that we only called the function once + config.Verify(h => h.SetConfig(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.SetConfig("Option.ClassifyDelaySeconds", value ), Times.Once); + } + + [Test] + [TestCase("10")] + [TestCase("100")] + [TestCase("200")] + public void ClassifyDelaySeconds_GetConfigValue( string value) + { + var config = CreateDefaultMockWithReturn( value ); + var options = new Options(config.Object); + Assert.That(options.ClassifyDelaySeconds == Convert.ToUInt32(value)); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.ClassifyDelaySeconds", It.IsAny()), Times.Once); + } + + [Test] + public void ClassifyDelayMilliseconds_GetDefaultFromClassifyDelaySeconds() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.ClassifyDelayMilliseconds == (uint)DefaultOptions.ClassifyDelaySeconds*1000); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.ClassifyDelaySeconds", It.IsAny()), Times.Once); + } + + [Test] + public void ReCheckCategories_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.ReCheckCategories == ((uint)DefaultOptions.ReCheckCategories == 1)); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.ReCheckCategories", It.IsAny()), Times.Once); + } + + [Test] + [TestCase("1")] + [TestCase("0")] + public void ReCheckCategories_SetValue(string value) + { + var config = CreateSetMock(value); + var options = new Options(config.Object) + { + ReCheckCategories = 1 == Convert.ToUInt32(value) + }; + + // check that we only called the function once + config.Verify(h => h.SetConfig(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.SetConfig("Option.ReCheckCategories", value), Times.Once); + } + + [Test] + public void ReAutomaticallyTrainMagnetMessages_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.ReAutomaticallyTrainMagnetMessages == ((uint)DefaultOptions.ReAutomaticallyTrainMagnetMessages == 1)); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.ReAutomaticallyTrainMagnetMessages", It.IsAny()), Times.Once); + } + + [Test] + [TestCase("1")] + [TestCase("0")] + public void ReAutomaticallyTrainMagnetMessages_SetValue(string value) + { + var config = CreateSetMock(value); + var options = new Options(config.Object) + { + ReAutomaticallyTrainMagnetMessages = 1 == Convert.ToUInt32(value) + }; + + // check that we only called the function once + config.Verify(h => h.SetConfig(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.SetConfig("Option.ReAutomaticallyTrainMagnetMessages", value), Times.Once); + } + + [Test] + public void ReAutomaticallyTrainMessages_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.ReAutomaticallyTrainMessages == ((uint)DefaultOptions.ReAutomaticallyTrainMessages == 1)); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.ReAutomaticallyTrainMessages", It.IsAny()), Times.Once); + } + + [Test] + [TestCase("1")] + [TestCase("0")] + public void ReAutomaticallyTrainMessages_SetValue(string value) + { + var config = CreateSetMock(value); + var options = new Options(config.Object) + { + ReAutomaticallyTrainMessages = 1 == Convert.ToUInt32(value) + }; + + // check that we only called the function once + config.Verify(h => h.SetConfig(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.SetConfig("Option.ReAutomaticallyTrainMessages", value), Times.Once); + } + + [Test] + public void ReCheckIfCtrlKeyIsDown_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.ReCheckIfCtrlKeyIsDown == ((uint)DefaultOptions.ReCheckIfCtrlKeyIsDown == 1)); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.ReCheckIfCtrlKeyIsDown", It.IsAny()), Times.Once); + } + + [Test] + [TestCase("1")] + [TestCase("0")] + public void ReCheckIfCtrlKeyIsDown_SetValue(string value) + { + var config = CreateSetMock(value); + var options = new Options(config.Object) + { + ReCheckIfCtrlKeyIsDown = 1 == Convert.ToUInt32(value) + }; + + // check that we only called the function once + config.Verify(h => h.SetConfig(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.SetConfig("Option.ReCheckIfCtrlKeyIsDown", value), Times.Once); + } + + [Test] + public void MagnetsWeight_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.MagnetsWeight == (uint)DefaultOptions.MagnetsWeight ); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.MagnetsWeight", It.IsAny()), Times.Once); + } + + [Test] + [TestCase("10")] + [TestCase("100")] + [TestCase("50")] + public void MagnetsWeight_SetConfigValue(string value) + { + var config = CreateSetMock(value); + var options = new Options(config.Object) + { + MagnetsWeight = Convert.ToUInt32(value) + }; + + // check that we only called the function once + config.Verify(h => h.SetConfig(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.SetConfig("Option.MagnetsWeight", value), Times.Once); + } + + [Test] + public void UserWeight_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.UserWeight == (uint)DefaultOptions.UserWeight); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.UserWeight", It.IsAny()), Times.Once); + } + + [Test] + [TestCase("10")] + [TestCase("100")] + [TestCase("50")] + public void UserWeight_SetConfigValue(string value) + { + var config = CreateSetMock(value); + var options = new Options(config.Object) + { + UserWeight = Convert.ToUInt32(value) + }; + + // check that we only called the function once + config.Verify(h => h.SetConfig(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.SetConfig("Option.UserWeight", value), Times.Once); + } + + [Test] + public void LogRetention_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.LogRetention == (uint)DefaultOptions.LogRetention); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.LogRetention", It.IsAny()), Times.Once); + } + + [Test] + [TestCase("10")] + [TestCase("100")] + [TestCase("50")] + public void LogRetention_SetConfigValue(string value) + { + var config = CreateSetMock(value); + var options = new Options(config.Object) + { + LogRetention = Convert.ToUInt32(value) + }; + + // check that we only called the function once + config.Verify(h => h.SetConfig(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.SetConfig("Option.LogRetention", value), Times.Once); + } + + [Test] + public void LogDisplaySize_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.LogDisplaySize == (uint)DefaultOptions.LogDisplaySize); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.LogDisplaySize", It.IsAny()), Times.Once); + } + + [Test] + [TestCase("10")] + [TestCase("100")] + [TestCase("50")] + public void LogDisplaySize_SetConfigValue(string value) + { + var config = CreateSetMock(value); + var options = new Options(config.Object) + { + LogDisplaySize = Convert.ToUInt32(value) + }; + + // check that we only called the function once + config.Verify(h => h.SetConfig(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.SetConfig("Option.LogDisplaySize", value), Times.Once); + } + + [Test] + public void LogLevel_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.LogLevel == (LogLevels)DefaultOptions.LogLevel); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.LogLevels", It.IsAny()), Times.Once); + } + + [Test] + public void CheckUnProcessedEmailsOnStartUp_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.CheckUnProcessedEmailsOnStartUp == ((uint)DefaultOptions.CheckUnProcessedEmailsOnStartUp == 1 )); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.CheckUnProcessedEmailsOnStartUp", It.IsAny()), Times.Once); + } + + [Test] + [TestCase("1")] + [TestCase("0")] + public void CheckUnProcessedEmailsOnStartUp_SetValue(string value) + { + var config = CreateSetMock(value); + var options = new Options(config.Object) + { + CheckUnProcessedEmailsOnStartUp = 1 == Convert.ToUInt32(value) + }; + + // check that we only called the function once + config.Verify(h => h.SetConfig(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.SetConfig("Option.CheckUnProcessedEmailsOnStartUp", value), Times.Once); + } + + [Test] + public void CheckIfUnKnownCategory_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.CheckIfUnKnownCategory == ((uint)DefaultOptions.CheckIfUnKnownCategory == 1)); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.CheckIfUnKnownCategory", It.IsAny()), Times.Once); + } + + [Test] + [TestCase("1")] + [TestCase("0")] + public void CheckIfUnKnownCategory_SetValue(string value) + { + var config = CreateSetMock(value); + var options = new Options(config.Object) + { + CheckIfUnKnownCategory = 1 == Convert.ToUInt32(value) + }; + + // check that we only called the function once + config.Verify(h => h.SetConfig(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.SetConfig("Option.CheckIfUnKnownCategory", value), Times.Once); + } + + [Test] + public void CommonWordsMinPercent_GetDefault() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.That(options.CommonWordsMinPercent == (uint)DefaultOptions.CommonWordsMinPercent); + + // check that we only called the function once + config.Verify(h => h.GetConfigWithDefault(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.GetConfigWithDefault("Option.CommonWordsMinPercent", It.IsAny()), Times.Once); + } + + [Test] + [TestCase("10")] + [TestCase("100")] + [TestCase("50")] + public void CommonWordsMinPercent_SetConfigValue(string value) + { + var config = CreateSetMock(value); + var options = new Options(config.Object) + { + CommonWordsMinPercent = Convert.ToUInt32(value) + }; + + // check that we only called the function once + config.Verify(h => h.SetConfig(It.IsAny(), It.IsAny()), Times.Once); + // and that the correct param was passed. + config.Verify(h => h.SetConfig("Option.CommonWordsMinPercent", value), Times.Once); + } + + [Test] + public void CanLog_None() + { + var config = CreateDefaultMock(); + var options = new Options(config.Object); + Assert.False(options.CanLog( LogLevels.None)); + } + + [Test] + [TestCase(LogLevels.Error, LogLevels.Error, true )] // [Error] only up to error + [TestCase(LogLevels.Error, LogLevels.Warning, false)] + [TestCase(LogLevels.Error, LogLevels.Information, false)] + [TestCase(LogLevels.Error, LogLevels.Verbose, false)] + [TestCase(LogLevels.Warning, LogLevels.Error, true)] // [Warning] up to warning + [TestCase(LogLevels.Warning, LogLevels.Warning, true)] + [TestCase(LogLevels.Warning, LogLevels.Information, false)] + [TestCase(LogLevels.Warning, LogLevels.Verbose, false)] + [TestCase(LogLevels.Information, LogLevels.Error, true)] // [Information] up to information + [TestCase(LogLevels.Information, LogLevels.Warning, true)] + [TestCase(LogLevels.Information, LogLevels.Information, true)] + [TestCase(LogLevels.Information, LogLevels.Verbose, false)] + [TestCase(LogLevels.Verbose, LogLevels.Error, true)] // [Verbose] all cases + [TestCase(LogLevels.Verbose, LogLevels.Warning, true)] + [TestCase(LogLevels.Verbose, LogLevels.Information, true)] + [TestCase(LogLevels.Verbose, LogLevels.Verbose, true)] + public void CanLog( LogLevels current, LogLevels check, bool expected ) + { + var config = CreateDefaultMockWithReturn( Convert.ToString((uint)current)); + var options = new Options(config.Object); + Assert.That( options.CanLog(check) == expected ); + + config.Verify(h => h.GetConfigWithDefault("Option.LogLevels", It.IsAny()), Times.Once); + } + } +} diff --git a/common/myoddweb.classifierUnitTest/myoddweb.classifierUnitTest.csproj b/common/myoddweb.classifierUnitTest/myoddweb.classifierUnitTest.csproj index 5aac986..e441ce0 100644 --- a/common/myoddweb.classifierUnitTest/myoddweb.classifierUnitTest.csproj +++ b/common/myoddweb.classifierUnitTest/myoddweb.classifierUnitTest.csproj @@ -82,6 +82,7 @@ + diff --git a/common/myoddweb.classifierUnitTest/myoddweb.classifierUnitTest64.csproj b/common/myoddweb.classifierUnitTest/myoddweb.classifierUnitTest64.csproj index 502b225..dea84e4 100644 --- a/common/myoddweb.classifierUnitTest/myoddweb.classifierUnitTest64.csproj +++ b/common/myoddweb.classifierUnitTest/myoddweb.classifierUnitTest64.csproj @@ -88,6 +88,7 @@ +