public void ToStringTest() { SourceHandlerConfiguration handlerConfiguration = new SourceHandlerConfiguration(); handlerConfiguration.Language = "TestLanguage"; string str = handlerConfiguration.ToString(); Assert.AreEqual("Source Handler: TestLanguage", str, "Unexpected string representation."); }
/// <summary> /// Moves project extensions to the new format. /// </summary> private void UpgradeProjectExtensions() { // Migrate project handler configurations string parserType = typeof(MSBuildProjectParser).FullName; ProjectHandlerConfiguration projectHandlerConfiguration = null; foreach (HandlerConfiguration handlerConfiguration in Handlers) { if (handlerConfiguration.HandlerType == HandlerType.Project) { ProjectHandlerConfiguration candidateConfiguration = handlerConfiguration as ProjectHandlerConfiguration; if (candidateConfiguration.ParserType != null && candidateConfiguration.ParserType.ToUpperInvariant() == parserType.ToUpperInvariant()) { projectHandlerConfiguration = candidateConfiguration; break; } } } // // Create the new project configuration if necessary // if (projectHandlerConfiguration == null) { projectHandlerConfiguration = new ProjectHandlerConfiguration(); projectHandlerConfiguration.ParserType = parserType; Handlers.Insert(0, projectHandlerConfiguration); } foreach (HandlerConfiguration handlerConfiguration in Handlers) { if (handlerConfiguration.HandlerType == HandlerType.Source) { SourceHandlerConfiguration sourceHandlerConfiguration = handlerConfiguration as SourceHandlerConfiguration; foreach (ExtensionConfiguration projectExtension in sourceHandlerConfiguration.ProjectExtensions) { bool upgraded = false; foreach (ExtensionConfiguration upgradedExtension in projectHandlerConfiguration.ProjectExtensions) { if (string.Compare(upgradedExtension.Name, projectExtension.Name, true) == 0) { upgraded = true; break; } } if (!upgraded) { projectHandlerConfiguration.ProjectExtensions.Add(projectExtension); } } sourceHandlerConfiguration.ProjectExtensions.Clear(); } } }
public void CreateTest() { string assemblyName = "NArrange.CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"; SourceHandlerConfiguration configuration = new SourceHandlerConfiguration(); configuration.AssemblyName = assemblyName; SourceHandler handler = new SourceHandler(configuration); Assert.IsNotNull(handler.CodeParser, "Parser was not created."); Assert.IsNotNull(handler.CodeWriter, "Writer was not created."); }
/// <summary> /// Creates a new SourceHandler. /// </summary> /// <param name="configuration">Source handler configuration.</param> public SourceHandler(SourceHandlerConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException("configuration"); } _configuration = configuration; Initialize(); }
/// <summary> /// Creates a clone of this instance. /// </summary> /// <returns>Clone of the instance.</returns> protected override HandlerConfiguration DoClone() { SourceHandlerConfiguration clone = new SourceHandlerConfiguration(); clone._language = _language; foreach (ExtensionConfiguration extension in SourceExtensions) { ExtensionConfiguration extensionClone = extension.Clone() as ExtensionConfiguration; clone.SourceExtensions.Add(extensionClone); } return(clone); }
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 { } } }
/// <summary> /// Creates a clone of this instance. /// </summary> /// <returns>Clone of the instance.</returns> protected override HandlerConfiguration DoClone() { SourceHandlerConfiguration clone = new SourceHandlerConfiguration(); clone._language = _language; foreach (ExtensionConfiguration extension in SourceExtensions) { ExtensionConfiguration extensionClone = extension.Clone() as ExtensionConfiguration; clone.SourceExtensions.Add(extensionClone); } return clone; }