-
Notifications
You must be signed in to change notification settings - Fork 750
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: Generator/SpecFlowUnitTestConverter.cs Parser/SpecFlowGenerator.cs Parser/TechTalk.SpecFlow.Parser.csproj Tests/ParserTests/SuccessfulGenerationTest.cs Tests/RuntimeTests/ExecutionTestBase.cs VsIntegration/SpecFlowSingleFileGenerator.cs changelog.txt
- Loading branch information
Showing
44 changed files
with
1,371 additions
and
1,314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using TechTalk.SpecFlow.Generator.Configuration; | ||
|
||
namespace TechTalk.SpecFlow.Generator | ||
{ | ||
public class BatchGenerator | ||
{ | ||
private readonly TextWriter traceWriter; | ||
private readonly bool verboseOutput; | ||
|
||
public BatchGenerator(TextWriter traceWriter, bool verboseOutput) | ||
{ | ||
this.traceWriter = traceWriter; | ||
this.verboseOutput = verboseOutput; | ||
} | ||
|
||
public void ProcessProject(SpecFlowProject specFlowProject, bool forceGenerate) | ||
{ | ||
if (verboseOutput) | ||
traceWriter.WriteLine("Processing project: " + specFlowProject); | ||
|
||
SpecFlowGenerator generator = new SpecFlowGenerator(specFlowProject); | ||
|
||
foreach (var featureFile in specFlowProject.FeatureFiles) | ||
{ | ||
string featureFileFullPath = featureFile.GetFullPath(specFlowProject); | ||
|
||
string codeFileFullPath = featureFileFullPath + ".cs"; | ||
|
||
bool needsProcessing = true; | ||
|
||
if (!forceGenerate && IsUpToDate(generator, featureFileFullPath, codeFileFullPath)) | ||
{ | ||
needsProcessing = false; | ||
} | ||
|
||
if (verboseOutput || needsProcessing) | ||
{ | ||
traceWriter.WriteLine("Processing file: {0}", featureFileFullPath); | ||
if (!needsProcessing) | ||
traceWriter.WriteLine(" up-to-date"); | ||
} | ||
|
||
if (needsProcessing) | ||
{ | ||
GenerateFile(generator, featureFile, codeFileFullPath); | ||
} | ||
} | ||
} | ||
|
||
protected virtual void GenerateFile(SpecFlowGenerator generator, SpecFlowFeatureFile featureFile, string codeFileFullPath) | ||
{ | ||
using (var writer = GetWriter(codeFileFullPath)) | ||
{ | ||
generator.GenerateCSharpTestFile(featureFile, writer); | ||
} | ||
} | ||
|
||
protected virtual StreamWriter GetWriter(string codeFileFullPath) | ||
{ | ||
return new StreamWriter(codeFileFullPath, false, Encoding.UTF8); | ||
} | ||
|
||
private static bool IsUpToDate(SpecFlowGenerator generator, string featureFileFullPath, string codeFileFullPath) | ||
{ | ||
// check existance of the target file | ||
if (!File.Exists(codeFileFullPath)) | ||
return false; | ||
|
||
// check modification time of the target file | ||
try | ||
{ | ||
var featureFileModificationTime = File.GetLastWriteTime(featureFileFullPath); | ||
var codeFileModificationTime = File.GetLastWriteTime(codeFileFullPath); | ||
|
||
if (featureFileModificationTime > codeFileModificationTime) | ||
return false; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine(ex); | ||
return false; | ||
} | ||
|
||
// check tools version | ||
var codeFileVersion = generator.GetGeneratedFileSpecFlowVersion(codeFileFullPath); | ||
if (codeFileVersion == null || codeFileVersion != generator.GetCurrentSpecFlowVersion()) | ||
return false; | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.Build.BuildEngine; | ||
using TechTalk.SpecFlow.Generator.Configuration; | ||
|
||
namespace TechTalk.SpecFlow.Generator.Configuration | ||
{ | ||
public static class MsBuildProjectReader | ||
{ | ||
public static SpecFlowProject LoadSpecFlowProjectFromMsBuild(string projectFile) | ||
{ | ||
projectFile = Path.GetFullPath(projectFile); | ||
|
||
Project project = Engine.GlobalEngine.GetLoadedProject(projectFile); | ||
if (project == null) | ||
{ | ||
project = new Project(); | ||
project.Load(projectFile, ProjectLoadSettings.IgnoreMissingImports); | ||
} | ||
|
||
string projectFolder = Path.GetDirectoryName(projectFile); | ||
|
||
SpecFlowProject specFlowProject = new SpecFlowProject(); | ||
specFlowProject.ProjectFolder = projectFolder; | ||
specFlowProject.ProjectName = Path.GetFileNameWithoutExtension(projectFile); | ||
specFlowProject.AssemblyName = project.GetEvaluatedProperty("AssemblyName"); | ||
specFlowProject.DefaultNamespace = project.GetEvaluatedProperty("RootNamespace"); | ||
|
||
var items = project.GetEvaluatedItemsByName("None").Cast<BuildItem>() | ||
.Concat(project.GetEvaluatedItemsByName("Content").Cast<BuildItem>()); | ||
foreach (BuildItem item in items) | ||
{ | ||
var extension = Path.GetExtension(item.FinalItemSpec); | ||
if (extension.Equals(".feature", StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
var featureFile = new SpecFlowFeatureFile(item.FinalItemSpec); | ||
var ns = item.GetEvaluatedMetadata("CustomToolNamespace"); | ||
if (!String.IsNullOrEmpty(ns)) | ||
featureFile.CustomNamespace = ns; | ||
specFlowProject.FeatureFiles.Add(featureFile); | ||
} | ||
|
||
if (Path.GetFileName(item.FinalItemSpec).Equals("app.config", StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
GeneratorConfigurationReader.UpdateConfigFromFile(specFlowProject.GeneratorConfiguration, Path.Combine(projectFolder, item.FinalItemSpec)); | ||
} | ||
} | ||
return specFlowProject; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("TechTalk.SpecFlow.Generator")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("TechTalk.SpecFlow.Generator")] | ||
[assembly: AssemblyCopyright("Copyright © 2009")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("743e1609-8937-4775-9896-6e8757c6d98d")] |
Oops, something went wrong.