Skip to content

Commit

Permalink
Added a few Options test for set/get and defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Guelfucci committed Oct 19, 2017
1 parent 4fb9067 commit 2c12cfd
Show file tree
Hide file tree
Showing 5 changed files with 563 additions and 29 deletions.
64 changes: 36 additions & 28 deletions Classifier.Outlook/core/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace myoddweb.classifier.core
{
public sealed class Options : IOptions
{
/// <summary>
/// The configuration insterface.
/// </summary>
private readonly IConfig _config;

private bool? _reAutomaticallyTrainMagnetMessages;
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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));
}
}

Expand All @@ -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") );
}
}

Expand All @@ -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"));
}
}

Expand All @@ -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"));
}
}

Expand All @@ -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"));
}
}

Expand All @@ -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));
}
}

Expand All @@ -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));
}
}

Expand All @@ -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));
}
}

Expand All @@ -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));
}
}

Expand All @@ -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));
}
}

Expand All @@ -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"));
}
}

Expand All @@ -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"));
}
}

Expand All @@ -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));
}
}

Expand All @@ -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;
}
}
Expand Down
8 changes: 7 additions & 1 deletion Classifier.Outlook/interfaces/IOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 2c12cfd

Please sign in to comment.