public void TraceNoMatchingStepDefinition(StepArgs stepArgs, GenerationTargetLanguage targetLanguage, List <BindingMatch> matchesWithoutScopeCheck) { // string stepDescription = stepFormatter.GetStepDescription(stepArgs); // return new BindingException( // string.Format("Multiple step definitions found, but none of them have matching scope for step '{0}': {1}", // stepDescription, // string.Join(", ", matches.Select(m => GetMethodText(m.StepBinding.MethodInfo)).ToArray()))); IStepDefinitionSkeletonProvider stepDefinitionSkeletonProvider = ObjectContainer.StepDefinitionSkeletonProvider(targetLanguage); StringBuilder message = new StringBuilder(); if (matchesWithoutScopeCheck == null || matchesWithoutScopeCheck.Count == 0) { message.AppendLine("No matching step definition found for the step. Use the following code to create one:"); } else { string preMessage = string.Format("No matching step definition found for the step. There are matching step definitions, but none of them have matching scope for this step: {0}.", string.Join(", ", matchesWithoutScopeCheck.Select(m => stepFormatter.GetMatchText(m, null)).ToArray())); traceListener.WriteToolOutput(preMessage); message.AppendLine("Change the scope or use the following code to create a new step definition:"); } message.Append( stepDefinitionSkeletonProvider.GetBindingClassSkeleton( stepDefinitionSkeletonProvider.GetStepDefinitionSkeleton(stepArgs)) .Indent(StepDefinitionSkeletonProviderBase.CODEINDENT)); traceListener.WriteToolOutput(message.ToString()); }
public static IStepDefinitionSkeletonProvider StepDefinitionSkeletonProvider(GenerationTargetLanguage targetLanguage) { switch (targetLanguage) { case GenerationTargetLanguage.VB: return(GetOrCreate(ref _stepDefinitionSkeletonProviderVB, typeof(StepDefinitionSkeletonProviderVB))); default: return(GetOrCreate(ref _stepDefinitionSkeletonProviderCS, typeof(StepDefinitionSkeletonProviderCS))); } }
public string GenerateFile(string inputFilePath, string outputFilePath, Func <GeneratorServices> generatorServicesProvider, Func <string, string> inputFileContentProvider = null, Action <string, string> outputFileContentWriter = null) { outputFileContentWriter = outputFileContentWriter ?? File.WriteAllText; inputFileContentProvider = inputFileContentProvider ?? File.ReadAllText; GeneratorServices generatorServices; ProjectSettings projectSettings; CodeDomHelper codeDomHelper; try { generatorServices = generatorServicesProvider(); projectSettings = generatorServices.GetProjectSettings(); codeDomHelper = GenerationTargetLanguage.CreateCodeDomHelper(projectSettings.ProjectPlatformSettings.Language); } catch (Exception ex) { OnOtherError(ex); return(null); } string inputFileContent; try { inputFileContent = inputFileContentProvider(inputFilePath); } catch (Exception ex) { OnOtherError(ex); return(null); } string outputFileContent = Generate(inputFilePath, inputFileContent, generatorServices, codeDomHelper, projectSettings); try { if (outputFilePath == null) { outputFilePath = inputFilePath + GenerationTargetLanguage.GetExtension(projectSettings.ProjectPlatformSettings.Language); } outputFileContentWriter(outputFilePath, outputFileContent); return(outputFilePath); } catch (Exception ex) { OnOtherError(ex); return(null); } }
public void TraceNoMatchingStepDefinition(StepArgs stepArgs, GenerationTargetLanguage targetLanguage) { IStepDefinitionSkeletonProvider stepDefinitionSkeletonProvider = ObjectContainer.StepDefinitionSkeletonProvider(targetLanguage); StringBuilder message = new StringBuilder(); message.AppendLine("No matching step definition found for the step. Use the following code to create one:"); message.Append( stepDefinitionSkeletonProvider.GetBindingClassSkeleton( stepDefinitionSkeletonProvider.GetStepDefinitionSkeleton(stepArgs)) .Indent(StepDefinitionSkeletonProviderBase.CODEINDENT)); traceListener.WriteToolOutput(message.ToString()); }
public FeatureInfo(CultureInfo language, string title, string description, GenerationTargetLanguage generationTargetLanguage, params string[] tags) { if (language.IsNeutralCulture) { // for backwards compatibility (execution of files that were generated with pre 1.3) language = LanguageHelper.GetSpecificCultureInfo(language); } Language = language; Title = title; Description = description; GenerationTargetLanguage = generationTargetLanguage; Tags = tags; }
public IStepDefinitionSkeletonProvider GetProvider(GenerationTargetLanguage targetLanguage, GherkinDialect gherkinDialect) { switch (targetLanguage) { case GenerationTargetLanguage.CSharp: return(new StepDefinitionSkeletonProviderCS(gherkinDialect)); case GenerationTargetLanguage.VB: return(new StepDefinitionSkeletonProviderVB(gherkinDialect)); default: return(new StepDefinitionSkeletonProviderCS(gherkinDialect)); } }
public CodeDomHelper(CodeDomProvider codeComProvider) { switch (codeComProvider.FileExtension.ToLower(CultureInfo.InvariantCulture)) { case "cs": TargetLanguage = GenerationTargetLanguage.CSharp; break; case "vb": TargetLanguage = GenerationTargetLanguage.VB; break; default: TargetLanguage = GenerationTargetLanguage.Other; break; } }
public string GenerateFile(string inputFilePath, string outputFilePath, Func <GeneratorServices> generatorServicesProvider, Func <string, string> inputFileContentProvider = null, Action <string, string> outputFileContentWriter = null) { outputFileContentWriter = outputFileContentWriter ?? File.WriteAllText; inputFileContentProvider = inputFileContentProvider ?? File.ReadAllText; GeneratorServices generatorServices; ProjectSettings projectSettings; CodeDomHelper codeDomHelper; try { generatorServices = generatorServicesProvider(); projectSettings = generatorServices.GetProjectSettings(); codeDomHelper = GenerationTargetLanguage.CreateCodeDomHelper(projectSettings.ProjectPlatformSettings.Language); if (outputFilePath == null) { outputFilePath = inputFilePath + GenerationTargetLanguage.GetExtension(projectSettings.ProjectPlatformSettings.Language); } if (_projectInfo.ReferencedSpecFlowVersion == null) { return(WriteNoSpecFlowVersionReferencedError(outputFilePath, outputFileContentWriter, codeDomHelper)); } var generatorVersion = generatorServices.GetGeneratorVersion(); if (generatorVersion.Major != _projectInfo.ReferencedSpecFlowVersion.Major || generatorVersion.Minor != _projectInfo.ReferencedSpecFlowVersion.Minor) { return(WriteSpecFlowVersionConflictError(outputFilePath, outputFileContentWriter, generatorVersion, codeDomHelper)); } } catch (Exception ex) { OnOtherError(ex); return(null); } string inputFileContent; try { inputFileContent = inputFileContentProvider(inputFilePath); } catch (Exception ex) { OnOtherError(ex); return(null); } string outputFileContent = Generate(inputFilePath, inputFileContent, generatorServices, codeDomHelper, projectSettings); try { outputFileContentWriter(outputFilePath, outputFileContent); return(outputFilePath); } catch (Exception ex) { OnOtherError(ex); return(null); } }
//obsolete attribute removed to avoid warnings in the generated code (Issue 58) //[Obsolete("Use ctor with ProgrammingLanguage")] public FeatureInfo(CultureInfo language, string title, string description, GenerationTargetLanguage generationTargetLanguage, params string[] tags) : this(language, title, description, (ProgrammingLanguage)generationTargetLanguage, tags) { }
public CodeDomHelper(GenerationTargetLanguage targetLanguage) { TargetLanguage = targetLanguage; }
private CodeDomHelper GetCodeDomHelper(ProjectSettings projectSettings) { return(GenerationTargetLanguage.CreateCodeDomHelper(projectSettings.ProjectPlatformSettings.Language)); }
public void TraceNoMatchingStepDefinition(StepArgs stepArgs, GenerationTargetLanguage targetLanguage, List <BindingMatch> matchesWithoutScopeCheck) { Console.WriteLine("TraceNoMatchingStepDefinition"); }