public void DefaultNodeTest() { ConfigurationSectionCollectionNode node = new ConfigurationSectionCollectionNode(); CreateHierarchyAndAddToHierarchyService(node, CreateDefaultConfiguration()); Assert.AreEqual(1, node.Nodes.Count); Assert.AreEqual(SR.DefaultEncryptionSettingsNodeName, node.Nodes[0].Name); }
/// <summary> /// <para>Opens the configuration settings and registers them with the application.</para> /// </summary> /// <param name="serviceProvider"> /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para> /// </param> public void Open(IServiceProvider serviceProvider) { ConfigurationContext configurationContext = ServiceHelper.GetCurrentConfigurationContext(serviceProvider); ConfigurationSectionCollectionNode sectionsNode = null; ConfigurationNode configurationNode = ServiceHelper.GetCurrentRootNode(serviceProvider); RemoveCurrentConfigurationSectionCollectionNode(serviceProvider); try { string appName = SR.DefaultApplicationName; ConfigurationSettings configurationSettings = configurationContext.GetMetaConfiguration(); if (null != configurationSettings) { appName = configurationSettings.ApplicationName; if (configurationSettings.ConfigurationSections.Count > 0) { sectionsNode = new ConfigurationSectionCollectionNode(configurationSettings); configurationNode.Nodes.Add(sectionsNode); } } if (configurationNode is ApplicationConfigurationNode) { ((ApplicationConfigurationNode)configurationNode).Name = appName; } } catch (ConfigurationException e) { ServiceHelper.LogError(serviceProvider, sectionsNode, e); } }
public void FindByPathTest() { ApplicationConfigurationNode appNode = new ApplicationConfigurationNode(ApplicationData.FromCurrentAppDomain()); ConfigurationSectionCollectionNode node = new ConfigurationSectionCollectionNode(); hierarchy.RootNode = appNode; appNode.Nodes.Add(node); node.Nodes.Add(new ConfigurationSectionNode()); ConfigurationNode foundNode = hierarchy.FindNodeByPath(node.Path); Assert.AreSame(node, foundNode); }
public void FindByTypeGrandChildTest() { ApplicationConfigurationNode appNode = new ApplicationConfigurationNode(ApplicationData.FromCurrentAppDomain()); ConfigurationSectionCollectionNode node = new ConfigurationSectionCollectionNode(); hierarchy.RootNode = appNode; appNode.Nodes.Add(node); node.Nodes.Add(new ConfigurationSectionCollectionNode()); ConfigurationNode[] foundNodes = hierarchy.FindNodesByType(typeof(ConfigurationSectionCollectionNode)); Assert.AreEqual(2, foundNodes.Length); }
public void OpenTest() { Assert.AreEqual(0, GeneratedApplicationNode.Nodes.Count); manager.Register(Host); manager.Open(Host); Assert.AreEqual(SR.DefaultConfigurationSectionCollectionNodeName, GeneratedApplicationNode.Nodes[0].Name); ConfigurationSectionCollectionNode sectionsNode = GeneratedApplicationNode.Nodes[0] as ConfigurationSectionCollectionNode; Assert.IsNotNull(sectionsNode); Assert.AreEqual("Test", sectionsNode.Nodes[1].Name); }
public void ExecuteTest() { AddConfigurationSectionCommand command = new AddConfigurationSectionCommand(Host, typeof(MockConfigurationNode), "mySection"); command.Execute(GeneratedApplicationNode); Assert.AreEqual(2, GeneratedApplicationNode.Nodes.Count); ConfigurationSectionCollectionNode collectionNode = (ConfigurationSectionCollectionNode)GeneratedHierarchy.FindNodeByType(GeneratedApplicationNode, typeof(ConfigurationSectionCollectionNode)); Assert.IsNotNull(collectionNode); ConfigurationSectionNode sectionNode = GeneratedHierarchy.FindNodeByName(collectionNode, "mySection") as ConfigurationSectionNode; Assert.IsNotNull(sectionNode); }
private ConfigurationSectionCollectionNode SelectConfigurationSectionsNode() { IUIHierarchy hierarchy = UIHierarchyService.SelectedHierarchy; ApplicationConfigurationNode applicationNode = hierarchy.RootNode as ApplicationConfigurationNode; Debug.Assert(applicationNode != null, "Expected an application node to be root for this node."); ConfigurationSectionCollectionNode sectionsNode = (ConfigurationSectionCollectionNode)hierarchy.FindNodeByType(hierarchy.RootNode, typeof(ConfigurationSectionCollectionNode)); if (sectionsNode == null) { sectionsNode = new ConfigurationSectionCollectionNode(); applicationNode.Nodes.AddWithDefaultChildren(sectionsNode); } return sectionsNode; }
public void CanFindHierarchyTest() { ConfigurationDesignHost host = new ConfigurationDesignHost(); UIHierarchyService hierarchyService = host.GetService(typeof(IUIHierarchyService)) as UIHierarchyService; Assert.IsNotNull(hierarchyService); ApplicationConfigurationNode appNode = new ApplicationConfigurationNode(ApplicationData.FromCurrentAppDomain()); UIHierarchy hierarchy = new UIHierarchy(appNode, host, new ConfigurationContext(appNode.ConfigurationFile)); ConfigurationSectionCollectionNode node = new ConfigurationSectionCollectionNode(); appNode.Nodes.Add(node); node.Nodes.Add(new ConfigurationSectionNode()); hierarchyService.AddHierarchy(hierarchy); IUIHierarchy foundHierarchy = hierarchyService.GetHierarchy(appNode.Id); Assert.AreSame(hierarchy, foundHierarchy); }
public void FindByTypeTwoTopSearchFromOneLowerChildTest() { ApplicationConfigurationNode appNode = new ApplicationConfigurationNode(ApplicationData.FromCurrentAppDomain()); ConfigurationSectionCollectionNode node = new ConfigurationSectionCollectionNode(); hierarchy.RootNode = appNode; appNode.Nodes.Add(node); EncryptionSettingsNode node2 = new EncryptionSettingsNode(); ConfigurationSectionCollectionNode node3 = new ConfigurationSectionCollectionNode(); appNode.Nodes.Add(node2); node2.Nodes.Add(node3); node3.Nodes.Add(new ConfigurationSectionNode()); node3.Nodes.Add(new ConfigurationSectionNode()); ConfigurationNode[] foundNodes = hierarchy.FindNodesByType(typeof(ConfigurationSectionNode)); Assert.AreEqual(2, foundNodes.Length); }
public void AddHierarchyAndEventFiredTest() { ConfigurationDesignHost host = new ConfigurationDesignHost(); UIHierarchyService hierarchyService = host.GetService(typeof(IUIHierarchyService)) as UIHierarchyService; hierarchyService.HierarchyAdded += new HierarchyAddedEventHandler(OnHierarchyAdded); Assert.IsNotNull(hierarchyService); ApplicationConfigurationNode appNode = new ApplicationConfigurationNode(ApplicationData.FromCurrentAppDomain()); IUIHierarchy hierarchy = new UIHierarchy(appNode, host, new ConfigurationContext(appNode.ConfigurationFile)); hierarchyService.AddHierarchy(hierarchy); Assert.IsTrue(addEventCalled); Assert.AreEqual(1, addEventCount); Assert.AreSame(hierarchy, eventHierarchy); ConfigurationSectionCollectionNode node = new ConfigurationSectionCollectionNode(); appNode.Nodes.Add(node); node.Nodes.Add(new ConfigurationSectionNode()); Assert.AreEqual(1, hierarchyService.hierarchies.Count); }
public override void SetUp() { base.SetUp(); INodeCreationService nodeCreationService = GetService(typeof(INodeCreationService)) as INodeCreationService; Assert.IsNotNull(nodeCreationService); Type nodeType = typeof(CustomKeyAlgorithmStorageProviderNode); NodeCreationEntry entry = NodeCreationEntry.CreateNodeCreationEntryNoMultiples(new AddChildNodeCommand(Host, nodeType), nodeType, typeof(CustomKeyAlgorithmPairStorageProviderData), SR.CustomKeyAlgorithmPairStorageProviderNodeDefaultName); nodeCreationService.AddNodeCreationEntry(entry); nodeType = typeof(CustomTransformerNode); entry = NodeCreationEntry.CreateNodeCreationEntryNoMultiples(new AddChildNodeCommand(Host, nodeType), nodeType, typeof(CustomTransformerData), SR.CustomTransformerNodeDefaultName); nodeCreationService.AddNodeCreationEntry(entry); nodeType = typeof(CustomStorageProviderNode); entry = NodeCreationEntry.CreateNodeCreationEntryNoMultiples(new AddChildNodeCommand(Host, nodeType), nodeType, typeof(CustomStorageProviderData), SR.CustomStorageProviderNodeDefaultName); nodeCreationService.AddNodeCreationEntry(entry); nodeType = typeof(XmlFileStorageProviderNode); entry = NodeCreationEntry.CreateNodeCreationEntryNoMultiples(new AddChildNodeCommand(Host, nodeType), nodeType, typeof(XmlFileStorageProviderData), SR.XMLStorageProviderNodeFriendlyName); nodeCreationService.AddNodeCreationEntry(entry); nodeType = typeof(XmlSerializerTransformerNode); entry = NodeCreationEntry.CreateNodeCreationEntryNoMultiples(new AddChildNodeCommand(Host, nodeType), nodeType, typeof(XmlSerializerTransformerData), SR.XmlSerializerTransformerNodeFriendlyName); nodeCreationService.AddNodeCreationEntry(entry); nodeType = typeof(ConfigurationSectionNode); entry = NodeCreationEntry.CreateNodeCreationEntryNoMultiples(new AddChildNodeCommand(Host, nodeType), nodeType, typeof(ConfigurationSectionData), SR.ConfigurationSectionNodeFriendlyName); nodeCreationService.AddNodeCreationEntry(entry); nodeType = typeof(ReadOnlyConfigurationSectionNode); entry = NodeCreationEntry.CreateNodeCreationEntryNoMultiples(new AddChildNodeCommand(Host, nodeType), nodeType, typeof(ReadOnlyConfigurationSectionData), SR.ReadOnlyConfigurationSectionNodeFriendlyName); nodeCreationService.AddNodeCreationEntry(entry); nodeType = typeof(FileKeyAlgorithmPairStorageProviderNode); entry = NodeCreationEntry.CreateNodeCreationEntryNoMultiples(new AddFileKeyAlgorithmPairNodeCommand(Host, nodeType), nodeType, typeof(FileKeyAlgorithmPairStorageProviderData), SR.FileKeyAlgorithmStorageProviderNodeFriendlyName); nodeCreationService.AddNodeCreationEntry(entry); configurationSectionsNode = new ConfigurationSectionCollectionNode(ConfigurationSettingsBuilder.Create()); Assert.IsNotNull(configurationSectionsNode); CreateHierarchyAndAddToHierarchyService(configurationSectionsNode, CreateDefaultConfiguration()); }
public void MakeSureThatIncludeTypesAreAddedForTheSection() { AddConfigurationSectionCommand cmd = new AddConfigurationSectionCommand(Host, typeof(MyConfigurationNode), section); cmd.Execute(GeneratedApplicationNode); ConfigurationSectionCollectionNode node = (ConfigurationSectionCollectionNode)GeneratedHierarchy.FindNodeByType(typeof(ConfigurationSectionCollectionNode)); Assert.IsNotNull(node); ConfigurationSectionNode sectionNode = (ConfigurationSectionNode)GeneratedHierarchy.FindNodeByName(node, section); ConfigurationNode[] types = GeneratedHierarchy.FindNodesByType(sectionNode, typeof(XmlIncludeTypeNode)); Assert.AreEqual(1, types.Length); XmlIncludeTypeNode xmlIncludeTypeNode = types[0] as XmlIncludeTypeNode; Assert.IsNotNull(xmlIncludeTypeNode); Assert.AreEqual(xmlIncludeTypeNode.Name, typeof(MyConfigurationData).Name); }
public void TwoNodesShareTheSameConfigurationAndIncludeTypeRemoveOneIncludeTypeRemains() { AddConfigurationSectionCommand cmd = new AddConfigurationSectionCommand(Host, typeof(MyConfigurationNode), section); cmd.Execute(GeneratedApplicationNode); cmd.Execute(GeneratedApplicationNode); ConfigurationNode secondAddedNode = cmd.ChildNode; RemoveNodeCommand removeNodeCommand = new RemoveNodeCommand(Host); removeNodeCommand.Execute(secondAddedNode); ConfigurationSectionCollectionNode node = (ConfigurationSectionCollectionNode)GeneratedHierarchy.FindNodeByType(typeof(ConfigurationSectionCollectionNode)); Assert.IsNotNull(node); ConfigurationSectionNode sectionNode = (ConfigurationSectionNode)GeneratedHierarchy.FindNodeByName(node, section); ConfigurationNode[] types = GeneratedHierarchy.FindNodesByType(sectionNode, typeof(XmlIncludeTypeNode)); Assert.AreEqual(1, types.Length); XmlIncludeTypeNode xmlIncludeTypeNode = types[0] as XmlIncludeTypeNode; Assert.IsNotNull(xmlIncludeTypeNode); Assert.AreEqual(xmlIncludeTypeNode.Name, typeof(MyConfigurationData).Name); }
public void SaveTest() { manager.Register(Host); manager.Open(Host); Assert.AreEqual(SR.DefaultConfigurationSectionCollectionNodeName, GeneratedApplicationNode.Nodes[0].Name); ConfigurationSectionCollectionNode sectionsNode = GeneratedApplicationNode.Nodes[0] as ConfigurationSectionCollectionNode; Assert.IsNotNull(sectionsNode); Assert.AreEqual("Test", sectionsNode.Nodes[1].Name); manager.Save(Host); GeneratedApplicationNode.Nodes.Clear(); Assert.AreEqual(0, GeneratedApplicationNode.childNodeLookup.Count); ApplicationConfigurationNode node = new ApplicationConfigurationNode(ApplicationData.FromCurrentAppDomain()); IUIHierarchy hierarchy = CreateHierarchyAndAddToHierarchyService(node, CreateDefaultConfiguration()); base.HierarchyService.SelectedHierarchy = hierarchy; manager.Open(Host); Assert.AreEqual(1, node.Nodes.Count); Assert.AreEqual(SR.DefaultConfigurationSectionCollectionNodeName, node.Nodes[0].Name); sectionsNode = node.Nodes[0] as ConfigurationSectionCollectionNode; Assert.IsNotNull(sectionsNode); Assert.AreEqual("Test", sectionsNode.Nodes[1].Name); manager.Save(Host); }