diff --git a/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleTestsCsProj.txt b/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleTestsCsProj.txt
new file mode 100644
index 000000000..ec3713d6f
--- /dev/null
+++ b/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleTestsCsProj.txt
@@ -0,0 +1,71 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {$$TestsProjectGuid$$}
+ Library
+ Properties
+ $$ProjectName$$
+ $$ProjectName$$
+ v4.5
+ 4.0
+
+
+ true
+ full
+ false
+ bin\
+ DEBUG;TRACE
+ prompt
+ 4
+ AllRules.ruleset
+ false
+
+
+ pdbonly
+ true
+ bin\
+ TRACE
+ prompt
+ 4
+ AllRules.ruleset
+ false
+
+
+
+ ..\..\..\..\..\lib\autofac\Autofac.dll
+
+
+ ..\..\..\..\..\lib\moq\Moq.dll
+
+
+ ..\..\..\..\..\lib\nhibernate\NHibernate.dll
+
+
+ ..\..\..\..\..\lib\nunit\nunit.framework.dll
+
+
+
+
+
+
+ False
+ ..\..\..\..\..\lib\sqlce\System.Data.SqlServerCe.dll
+ True
+
+
+ $$FileIncludes$$
+
+ {6CB3EB30-F725-45C0-9742-42599BA8E8D2}
+ Orchard.Tests.Modules
+
+
+ {abc826d4-2fa1-4f2f-87de-e6095f653810}
+ Orchard.Framework.Tests
+
+ $$OrchardReferences$$
+
+
+
\ No newline at end of file
diff --git a/src/Orchard.Web/Modules/Orchard.CodeGeneration/Commands/CodeGenerationCommands.cs b/src/Orchard.Web/Modules/Orchard.CodeGeneration/Commands/CodeGenerationCommands.cs
index 7a860b991..2c9d1e52e 100644
--- a/src/Orchard.Web/Modules/Orchard.CodeGeneration/Commands/CodeGenerationCommands.cs
+++ b/src/Orchard.Web/Modules/Orchard.CodeGeneration/Commands/CodeGenerationCommands.cs
@@ -17,14 +17,18 @@ namespace Orchard.CodeGeneration.Commands {
private readonly IExtensionManager _extensionManager;
private readonly ISchemaCommandGenerator _schemaCommandGenerator;
private const string SolutionDirectoryModules = "E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5";
+ private const string SolutionDirectoryTests = "74E681ED-FECC-4034-B9BD-01B0BB1BDECA";
private const string SolutionDirectoryThemes = "74492CBC-7201-417E-BC29-28B4C25A58B0";
- private static readonly string[] _themeDirectories = new [] {
+ private static readonly string[] _themeDirectories = new[] {
"", "Content", "Styles", "Scripts", "Views", "Zones"
};
- private static readonly string[] _moduleDirectories = new [] {
+ private static readonly string[] _moduleDirectories = new[] {
"", "Properties", "Controllers", "Views", "Models", "Scripts", "Styles"
};
+ private static readonly string[] _moduleTestsDirectories = new[] {
+ "", "Properties"
+ };
private const string ModuleName = "CodeGeneration";
private static readonly string _codeGenTemplatePath = HostingEnvironment.MapPath("~/Modules/Orchard." + ModuleName + "/CodeGenerationTemplates/");
@@ -66,7 +70,7 @@ namespace Orchard.CodeGeneration.Commands {
string dataMigrationFilePath = dataMigrationFolderPath + "Migrations.cs";
string templatesPath = HostingEnvironment.MapPath("~/Modules/Orchard." + ModuleName + "/CodeGenerationTemplates/");
string moduleCsProjPath = HostingEnvironment.MapPath(string.Format("~/Modules/{0}/{0}.csproj", extensionDescriptor.Id));
-
+
if (!Directory.Exists(dataMigrationFolderPath)) {
Directory.CreateDirectory(dataMigrationFolderPath);
}
@@ -95,7 +99,7 @@ namespace Orchard.CodeGeneration.Commands {
string projectFileText = File.ReadAllText(moduleCsProjPath);
// The string searches in solution/project files can be made aware of comment lines.
- if ( projectFileText.Contains("\r\n ", "Migrations.cs");
projectFileText = projectFileText.Insert(projectFileText.LastIndexOf(" String.Equals(moduleName, extension.Name, StringComparison.OrdinalIgnoreCase)) ) {
+ if (_extensionManager.AvailableExtensions().Any(extension => String.Equals(moduleName, extension.Name, StringComparison.OrdinalIgnoreCase))) {
Context.Output.WriteLine(T("Creating Module {0} failed: a module of the same name already exists", moduleName));
return;
}
@@ -124,6 +128,59 @@ namespace Orchard.CodeGeneration.Commands {
Context.Output.WriteLine(T("Module {0} created successfully", moduleName));
}
+ [CommandHelp("codegen moduletests [/IncludeInSolution:true|false]\r\n\t" + "Creates a new test project for a module")]
+ [CommandName("codegen moduletests")]
+ [OrchardSwitches("IncludeInSolution")]
+ public void CreateModuleTests(string moduleName) {
+ var projectName = moduleName + ".Tests";
+
+ Context.Output.WriteLine(T("Creating module tests project {0}", projectName));
+
+ var testsPath = HostingEnvironment.MapPath("~/Modules/" + moduleName + "/" + projectName + "/");
+
+ if (Directory.Exists(testsPath)) {
+ Context.Output.WriteLine(T("Creating module tests project {0} failed: a project of the same name already exists", projectName));
+ return;
+ }
+
+ var propertiesPath = testsPath + "Properties";
+ var content = new HashSet();
+ var folders = new HashSet();
+
+ foreach (var folder in _moduleTestsDirectories) {
+ Directory.CreateDirectory(testsPath + folder);
+ if (!String.IsNullOrEmpty(folder)) {
+ folders.Add(testsPath + folder);
+ }
+ }
+
+ var projectGuid = Guid.NewGuid().ToString().ToUpper();
+
+ var templateText = File.ReadAllText(_codeGenTemplatePath + "ModuleAssemblyInfo.txt");
+ templateText = templateText.Replace("$$ModuleName$$", projectName);
+ templateText = templateText.Replace("$$ModuleTypeLibGuid$$", Guid.NewGuid().ToString());
+ File.WriteAllText(propertiesPath + "\\AssemblyInfo.cs", templateText);
+ content.Add(propertiesPath + "\\AssemblyInfo.cs");
+
+ var itemGroup = CreateProjectItemGroup(testsPath, content, folders);
+
+ var csprojText = File.ReadAllText(_codeGenTemplatePath + "\\ModuleTestsCsProj.txt");
+ csprojText = csprojText.Replace("$$ProjectName$$", projectName);
+ csprojText = csprojText.Replace("$$TestsProjectGuid$$", projectGuid);
+ csprojText = csprojText.Replace("$$FileIncludes$$", itemGroup ?? "");
+ csprojText = csprojText.Replace("$$OrchardReferences$$", GetOrchardReferences());
+
+ File.WriteAllText(testsPath + projectName + ".csproj", csprojText);
+
+
+ // The string searches in solution/project files can be made aware of comment lines.
+ if (IncludeInSolution) {
+ AddToSolution(Context.Output, projectName, projectGuid, "Modules\\" + moduleName, SolutionDirectoryTests);
+ }
+
+ Context.Output.WriteLine(T("Module tests project {0} created successfully", projectName));
+ }
+
[CommandName("codegen theme")]
[CommandHelp("codegen theme [/CreateProject:true|false][/IncludeInSolution:true|false][/BasedOn:]\r\n\tCreate a new Orchard theme")]
[OrchardSwitches("IncludeInSolution,BasedOn,CreateProject")]
@@ -217,7 +274,7 @@ namespace Orchard.CodeGeneration.Commands {
var content = new HashSet();
var folders = new HashSet();
- foreach(var folder in _moduleDirectories) {
+ foreach (var folder in _moduleDirectories) {
Directory.CreateDirectory(modulePath + folder);
if (!String.IsNullOrEmpty(folder)) {
folders.Add(modulePath + folder);
@@ -257,7 +314,7 @@ namespace Orchard.CodeGeneration.Commands {
}
private static string GetOrchardReferences() {
- return IsSourceEnlistment() ?
+ return IsSourceEnlistment() ?
@"
{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}
Orchard.Framework
diff --git a/src/Orchard.Web/Modules/Orchard.CodeGeneration/Orchard.CodeGeneration.csproj b/src/Orchard.Web/Modules/Orchard.CodeGeneration/Orchard.CodeGeneration.csproj
index 264e5f358..9e32becae 100644
--- a/src/Orchard.Web/Modules/Orchard.CodeGeneration/Orchard.CodeGeneration.csproj
+++ b/src/Orchard.Web/Modules/Orchard.CodeGeneration/Orchard.CodeGeneration.csproj
@@ -69,6 +69,7 @@
+