public void CreateTest() { ElementReferenceConfiguration elementReferenceConfiguration = new ElementReferenceConfiguration(); // // Verify default state // Assert.IsNull(elementReferenceConfiguration.Id, "Unexpected default value for Id."); }
public void ToStringTest() { ElementReferenceConfiguration elementReference = new ElementReferenceConfiguration(); elementReference.Id = "SomeId"; string str = elementReference.ToString(); Assert.AreEqual("Element Reference: SomeId", str, "Unexpected string representation."); }
/// <summary> /// Creates an element arranger using the specified configuration information. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="parentConfiguration">The parent configuration.</param> /// <returns> /// Returns an IElementArranger if succesful, otherwise null. /// </returns> public static IElementArranger CreateElementArranger( ConfigurationElement configuration, ConfigurationElement parentConfiguration) { IElementArranger arranger = null; if (configuration == null) { throw new ArgumentNullException("configuration"); } // // If this is an element reference, build the arranger using the referenced // element configuration instead. // ElementReferenceConfiguration elementReference = configuration as ElementReferenceConfiguration; if (elementReference != null && elementReference.ReferencedElement != null) { configuration = elementReference.ReferencedElement; } ElementConfiguration elementConfiguration = configuration as ElementConfiguration; if (elementConfiguration != null) { arranger = new ElementArranger(elementConfiguration, parentConfiguration); } else { RegionConfiguration regionConfiguration = configuration as RegionConfiguration; if (regionConfiguration != null) { arranger = new RegionArranger(regionConfiguration, parentConfiguration); } else { arranger = CreateChildrenArranger(configuration); } } return(arranger); }
public void DefaultTest() { CodeConfiguration defaultConfig = CodeConfiguration.Default; Assert.IsNotNull(defaultConfig, "Default configuration should not be null."); Assert.AreEqual(7, defaultConfig.Elements.Count, "Unexpected number of root level elements."); // // Handlers // Assert.IsNotNull(defaultConfig.Handlers, "Handlers collection should not be null."); Assert.AreEqual(4, defaultConfig.Handlers.Count, "Unexpected number of default handlers."); ProjectHandlerConfiguration msbuildProjectHandlerConfiguration = defaultConfig.Handlers[0] as ProjectHandlerConfiguration; Assert.IsNotNull(msbuildProjectHandlerConfiguration, "Expected a project handler configuration."); Assert.AreEqual(2, msbuildProjectHandlerConfiguration.ProjectExtensions.Count, "Unexpected number of project handler extensions."); ProjectHandlerConfiguration monoDevelopProjectHandlerConfiguration = defaultConfig.Handlers[1] as ProjectHandlerConfiguration; Assert.IsNotNull(monoDevelopProjectHandlerConfiguration, "Expected a project handler configuration."); Assert.AreEqual(1, monoDevelopProjectHandlerConfiguration.ProjectExtensions.Count, "Unexpected number of project handler extensions."); SourceHandlerConfiguration csharpHandler = defaultConfig.Handlers[2] as SourceHandlerConfiguration; Assert.IsNotNull(csharpHandler, "Expected a source handler configuration."); Assert.IsTrue(csharpHandler.AssemblyName.Contains("NArrange.CSharp")); Assert.AreEqual("CSharp", csharpHandler.Language); Assert.IsNotNull(csharpHandler.SourceExtensions[0].FilterBy); SourceHandlerConfiguration visualBasicHandler = defaultConfig.Handlers[3] as SourceHandlerConfiguration; Assert.IsNotNull(visualBasicHandler, "Expected a source handler configuration."); Assert.IsTrue(visualBasicHandler.AssemblyName.Contains("NArrange.VisualBasic")); Assert.AreEqual("VisualBasic", visualBasicHandler.Language); Assert.IsNotNull(visualBasicHandler.SourceExtensions[0].FilterBy); // // Formatting // Assert.IsNotNull(defaultConfig.Formatting.Tabs, "Tab configuration should not be null."); Assert.AreEqual(TabStyle.Spaces, defaultConfig.Formatting.Tabs.TabStyle, "Unexpected tab style."); Assert.AreEqual(4, defaultConfig.Formatting.Tabs.SpacesPerTab, "Unexpected number of spaces per tab."); Assert.IsNotNull(defaultConfig.Formatting.ClosingComments, "Closing comment configuration should not be null."); Assert.IsFalse(defaultConfig.Formatting.ClosingComments.Enabled, "Unexpected value for closing comments enabled."); Assert.IsNotNull(defaultConfig.Formatting.Regions, "Region configuration should not be null."); Assert.AreEqual( defaultConfig.Formatting.Regions.Style, RegionStyle.Default, "Unexpected default value for region style."); Assert.IsNotNull(defaultConfig.Formatting.LineSpacing, "Line spacing configuration should not be null."); Assert.IsTrue( defaultConfig.Formatting.LineSpacing.RemoveConsecutiveBlankLines, "Unexpected default value for remove consecutive blank lines."); Assert.IsNotNull(defaultConfig.Formatting.Usings, "Using configuration should not be null."); Assert.AreEqual( CodeLevel.Namespace, defaultConfig.Formatting.Usings.MoveTo, "Unexpected default value for moving usings."); // // Global region settings // Assert.IsTrue(defaultConfig.Formatting.Regions.EndRegionNameEnabled); // // Header comment region // RegionConfiguration commentRegion = defaultConfig.Elements[0] as RegionConfiguration; Assert.IsNotNull(commentRegion, "Expected a RegionConfiguration."); ElementConfiguration commentElement = commentRegion.Elements[0] as ElementConfiguration; Assert.AreEqual(ElementType.Comment, commentElement.ElementType, "Unexpected element type."); Assert.IsNull(commentElement.GroupBy, "Expected grouping to not be specified."); Assert.IsNotNull(commentElement.FilterBy, "Expected a filter to be specified."); // // Using elements // ElementConfiguration usingElement = defaultConfig.Elements[1] as ElementConfiguration; Assert.IsNotNull(usingElement, "Expected an ElementConfiguration."); Assert.AreEqual(ElementType.Using, usingElement.ElementType, "Unexpected element type."); Assert.IsNotNull(usingElement.GroupBy, "Expected grouping to be specified."); Assert.AreEqual(ElementAttributeType.Type, usingElement.GroupBy.By, "Expected type grouping."); Assert.IsNotNull(usingElement.GroupBy.InnerGroupBy, "Expected inner grouping to be specified."); Assert.AreEqual(ElementAttributeType.Name, usingElement.GroupBy.InnerGroupBy.By, "Expected name grouping."); Assert.IsNotNull(usingElement.SortBy, "Expected a sort to be specified."); Assert.AreEqual(ElementAttributeType.Name, usingElement.SortBy.By, "Expected name sorting."); // // Assembly attributes // ElementConfiguration attributeElement = defaultConfig.Elements[2] as ElementConfiguration; Assert.IsNotNull(attributeElement, "Expected an ElementConfiguration"); Assert.AreEqual(ElementType.Attribute, attributeElement.ElementType, "Unexpected element type."); Assert.IsNull(attributeElement.SortBy, "Expected a sort to not be specified."); // // Conditional directives // ElementConfiguration conditionDirectiveElemement = defaultConfig.Elements[3] as ElementConfiguration; Assert.IsNotNull(attributeElement, "Expected an ElementConfiguration"); Assert.AreEqual(ElementType.ConditionDirective, conditionDirectiveElemement.ElementType, "Unexpected element type."); // // Element references // ElementReferenceConfiguration interfaceReference = defaultConfig.Elements[4] as ElementReferenceConfiguration; Assert.AreEqual("DefaultInterface", interfaceReference.Id, "Unexpected reference Id."); Assert.IsNotNull(interfaceReference.ReferencedElement, "Referenced element should not be null."); ElementReferenceConfiguration typeReference = defaultConfig.Elements[5] as ElementReferenceConfiguration; Assert.AreEqual("DefaultType", typeReference.Id, "Unexpected reference Id."); Assert.IsNotNull(typeReference.ReferencedElement, "Referenced element should not be null."); // // Namespace elements // ElementConfiguration namespaceElement = defaultConfig.Elements[6] as ElementConfiguration; Assert.IsNotNull(namespaceElement, "Expected an ElementConfiguration."); Assert.AreEqual(ElementType.Namespace, namespaceElement.ElementType, "Unexpected element type."); //// TODO: Verify entire heirarchy }
public void SerializeAndDeserializeTest() { CodeConfiguration origConfig = new CodeConfiguration(); ElementConfiguration elementConfiguration1 = new ElementConfiguration(); elementConfiguration1.ElementType = ElementType.Using; elementConfiguration1.Id = "TestId"; origConfig.Elements.Add(elementConfiguration1); ElementConfiguration elementConfiguration2 = new ElementConfiguration(); elementConfiguration2.ElementType = ElementType.Namespace; origConfig.Elements.Add(elementConfiguration2); ElementReferenceConfiguration elementReferenceConfiguration = new ElementReferenceConfiguration(); elementReferenceConfiguration.Id = "TestId"; origConfig.Elements.Add(elementReferenceConfiguration); RegionConfiguration regionConfiguration = new RegionConfiguration(); regionConfiguration.Name = "Test Region"; origConfig.Elements.Add(regionConfiguration); origConfig.ResolveReferences(); Assert.AreEqual( elementConfiguration1.Elements.Count, elementReferenceConfiguration.ReferencedElement.Elements.Count, "Element reference was not resolved."); string tempFile = Path.GetTempFileName(); try { // // Save the configuration to an XML file // origConfig.Save(tempFile); // // Load the configuration from the XML file // CodeConfiguration loadedConfig = CodeConfiguration.Load(tempFile); Assert.IsNotNull(loadedConfig, "Loaded configuration should not be null."); Assert.AreEqual(origConfig.Elements.Count, loadedConfig.Elements.Count, "An unexpected number of config elements were deserialized."); for (int index = 0; index < origConfig.Elements.Count; index++) { if (origConfig.Elements[index] is ElementConfiguration) { ElementConfiguration origElement = origConfig.Elements[index] as ElementConfiguration; ElementConfiguration loadedElement = loadedConfig.Elements[index] as ElementConfiguration; Assert.AreEqual(origElement.ElementType, loadedElement.ElementType, "Unexpected element type."); } else if (origConfig.Elements[index] is ElementReferenceConfiguration) { ElementReferenceConfiguration origElement = origConfig.Elements[index] as ElementReferenceConfiguration; ElementReferenceConfiguration loadedElement = loadedConfig.Elements[index] as ElementReferenceConfiguration; Assert.AreEqual(origElement.Id, loadedElement.Id, "Unexpected element type."); Assert.AreEqual( origElement.ReferencedElement.Id, loadedElement.ReferencedElement.Id, "Unexpected referenced element."); } else if (origConfig.Elements[index] is RegionConfiguration) { RegionConfiguration origRegion = origConfig.Elements[index] as RegionConfiguration; RegionConfiguration loadedRegion = loadedConfig.Elements[index] as RegionConfiguration; Assert.AreEqual(origRegion.Name, loadedRegion.Name, "Unexpected region name."); } } } finally { File.Delete(tempFile); } }