Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new configuration using the specified filename and updates
        /// the UI.
        /// </summary>
        /// <param name="filename">The filename.</param>
        private void CreateConfiguration(string filename)
        {
            try
            {
                CodeConfiguration configuration = CodeConfiguration.Default.Clone() as CodeConfiguration;
                configuration.Save(filename);

                _configurationEditorControl.Configuration = configuration;
                this.CanSelectConfig = false;
            }
            catch
            {
                string message = string.Format(
                    CultureInfo.CurrentUICulture,
                    "Unable to create configuration file {0}.",
                    filename);

                MessageBox.Show(this, message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        public void ArrangeProjectFilteredTest()
        {
            CodeConfiguration filterProjectConfig = CodeConfiguration.Default.Clone() as CodeConfiguration;

            // Set up the filter
            FilterBy filter = new FilterBy();

            filter.Condition = "!($(File.Path) : '.Filtered.')";
            ((ProjectHandlerConfiguration)filterProjectConfig.Handlers[0]).ProjectExtensions[0].FilterBy = filter;

            string filterProjectConfigFile = Path.Combine(Path.GetTempPath(), "FilterProjectConfig.xml");

            try
            {
                filterProjectConfig.Save(filterProjectConfigFile);

                TestLogger   logger       = new TestLogger();
                FileArranger fileArranger = new FileArranger(filterProjectConfigFile, logger);

                bool success = fileArranger.Arrange(_testFilteredProjectFile, null);

                Assert.IsTrue(success, "Expected file to be arranged succesfully.");
                Assert.IsTrue(
                    logger.HasMessage(LogLevel.Verbose, "0 files written."),
                    "Expected 0 files to be written - " + logger.ToString());
            }
            finally
            {
                try
                {
                    File.Delete(filterProjectConfigFile);
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 3
0
        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
                {
                }
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }