#18696: Adding module unit tests code generation command

Work Item: 18696
This commit is contained in:
Lombiq
2013-12-23 21:03:29 +01:00
committed by Zoltán Lehóczky
parent 43ad02b0f1
commit 4ce3ee3226
3 changed files with 136 additions and 7 deletions

View File

@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{$$TestsProjectGuid$$}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>$$ProjectName$$</RootNamespace>
<AssemblyName>$$ProjectName$$</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<OldToolsVersion>4.0</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac">
<HintPath>..\..\..\..\..\lib\autofac\Autofac.dll</HintPath>
</Reference>
<Reference Include="Moq">
<HintPath>..\..\..\..\..\lib\moq\Moq.dll</HintPath>
</Reference>
<Reference Include="NHibernate">
<HintPath>..\..\..\..\..\lib\nhibernate\NHibernate.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\..\..\..\..\lib\nunit\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\sqlce\System.Data.SqlServerCe.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
$$FileIncludes$$<ItemGroup>
<ProjectReference Include="..\..\..\..\Orchard.Tests.Modules\Orchard.Tests.Modules.csproj">
<Project>{6CB3EB30-F725-45C0-9742-42599BA8E8D2}</Project>
<Name>Orchard.Tests.Modules</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Orchard.Tests\Orchard.Framework.Tests.csproj">
<Project>{abc826d4-2fa1-4f2f-87de-e6095f653810}</Project>
<Name>Orchard.Framework.Tests</Name>
</ProjectReference>
$$OrchardReferences$$
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -17,6 +17,7 @@ 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[] {
@@ -25,6 +26,9 @@ namespace Orchard.CodeGeneration.Commands {
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/");
@@ -124,6 +128,59 @@ namespace Orchard.CodeGeneration.Commands {
Context.Output.WriteLine(T("Module {0} created successfully", moduleName));
}
[CommandHelp("codegen moduletests <module-name> [/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<string>();
var folders = new HashSet<string>();
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 <theme-name> [/CreateProject:true|false][/IncludeInSolution:true|false][/BasedOn:<theme-name>]\r\n\tCreate a new Orchard theme")]
[OrchardSwitches("IncludeInSolution,BasedOn,CreateProject")]

View File

@@ -69,6 +69,7 @@
<Compile Include="Services\CodeGenerationCommandInterpreter.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="CodeGenerationTemplates\ModuleTestsCsProj.txt" />
<Content Include="CodeGenerationTemplates\StaticFilesWebConfig.txt" />
<Content Include="CodeGenerationTemplates\Theme.png" />
<Content Include="CodeGenerationTemplates\ThemeManifest.txt" />