Skip to content

Commit

Permalink
move missing SpecFlow error message to IdeSingleFileGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
david1995 committed Apr 25, 2019
1 parent 48b142b commit fb49856
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 12 additions & 0 deletions IdeIntegration/Generator/IdeSingleFileGenerator.cs
Expand Up @@ -40,6 +40,18 @@ public IdeSingleFileGenerator(ProjectInfo projectInfo)
outputFilePath = inputFilePath + GenerationTargetLanguage.GetExtension(projectSettings.ProjectPlatformSettings.Language);
}

if (_projectInfo.ReferencedSpecFlowVersion == null)
{
string errorMessage = $@"Could not find a reference to SpecFlow in project '{_projectInfo.ProjectName}'.
Please add the 'TechTalk.SpecFlow' package to the project and use MSBuild generation instead of using SpecFlowSingleFileGenerator.
For more information see https://specflow.org/documentation/Generate-Tests-from-MsBuild/";

var exception = new InvalidOperationException(errorMessage);
string errorText = GenerateError(exception, codeDomHelper);
outputFileContentWriter(outputFilePath, errorText);
return errorText;
}

var generatorVersion = generatorServices.GetGeneratorVersion();

if (generatorVersion.Major != _projectInfo.ReferencedSpecFlowVersion.Major
Expand Down
Expand Up @@ -6,6 +6,7 @@
using EnvDTE;
using TechTalk.SpecFlow.Generator.Interfaces;
using TechTalk.SpecFlow.IdeIntegration.Generator;
using TechTalk.SpecFlow.Utils;
using VSLangProj80;

namespace TechTalk.SpecFlow.VsIntegration.Implementation.SingleFileGenerator
Expand Down Expand Up @@ -40,17 +41,7 @@ protected override bool GenerateInternal(string inputFilePath, string inputFileC
var vsProject = project.Object as VSProject2;
var references = vsProject?.References.Cast<Reference3>() ?? Enumerable.Empty<Reference3>();
var specFlowReference = references.FirstOrDefault(r => r.Name == "TechTalk.SpecFlow");

if (specFlowReference == null)
{
// TODO: dei set generatedContent
string errorMessage = $@"Could not find a reference to SpecFlow in project '{project.Name}'.
Please add the 'TechTalk.SpecFlow' package to the project and use MSBuild generation instead of using SpecFlowSingleFileGenerator.
For more information see https://specflow.org/documentation/Generate-Tests-from-MsBuild/";
throw new InvalidOperationException(errorMessage);
}

var referencedSpecFlowVersion = Version.Parse(specFlowReference.Version);
var referencedSpecFlowVersion = specFlowReference is Reference3 reference ? Version.Parse(reference.Version) : null;
var projectInfo = new ProjectInfo(project.Name, referencedSpecFlowVersion);

var ideSingleFileGenerator = new IdeSingleFileGenerator(projectInfo);
Expand Down

0 comments on commit fb49856

Please sign in to comment.