13 changed files with 186 additions and 22 deletions
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.TextTemplating |
||||
{ |
||||
public class NamespaceHint |
||||
{ |
||||
string hint = String.Empty; |
||||
FileProjectItem templateFile; |
||||
|
||||
public NamespaceHint(FileProjectItem templateFile) |
||||
{ |
||||
this.templateFile = templateFile; |
||||
GetNamespaceHint(); |
||||
} |
||||
|
||||
void GetNamespaceHint() |
||||
{ |
||||
hint = GetCustomToolNamespace(); |
||||
if (String.IsNullOrEmpty(hint)) { |
||||
hint = GetProjectRootNamespace(); |
||||
} |
||||
} |
||||
|
||||
string GetProjectRootNamespace() |
||||
{ |
||||
return templateFile.Project.RootNamespace; |
||||
} |
||||
|
||||
string GetCustomToolNamespace() |
||||
{ |
||||
return templateFile.GetEvaluatedMetadata("CustomToolNamespace"); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return hint; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Internal.Templates; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace TextTemplating.Tests.Helpers |
||||
{ |
||||
public static class ProjectHelper |
||||
{ |
||||
public static IProject CreateProject() |
||||
{ |
||||
var info = new ProjectCreateInformation(); |
||||
info.Solution = new Solution(); |
||||
info.OutputProjectFileName = @"d:\projects\MyProject\MyProject.csproj"; |
||||
info.ProjectName = "MyProject"; |
||||
return new MSBuildBasedProject(info); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Project.RootNamespace returns Project.Name
|
||||
/// </summary>
|
||||
public static void SetProjectRootNamespace(IProject project, string rootNamespace) |
||||
{ |
||||
project.Name = rootNamespace; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,54 @@
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.TextTemplating; |
||||
using NUnit.Framework; |
||||
using TextTemplating.Tests.Helpers; |
||||
|
||||
namespace TextTemplating.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class NamespaceHintTests |
||||
{ |
||||
NamespaceHint namespaceHint; |
||||
IProject project; |
||||
FileProjectItem templateFile; |
||||
|
||||
void CreateProjectTemplateFile() |
||||
{ |
||||
project = ProjectHelper.CreateProject(); |
||||
templateFile = new FileProjectItem(project, ItemType.None, "MyTemplate.tt"); |
||||
} |
||||
|
||||
void CreateNamespaceHint() |
||||
{ |
||||
namespaceHint = new NamespaceHint(templateFile); |
||||
} |
||||
|
||||
[Test] |
||||
public void ToString_TemplateFileHasCustomToolNamespaceSetToTest_ReturnsTest() |
||||
{ |
||||
CreateProjectTemplateFile(); |
||||
templateFile.SetMetadata("CustomToolNamespace", "Test"); |
||||
CreateNamespaceHint(); |
||||
|
||||
string result = namespaceHint.ToString(); |
||||
|
||||
Assert.AreEqual("Test", result); |
||||
} |
||||
|
||||
[Test] |
||||
public void ToString_TemplateFileHasNoCustomToolNamespace_ReturnsProjectRootNamespace() |
||||
{ |
||||
CreateProjectTemplateFile(); |
||||
ProjectHelper.SetProjectRootNamespace(project, "ProjectRootNamespace"); |
||||
CreateNamespaceHint(); |
||||
|
||||
string result = namespaceHint.ToString(); |
||||
|
||||
Assert.AreEqual("ProjectRootNamespace", result); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue