public void CanCreateConfigurationSourceFromConfigurationElement() { ManageableConfigurationSourceElement element = new ManageableConfigurationSourceElement( "manageable", AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, "testapp", true, false); element.ConfigurationManageabilityProviders.Add(new ConfigurationSectionManageabilityProviderData("section1", typeof(MockConfigurationSectionManageabilityProvider))); element.ConfigurationManageabilityProviders.Get(0).ManageabilityProviders.Add(new ConfigurationElementManageabilityProviderData("1", typeof(MockConfigurationElementManageabilityProvider), typeof(String))); element.ConfigurationManageabilityProviders.Add(new ConfigurationSectionManageabilityProviderData("section2", typeof(MockConfigurationSectionManageabilityProvider))); element.ConfigurationManageabilityProviders.Get(1).ManageabilityProviders.Add(new ConfigurationElementManageabilityProviderData("2", typeof(MockConfigurationElementManageabilityProvider), typeof(Boolean))); element.ConfigurationManageabilityProviders.Get(1).ManageabilityProviders.Add(new ConfigurationElementManageabilityProviderData("3", typeof(MockConfigurationElementManageabilityProvider), typeof(Int32))); IConfigurationSource configurationSource = element.InvokeCreateSource(); Assert.IsNotNull(configurationSource); Assert.AreSame(typeof(ManageableConfigurationSource), configurationSource.GetType()); ManageableConfigurationSourceImplementation implementation = ((ManageableConfigurationSource)configurationSource).Implementation; Assert.AreSame(typeof(ManageabilityHelper), implementation.ManageabilityHelper.GetType()); ManageabilityHelper manageabilityHelper = (ManageabilityHelper)implementation.ManageabilityHelper; Assert.AreEqual(2, manageabilityHelper.ManageabilityProviders.Count); }
public void ConfigurationCanBeDeserialized() { ConfigurationManager.RefreshSection(ConfigurationSourceSection.SectionName); ConfigurationSourceSection section = (ConfigurationSourceSection)ConfigurationManager.GetSection(ConfigurationSourceSection.SectionName); Assert.IsNotNull(section); Assert.AreEqual(1, section.Sources.Count); ManageableConfigurationSourceElement element = section.Sources.Get(0) as ManageableConfigurationSourceElement; Assert.IsNotNull(element); Assert.AreEqual(2, element.ConfigurationManageabilityProviders.Count); ConfigurationSectionManageabilityProviderData data1 = element.ConfigurationManageabilityProviders.Get("section1"); Assert.IsNotNull(data1); Assert.AreEqual(typeof(MockConfigurationSectionManageabilityProvider), data1.Type); Assert.AreEqual(3, data1.ManageabilityProviders.Count); ConfigurationElementManageabilityProviderData elementData11 = data1.ManageabilityProviders.Get("subProvider1"); Assert.IsNotNull(elementData11); Assert.AreEqual(typeof(Object), elementData11.TargetType); ConfigurationSectionManageabilityProviderData data2 = element.ConfigurationManageabilityProviders.Get("section2"); Assert.IsNotNull(data2); Assert.AreEqual(typeof(MockConfigurationSectionManageabilityProvider), data1.Type); Assert.AreEqual(0, data2.ManageabilityProviders.Count); }
public void AppropriateDefaultsAreSet() { ManageableConfigurationSourceElement element = new ManageableConfigurationSourceElement(); Assert.AreEqual(true, element.EnableGroupPolicies); Assert.AreEqual(string.Empty, element.FilePath); Assert.AreEqual("Application", element.ApplicationName); }
protected override void Arrange() { base.Arrange(); Mock <AssemblyLocator> assemblyLocator = new Mock <AssemblyLocator>(); assemblyLocator.Setup(x => x.Assemblies).Returns(new Assembly[] { typeof(ManageableConfigurationSourceElement).Assembly }); this.Container.RegisterType <ManageableConfigurationSourceViewModel>( new InjectionConstructor( typeof(ElementCollectionViewModel), typeof(ConfigurationElement), new InjectionParameter <AssemblyLocator>(assemblyLocator.Object))); targetFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "manageableSourcetextnp.config"); File.Create(targetFilePath).Dispose(); File.WriteAllText(targetFilePath, "<configuration/>"); var source = new DesignConfigurationSource(targetFilePath); ConfigurationSourceElement = new ManageableConfigurationSourceElement { Name = "manageable", FilePath = "file.config", ConfigurationManageabilityProviders = { new ConfigurationSectionManageabilityProviderData { Name = "provider", TypeName = typeof(object).AssemblyQualifiedName } } }; var section = new ConfigurationSourceSection { SelectedSource = "manageable", Sources = { ConfigurationSourceElement } }; source.AddLocalSection(ConfigurationSourceSection.SectionName, section); var sourceModel = this.Container.Resolve <ConfigurationSourceModel>(); sourceModel.Load(source); SectionViewModel = sourceModel.Sections.Where(x => x.ConfigurationType == typeof(ConfigurationSourceSection)).Single(); ConfigurationSourceViewModel = SectionViewModel.GetDescendentsOfType <ManageableConfigurationSourceElement>().FirstOrDefault(); ConfigurationSourceElement = (ManageableConfigurationSourceElement)ConfigurationSourceViewModel.ConfigurationElement; }
/// <summary> /// /// </summary> /// <param name="element"></param> public ManageableConfigurationSourceElementNode(ManageableConfigurationSourceElement element) : base(null == element ? string.Empty : element.Name) { if (null == element) { throw new ArgumentNullException("element"); } this.filePath = element.FilePath; this.type = element.Type; this.enableWmi = element.EnableWmi; this.enableGroupPolicies = element.EnableGroupPolicies; this.applicationName = element.ApplicationName; }
public void CanCreateElementFromNode() { ManageableConfigurationSourceElement originalElement = new ManageableConfigurationSourceElement("name", "test.config", "app", true, false); ManageableConfigurationSourceElementNode node = new ManageableConfigurationSourceElementNode(originalElement); String[] assemblyNames = new String[] { Assembly.GetExecutingAssembly().GetName().Name + ".dll" }; ManageableConfigurationSourceElementBuilder builder = new ManageableConfigurationSourceElementBuilder(node, new ConfigurationManageabilityProviderAttributeRetriever(assemblyNames)); ManageableConfigurationSourceElement createdElement = builder.Build(); Assert.AreEqual(originalElement.Name, createdElement.Name); Assert.AreEqual(originalElement.FilePath, createdElement.FilePath); Assert.AreEqual(originalElement.ApplicationName, createdElement.ApplicationName); Assert.AreEqual(originalElement.EnableGroupPolicies, createdElement.EnableGroupPolicies); Assert.AreEqual(originalElement.EnableWmi, createdElement.EnableWmi); }
public void ConfigurationElementWithProvidersCanBeSerialized() { string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); ExeConfigurationFileMap configMap = new ExeConfigurationFileMap(); configMap.ExeConfigFilename = otherConfigurationFile; File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); try { SysConfig.Configuration rwConfiguration = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None); ConfigurationSourceSection rwConfigurationSourceSection = rwConfiguration.GetSection(ConfigurationSourceSection.SectionName) as ConfigurationSourceSection; rwConfigurationSourceSection.Sources.Clear(); ManageableConfigurationSourceElement rwConfigurationSourceElement = new ManageableConfigurationSourceElement("manageable", otherConfigurationFile, "TestApplication"); rwConfigurationSourceElement.ConfigurationManageabilityProviders.Add(new ConfigurationSectionManageabilityProviderData("section1", typeof(MockConfigurationSectionManageabilityProvider))); rwConfigurationSourceSection.Sources.Add(rwConfigurationSourceElement); rwConfiguration.Save(); SysConfig.Configuration roConfiguration = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None); ConfigurationSourceSection roConfigurationSourceSection = roConfiguration.GetSection(ConfigurationSourceSection.SectionName) as ConfigurationSourceSection; Assert.IsNotNull(roConfigurationSourceSection); Assert.AreEqual(1, roConfigurationSourceSection.Sources.Count); ManageableConfigurationSourceElement roConfigurationSourceElement = roConfigurationSourceSection.Sources.Get("manageable") as ManageableConfigurationSourceElement; Assert.IsNotNull(roConfigurationSourceElement); Assert.AreEqual(1, roConfigurationSourceElement.ConfigurationManageabilityProviders.Count); ConfigurationSectionManageabilityProviderData roProviderData = roConfigurationSourceElement.ConfigurationManageabilityProviders.Get(0); Assert.AreEqual("section1", roProviderData.Name); } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
protected override void Arrange() { base.Arrange(); base.Arrange(); var resourceHelper = new ResourceHelper <ConfigFiles.ConfigFileLocator>(); mainFilePath = resourceHelper.DumpResourceFileToDisk("empty.config", "ds_mgmt_subdir_path"); mainConfigurationSource = new DesignConfigurationSource(mainFilePath); configurationSourceElement = new ManageableConfigurationSourceElement("relativefile", "subdir\\relative.config", "app"); var mainFileDirectory = Path.GetDirectoryName(mainFilePath); expectedFilePath = Path.Combine(mainFileDirectory, configurationSourceElement.FilePath); Directory.CreateDirectory(Path.GetDirectoryName(expectedFilePath)); }
public ManageableConfigurationSourceElement Build() { ManageableConfigurationSourceElement element = new ManageableConfigurationSourceElement( this.node.Name, this.node.File, this.node.ApplicationName, this.node.EnableGroupPolicies, this.node.EnableWmi); foreach (ConfigurationSectionManageabilityProviderData data in BuildSectionManageabilityProvidersData(retriever.SectionManageabilityProviderAttributes, retriever.ElementManageabilityProviderAttributes)) { element.ConfigurationManageabilityProviders.Add(data); } return(element); }
public void CanCreateElementFromNewNode() { ManageableConfigurationSourceElementNode node = new ManageableConfigurationSourceElementNode(); node.Name = "name"; node.File = "test.config"; node.ApplicationName = "app"; node.EnableGroupPolicies = true; node.EnableWmi = false; String[] assemblyNames = new String[] { typeof(MockConfigurationSectionManageabilityProvider).Assembly.GetName().Name + ".dll" }; ManageableConfigurationSourceElementBuilder builder = new ManageableConfigurationSourceElementBuilder(node, new ConfigurationManageabilityProviderAttributeRetriever(assemblyNames)); ManageableConfigurationSourceElement createdElement = builder.Build(); Assert.AreEqual(node.Name, createdElement.Name); Assert.AreEqual(node.File, createdElement.FilePath); Assert.AreEqual(node.ApplicationName, createdElement.ApplicationName); Assert.AreEqual(node.EnableGroupPolicies, createdElement.EnableGroupPolicies); Assert.AreEqual(node.EnableWmi, createdElement.EnableWmi); Assert.AreEqual(1, createdElement.ConfigurationManageabilityProviders.Count); }