public void GenerateCode(FileProjectItem item, CustomToolContext context) { context.RunAsync( ()=> { string fileName = item.FileName; var projectNode = item.Project; SpecFlowProject specFlowProject = CreateSpecFlowProjectFrom(projectNode); var specFlowGenerator = new SpecFlowGenerator(specFlowProject); string outputFile = context.GetOutputFileName(item, ".feature"); var specFlowFeatureFile = specFlowProject.GetOrCreateFeatureFile(fileName); var fileContents = File.ReadAllText(fileName); string outputFileContents; using(var reader = new StringReader(fileContents)) { using (var writer = new StringWriter(new StringBuilder())) { specFlowGenerator.GenerateTestFile(specFlowFeatureFile, projectNode.LanguageProperties.CodeDomProvider, reader, writer); outputFileContents = writer.ToString(); } } File.WriteAllText(outputFile, outputFileContents); WorkbenchSingleton.SafeThreadCall( () => context.EnsureOutputFileIsInProject(item, outputFile)); }); }
protected virtual void GenerateFile(SpecFlowGenerator generator, SpecFlowFeatureFile featureFile, string codeFileFullPath) { using (var writer = GetWriter(codeFileFullPath)) { generator.GenerateCSharpTestFile(featureFile, writer); } }
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); }
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; }
protected virtual void GenerateFile(SpecFlowGenerator generator, SpecFlowFeatureFile featureFile, string codeFileFullPath) { using (var writer = GetWriter(codeFileFullPath)) { generator.GenerateCSharpTestFile(featureFile, writer); } }
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 override string GenerateCode(string inputFileContent) { CodeDomProvider provider = GetCodeProvider(); SpecFlowProject specFlowProject = DteProjectReader.LoadSpecFlowProjectFromDteProject(CurrentProject); SpecFlowGenerator generator = new SpecFlowGenerator(specFlowProject); using (var writer = new StringWriter(new StringBuilder())) { generator.GenerateTestFile( specFlowProject.GetOrCreateFeatureFile(CodeFilePath), provider, new StringReader(inputFileContent), writer); return writer.ToString(); } }
protected override void GenerateFile(SpecFlowGenerator generator, SpecFlowFeatureFile featureFile, string codeFileFullPath) { try { base.GenerateFile(generator, featureFile, codeFileFullPath); outputFile.Done(task.Errors); } catch(Exception ex) { task.RecordException(ex); } finally { outputFile = null; } }
private FilePath GenerateFeatureCodeFileFor(ProjectFile featureFile) { // TODO: We only support C# for now, later we'll add support to grab the provider based on the project CodeDomProvider codeProvider = new CSharpCodeProvider(); FilePath outputFile = featureFile.FilePath.ChangeExtension(".feature." + codeProvider.FileExtension); SpecFlowProject specFlowProject = MonoDevelopProjectReader.CreateSpecFlowProjectFrom(featureFile.Project); var specFlowGenerator = new SpecFlowGenerator(specFlowProject); using (var writer = new StringWriter(new StringBuilder())) using (var reader = new StringReader(File.ReadAllText(featureFile.FilePath))) { FeatureFileInput specFlowFeatureFile = specFlowProject.GetOrCreateFeatureFile(featureFile.FilePath); specFlowGenerator.GenerateTestFile(specFlowFeatureFile, codeProvider, reader, writer); File.WriteAllText(outputFile, writer.ToString()); } return outputFile; }
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); } } }