public void NonCachedResults() { // Just check if expression is analyzed completely. // Non cached results allow rescan with same objects DependenciesSection section = TestHelper.GetDependenciesSection(); MockDependenciesInfoBuilder builder = new MockDependenciesInfoBuilder(); builder.MockEvaluator.ReturnValues.Add("Reg1", true); builder.MockEvaluator.ReturnValues.Add("Reg2", true); builder.MockEvaluator.ReturnValues.Add("Soft1", true); builder.MockEvaluator.ResetHitsPerCheck(); DependenciesInfo info = builder.BuildDependenciesInfo(section, 200); bool checkValue1 = info.EvaluationContext.Evaluate(info.Dependencies[0].Check); bool checkValue2 = info.EvaluationContext.Evaluate(info.Dependencies[1].Check); Assert.IsTrue(checkValue1); Assert.IsTrue(checkValue2); Assert.AreEqual(2, builder.MockEvaluator.HitsPerCheck["Reg1"]); Assert.AreEqual(2, builder.MockEvaluator.HitsPerCheck["Reg2"]); Assert.AreEqual(0, builder.MockEvaluator.HitsPerCheck["Soft1"]); checkValue1 = info.EvaluationContext.Evaluate(info.Dependencies[0].Check); checkValue2 = info.EvaluationContext.Evaluate(info.Dependencies[1].Check); Assert.IsTrue(checkValue1); Assert.IsTrue(checkValue2); Assert.AreEqual(4, builder.MockEvaluator.HitsPerCheck["Reg1"]); Assert.AreEqual(4, builder.MockEvaluator.HitsPerCheck["Reg2"]); Assert.AreEqual(0, builder.MockEvaluator.HitsPerCheck["Soft1"]); }
public DependenciesInfo BuildDependenciesInfo(DependenciesSection configSection, int osBuild) { bool supported = TryGetOsBuildNumber(configSection, ref osBuild); if (!supported) { throw new NotSupportedOperatingSystemException(osBuild); } var info = new DependenciesInfo { CompatibleOsBuild = osBuild, EvaluationContext = new EvaluationContext(), Dependencies = new List <Dependency>() }; // Add common checks & dependencies this.AddDependencyChecks(info, configSection.CommonChecks); this.AddDependencies(info, configSection.MinimumRequirements.Dependencies); // Add OS checks & dependencies DependencyGroup osDependencyGroup = configSection.DependencyGroups.GetDependencyGroupByOsBuild(osBuild); if (osDependencyGroup != null) { this.AddDependencyChecks(info, osDependencyGroup.Checks); this.AddDependencies(info, osDependencyGroup.Dependencies); } // Add evaluators this.AddCheckEvaluators((EvaluationContext)info.EvaluationContext, configSection.CheckEvaluators); return(info); }
private void InitializeConfigurationSection() { const string configurationFileName = "App.config"; string configFilePath = Path.Combine(Path.GetTempPath(), configurationFileName); TextReader configReader = new StreamReader(this.GetType().Assembly.GetManifestResourceStream(this.GetType().Namespace + "." + configurationFileName)); File.WriteAllText(configFilePath, configReader.ReadToEnd()); var map = new ExeConfigurationFileMap { ExeConfigFilename = configFilePath }; this.fileConfig = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); this.configSection = (DependenciesSection)this.fileConfig.GetSection(DependenciesSection.SectionName); try { this.dependenciesInfo = this.GetDependenciesInfoBuilder().BuildDependenciesInfo(this.configSection); } catch (NotSupportedException e) { MessageBox.Show(e.Message, @"OS Not Supported", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(-1); } }
public void LoadsDependeciesList() { DependenciesSection section = TestHelper.GetDependenciesSection(); var builder = new DependenciesInfoBuilder(null); DependenciesInfo info = builder.BuildDependenciesInfo(section, 200); Assert.AreEqual(2, info.Dependencies.Count); Assert.AreEqual("MinimumRequirement", info.Dependencies[0].Title); Assert.AreEqual(true, info.Dependencies[0].Enabled); Assert.AreEqual("This might be handy in all cases", info.Dependencies[0].Explanation); Assert.AreEqual("http://www.microsoft.com", info.Dependencies[0].DownloadUrl); Assert.IsTrue(string.IsNullOrEmpty(info.Dependencies[0].InfoUrl)); Assert.IsTrue(string.IsNullOrEmpty(info.Dependencies[0].ScriptName)); Assert.AreEqual("Optional", info.Dependencies[0].Category); Assert.AreEqual("Reg2", info.Dependencies[0].Check); Assert.AreEqual("Microsoft Visual Studio 2005", info.Dependencies[1].Title); Assert.AreEqual(true, info.Dependencies[1].Enabled); Assert.AreEqual("In order to use the Guidance Package, you will need to install Visual Studio 2005", info.Dependencies[1].Explanation); Assert.AreEqual("http://www.microsoft.com/VisualStudio", info.Dependencies[1].DownloadUrl); Assert.IsTrue(string.IsNullOrEmpty(info.Dependencies[1].InfoUrl)); Assert.IsTrue(string.IsNullOrEmpty(info.Dependencies[1].ScriptName)); Assert.AreEqual("MyCategory", info.Dependencies[1].Category); Assert.AreEqual("(Reg1 || Soft1) && Exp12", info.Dependencies[1].Check); }
public void CanLoadOSSpecificChecksConfiguration() { Configuration config = TestHelper.GetConfiguration(); DependenciesSection dcSection = (DependenciesSection)config.GetSection(DependenciesSection.SectionName); Assert.AreEqual(2, dcSection.DependencyGroups["MockOS"].Checks.Count); }
public void CanLoadCommonChecksConfiguration() { Configuration config = TestHelper.GetConfiguration(); DependenciesSection dcSection = (DependenciesSection)config.GetSection(DependenciesSection.SectionName); DependencyCheckCollection commonChecks = dcSection.CommonChecks; Assert.AreEqual(6, commonChecks.Count); }
public void CustomOSChecksOverrideCommonChecks() { DependenciesSection section = TestHelper.GetDependenciesSection(); var builder = new DependenciesInfoBuilder(null); DependenciesInfo info = builder.BuildDependenciesInfo(section, 100); Assert.AreEqual(7, TestHelper.Count(info.EvaluationContext.GetCheckNames())); }
public void CommonChecksAreIncluded() { DependenciesSection section = TestHelper.GetDependenciesSection(); var builder = new DependenciesInfoBuilder(null); DependenciesInfo info = builder.BuildDependenciesInfo(section, 300); Assert.AreEqual(6, TestHelper.Count(info.EvaluationContext.GetCheckNames())); }
public void FindsExactMatch() { DependenciesSection section = TestHelper.GetDependenciesSection(); var builder = new DependenciesInfoBuilder(null); DependenciesInfo info = builder.BuildDependenciesInfo(section, 100); Assert.IsNotNull(info); Assert.AreEqual(100, info.CompatibleOsBuild); }
private static bool TryGetOsBuildNumber(DependenciesSection configSection, ref int currentOsBuild) { int minimumOsBuild; if (!int.TryParse(configSection.MinimumRequirements.MinimumOsBuild, out minimumOsBuild)) { throw new ConfigurationErrorsException("MinimumOSBuild property of MinimumRequirements element is not in correct format. Expected integer"); } return(minimumOsBuild <= currentOsBuild); }
public void CanLoadOSConfiguration() { Configuration config = TestHelper.GetConfiguration(); DependenciesSection dcSection = (DependenciesSection)config.GetSection(DependenciesSection.SectionName); Assert.IsNotNull(dcSection); DependencyGroupCollection commonChecks = dcSection.DependencyGroups; Assert.IsNotNull(commonChecks); Assert.AreEqual(4, commonChecks.Count); }
public void ChecksMinimumBuildNumber() { DependenciesSection section = TestHelper.GetDependenciesSection(); var builder = new DependenciesInfoBuilder(null); builder.BuildDependenciesInfo(section, 20); try { builder.BuildDependenciesInfo(section, 5); Assert.Fail("Does not check for minimum build."); } catch (NotSupportedOperatingSystemException) { } }
public void CheckAnalysisIsPropagated2() { DependenciesSection section = TestHelper.GetDependenciesSection(); MockDependenciesInfoBuilder builder = new MockDependenciesInfoBuilder(); builder.MockEvaluator.ReturnValues.Add("Reg1", false); builder.MockEvaluator.ReturnValues.Add("Reg2", false); builder.MockEvaluator.ResetHitsPerCheck(); DependenciesInfo info = builder.BuildDependenciesInfo(section, 400); bool checkValue1 = info.EvaluationContext.Evaluate(info.Dependencies[0].Check); bool checkValue2 = info.EvaluationContext.Evaluate(info.Dependencies[1].Check); Assert.IsFalse(checkValue1); Assert.IsFalse(checkValue2); Assert.AreEqual(1, builder.MockEvaluator.HitsPerCheck["Reg1"]); Assert.AreEqual(1, builder.MockEvaluator.HitsPerCheck["Reg2"]); }
public DependenciesInfo BuildDependenciesInfo(DependenciesSection configSection) { return(this.BuildDependenciesInfo(configSection, OperatingSystem.GetOsBuild())); }