Example #1
0
        public void CreateWithAssemblyTest()
        {
#warning Failed because the assembly name was wrong.

            string assemblyName = Assembly.GetExecutingAssembly().FullName;

            //was hardcoded: "NArrange.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
            ProjectHandlerConfiguration configuration = new ProjectHandlerConfiguration();
            configuration.AssemblyName = assemblyName;
            configuration.ParserType   = "NArrange.Core.MSBuildProjectParser";

            ProjectHandler handler = new ProjectHandler(configuration);

            Assert.IsNotNull(handler.ProjectParser, "Project parser was not created.");
            Assert.That(handler.ProjectParser, Is.InstanceOf(typeof(MSBuildProjectParser)));
        }
Example #2
0
        /// <summary>
        /// Initializes the manager from the configuration supplied
        /// during constuction.
        /// </summary>
        private void Initialize()
        {
            //
            // Load extension handlers
            //
            _projectExtensionHandlers = new Dictionary <string, ProjectHandler>(
                StringComparer.OrdinalIgnoreCase);
            _sourceExtensionHandlers = new Dictionary <string, SourceHandler>(
                StringComparer.OrdinalIgnoreCase);
            foreach (HandlerConfiguration handlerConfiguration in _configuration.Handlers)
            {
                switch (handlerConfiguration.HandlerType)
                {
                case HandlerType.Source:
                    SourceHandlerConfiguration sourceConfiguration = handlerConfiguration as SourceHandlerConfiguration;
                    SourceHandler sourceHandler = new SourceHandler(sourceConfiguration);
                    foreach (ExtensionConfiguration extension in sourceConfiguration.SourceExtensions)
                    {
                        _sourceExtensionHandlers.Add(extension.Name, sourceHandler);
                    }
                    break;

                case HandlerType.Project:
                    ProjectHandlerConfiguration projectConfiguration = handlerConfiguration as ProjectHandlerConfiguration;
                    ProjectHandler projectHandler = new ProjectHandler(projectConfiguration);
                    foreach (ExtensionConfiguration extension in projectConfiguration.ProjectExtensions)
                    {
                        _projectExtensionHandlers.Add(extension.Name, projectHandler);
                    }
                    break;

                default:
                    throw new InvalidOperationException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  "Unrecognized handler configuration {0}",
                                  handlerConfiguration));
                }
            }
        }
        public void UpgradeProjectExtensionsTest()
        {
            string filename = Path.GetTempFileName();

            try
            {
                CodeConfiguration oldConfiguration = new CodeConfiguration();

                SourceHandlerConfiguration sourceHandler = new SourceHandlerConfiguration();
                ExtensionConfiguration     oldExtension  = new ExtensionConfiguration();
                oldExtension.Name = "csproj";
                sourceHandler.ProjectExtensions.Add(oldExtension);
                oldConfiguration.Handlers.Add(sourceHandler);
                oldConfiguration.Save(filename);

                CodeConfiguration newConfiguration = CodeConfiguration.Load(filename);
                Assert.AreEqual(2, newConfiguration.Handlers.Count, "New handler was not created.");
                ProjectHandlerConfiguration projectHandlerConfiguration =
                    newConfiguration.Handlers[0] as ProjectHandlerConfiguration;
                Assert.IsNotNull(projectHandlerConfiguration, "Expected a project handler config to be created.");
                Assert.IsNull(projectHandlerConfiguration.AssemblyName);
                Assert.AreEqual(typeof(MSBuildProjectParser).FullName, projectHandlerConfiguration.ParserType);
                Assert.AreEqual(1, projectHandlerConfiguration.ProjectExtensions.Count, "Unexpected number of project extensions.");
                Assert.AreEqual(oldExtension.Name, projectHandlerConfiguration.ProjectExtensions[0].Name);
            }
            finally
            {
                try
                {
                    File.Delete(filename);
                }
                catch
                {
                }
            }
        }
        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
        }