public HomeController(IOptions <RegionConfiguration> regionConfiguration) { _regionConfiguration = regionConfiguration.Value; }
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 ArrangeNestedRegionTest() { List <ICodeElement> elements = new List <ICodeElement>(); TypeElement type = new TypeElement(); type.Type = TypeElementType.Class; type.Name = "TestClass"; FieldElement field = new FieldElement(); field.Name = "val"; field.Type = "int"; type.AddChild(field); elements.Add(type); // Create a configuration with a nested region CodeConfiguration codeConfiguration = new CodeConfiguration(); ElementConfiguration typeConfiguration = new ElementConfiguration(); typeConfiguration.ElementType = ElementType.Type; RegionConfiguration regionConfiguration1 = new RegionConfiguration(); regionConfiguration1.Name = "Region1"; RegionConfiguration regionConfiguration2 = new RegionConfiguration(); regionConfiguration2.Name = "Region2"; ElementConfiguration fieldConfiguration = new ElementConfiguration(); fieldConfiguration.ElementType = ElementType.Field; regionConfiguration2.Elements.Add(fieldConfiguration); regionConfiguration1.Elements.Add(regionConfiguration2); typeConfiguration.Elements.Add(regionConfiguration1); codeConfiguration.Elements.Add(typeConfiguration); CodeArranger arranger = new CodeArranger(codeConfiguration); ReadOnlyCollection <ICodeElement> arrangedElements = arranger.Arrange(elements.AsReadOnly()); Assert.AreEqual(1, arrangedElements.Count, "Unexpected number of arranged elements."); TypeElement arrangedType = arrangedElements[0] as TypeElement; Assert.IsNotNull(arrangedType, "Expected a type element after arranging."); Assert.AreEqual(1, arrangedType.Children.Count, "Unexpected number of arranged child elements."); RegionElement arrangedRegion1 = arrangedType.Children[0] as RegionElement; Assert.IsNotNull(arrangedRegion1, "Expected a region element after arranging."); Assert.AreEqual(regionConfiguration1.Name, arrangedRegion1.Name); Assert.AreEqual(1, arrangedRegion1.Children.Count, "Unexpected number of arranged child elements."); RegionElement arrangedRegion2 = arrangedRegion1.Children[0] as RegionElement; Assert.IsNotNull(arrangedRegion2, "Expected a region element after arranging."); Assert.AreEqual(regionConfiguration2.Name, arrangedRegion2.Name); Assert.AreEqual(1, arrangedRegion2.Children.Count, "Unexpected number of arranged child elements."); FieldElement arrangedFieldElement = arrangedRegion2.Children[0] as FieldElement; Assert.IsNotNull(arrangedFieldElement, "Expected a field element after arranging."); }
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); } }