public void SpacesTest() { CodeConfiguration configuration = CodeConfiguration.Load(@"TestConfigurations\SpacesConfig.xml"); Assert.IsNotNull(configuration); Assert.AreEqual(TabStyle.Spaces, configuration.Formatting.Tabs.TabStyle, "Unexpected tab style."); }
public void NoEndRegionNamesTest() { CodeConfiguration configuration = CodeConfiguration.Load(@"TestConfigurations\NoEndRegionNames.xml"); Assert.IsNotNull(configuration); Assert.IsFalse(configuration.Formatting.Regions.EndRegionNameEnabled, "Unexpected value for EndRegionNameEnabled."); }
public void SpacesTest() { CodeConfiguration configuration = CodeConfiguration.Load(Path.Combine(TestContext.CurrentContext.WorkDirectory, "TestConfigurations", "SpacesConfig.xml")); Assert.IsNotNull(configuration); Assert.AreEqual(TabStyle.Spaces, configuration.Formatting.Tabs.TabStyle, "Unexpected tab style."); }
public void NoEndRegionNamesTest() { CodeConfiguration configuration = CodeConfiguration.Load(Path.Combine(TestContext.CurrentContext.WorkDirectory, "TestConfigurations", "NoEndRegionNames.xml")); Assert.IsNotNull(configuration); Assert.IsFalse(configuration.Formatting.Regions.EndRegionNameEnabled, "Unexpected value for EndRegionNameEnabled."); }
public void SpacesTest() { string testPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", string.Empty); CodeConfiguration configuration = CodeConfiguration.Load(Path.Combine(testPath, @"TestConfigurations\SpacesConfig.xml")); Assert.IsNotNull(configuration); Assert.AreEqual(TabStyle.Spaces, configuration.Formatting.Tabs.TabStyle, "Unexpected tab style."); }
public void NoEndRegionNamesTest() { string testPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", string.Empty); CodeConfiguration configuration = CodeConfiguration.Load(Path.Combine(testPath, @"TestConfigurations\NoEndRegionNames.xml")); Assert.IsNotNull(configuration); Assert.IsFalse(configuration.Formatting.Regions.EndRegionNameEnabled, "Unexpected value for EndRegionNameEnabled."); }
/// <summary> /// Loads the configuration file that specifies how elements will be arranged. /// </summary> /// <param name="configFile">The config file.</param> private void LoadConfiguration(string configFile) { if (_configuration == null) { if (configFile != null) { _configuration = CodeConfiguration.Load(configFile); } else { _configuration = CodeConfiguration.Default; } _projectManager = new ProjectManager(_configuration); _encoding = _configuration.Encoding.GetEncoding(); } }
/// <summary> /// Loads the configuration file into the editor and updates the UI state. /// </summary> /// <param name="filename">The filename.</param> private void LoadConfiguration(string filename) { if (filename.Length == 0) { MessageBox.Show(this, "Please select a configuration to load.", this.Text); } else { try { CodeConfiguration configuration = CodeConfiguration.Load(filename, false); _configurationEditorControl.Configuration = configuration; this.CanSelectConfig = false; } catch (Exception ex) { StringBuilder messageBuilder = new StringBuilder( string.Format( CultureInfo.CurrentUICulture, "Unable to load configuration file {0}: {1}", filename, ex.Message)); if (ex.InnerException != null) { messageBuilder.AppendFormat(" {0}", ex.InnerException.Message); } MessageBox.Show( this, messageBuilder.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
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 WriteArrangedElementTest() { string outputDirectory = "Arranged"; if (Directory.Exists(outputDirectory)) { try { Directory.Delete(outputDirectory, true); } catch { } } ReadOnlyCollection <ICodeElement> testElements; ISourceCodeTestFile[] testFiles = ValidTestFiles; foreach (ISourceCodeTestFile testFile in testFiles) { using (TextReader reader = testFile.GetReader()) { TCodeParser parser = new TCodeParser(); testElements = parser.Parse(reader); Assert.IsTrue(testElements.Count > 0, "Test file does not contain any elements."); } foreach (FileInfo configFile in TestUtilities.TestConfigurationFiles) { try { CodeConfiguration configuration = CodeConfiguration.Load(configFile.FullName); CodeArranger arranger = new CodeArranger(configuration); ReadOnlyCollection <ICodeElement> arranged = arranger.Arrange(testElements); // // Write the arranged elements // StringWriter writer = new StringWriter(); TCodeWriter codeWriter = new TCodeWriter(); codeWriter.Configuration = configuration; codeWriter.Write(arranged, writer); string text = writer.ToString(); // Write the file to the output directory for further analysis Directory.CreateDirectory(outputDirectory); string configurationDirectory = Path.Combine( outputDirectory, Path.GetFileNameWithoutExtension(configFile.FullName)); Directory.CreateDirectory(configurationDirectory); File.WriteAllText(Path.Combine(configurationDirectory, testFile.Name), text); // // Verify that the arranged file still compiles sucessfully. // CompilerResults results = Compile(text, testFile.Name); CompilerError error = TestUtilities.GetCompilerError(results); if (error != null) { Assert.Fail( "Arranged source code should not produce compiler errors. " + "Error: {0} - {1}, line {2}, column {3} ", error.ErrorText, testFile.Name, error.Line, error.Column); } } catch (Exception ex) { Assert.Fail("Configuration " + configFile + ": " + ex.ToString()); } } } }
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); } }