public void ProjectInfo_ExtensionMethods_GetAndSet() { // 0. Setup AnalysisConfig config = new AnalysisConfig(); AnalysisSetting setting; string result; // 1. Get/TryGet missing setting result = config.GetSetting("missing", "123"); Assert.IsFalse(config.TryGetSetting("missing", out setting), "Setting should not have been found"); Assert.AreEqual("123", config.GetSetting("missing", "123"), "Expecting the default setting to be returned"); // 2. Set and get a previously new setting config.SetValue("id1", "value1"); Assert.IsTrue(config.TryGetSetting("id1", out setting), "Setting should have been found"); Assert.AreEqual("value1", setting.Value, "Unexpected value returned for setting"); Assert.AreEqual("value1", config.GetSetting("id1", "123"), "Unexpected value returned for setting"); // 3. Update and refetch the setting config.SetValue("id1", "updated value"); Assert.IsTrue(config.TryGetSetting("id1", out setting), "Setting should have been found"); Assert.AreEqual("updated value", setting.Value, "Unexpected value returned for setting"); Assert.AreEqual("updated value", config.GetSetting("id1", "123"), "Unexpected value returned for setting"); }
private string TryGetRegularExpression(AnalysisConfig config) { Debug.Assert(config != null, "Not expecting the supplied config to be null"); AnalysisSetting setting; string regEx = null; if (config.TryGetSetting(TestRegExSettingId, out setting)) { regEx = setting.Value; } if (!string.IsNullOrWhiteSpace(regEx)) { this.Log.LogMessage(MessageImportance.Low, Resources.IsTest_UsingRegExFromConfig, regEx); } return(regEx); }