protected override bool GenerateInternal(string inputFilePath, string inputFileContent, Project project, string defaultNamespace, Action <SingleFileGeneratorError> onError, out string generatedContent)
        {
            if (IsSharePointFeature(inputFileContent))
            {
                var sharePointFeatureComment = new StringBuilder();
                sharePointFeatureComment.AppendFormat("/*SpecFlow tried to generate a test class file, but {0} appears to be a SharePoint feature.", Path.GetFileName(inputFilePath));
                sharePointFeatureComment.AppendLine("  The SpecFlow test class was not be generated in order to avoid errors in the SharePoint proejct*/");
                generatedContent = sharePointFeatureComment.ToString();
                return(true);
            }

            var projectInfo = GetProjectInfoForProject(project);

            var ideSingleFileGenerator = new IdeSingleFileGenerator(projectInfo);

            ideSingleFileGenerator.GenerationError +=
                delegate(TestGenerationError error)
            {
                onError(new SingleFileGeneratorError(error.Line, error.LinePosition, error.Message));
            };
            ideSingleFileGenerator.OtherError +=
                delegate(Exception exception)
            {
                onError(new SingleFileGeneratorError(GetMessage(exception)));
            };

            string outputContent  = null;
            string outputFilePath = ideSingleFileGenerator.GenerateFile(inputFilePath, null, GeneratorServicesProvider(project), _ => inputFileContent, (_, oc) => { outputContent = oc; });

            generatedContent = outputContent;

            return(outputFilePath != null);
        }
コード例 #2
0
        public void GenerateCode(FileProjectItem item, CustomToolContext context)
        {
            context.RunAsync(() =>
            {
                var ideSingleFileGenerator = new IdeSingleFileGenerator();

                string outputFilePath = context.GetOutputFileName(item, ".feature");
                ideSingleFileGenerator.GenerateFile(item.FileName, outputFilePath, () => new SharpDevelop4GeneratorServices(item.Project));

                WorkbenchSingleton.SafeThreadCall(
                    () => context.EnsureOutputFileIsInProject(item, outputFilePath));
            });
        }
コード例 #3
0
        public async Task Generate(ProgressMonitor monitor, ProjectFile featureFile, SingleFileCustomToolResult result)
        {
            await Task.Run(() => {
                var ideSingleFileGenerator = new IdeSingleFileGenerator();

                ideSingleFileGenerator.GenerationError +=
                    delegate(TestGenerationError error)
                {
                    result.Errors.Add(new CompilerError(featureFile.Name, error.Line + 1, error.LinePosition + 1, "0", error.Message));
                };
                ideSingleFileGenerator.OtherError +=
                    delegate(Exception exception)
                {
                    result.UnhandledException = exception;
                };

                string outputFilePath    = ideSingleFileGenerator.GenerateFile(featureFile.FilePath, null, () => new MonoDevelopGeneratorServices(featureFile.Project));
                result.GeneratedFilePath = outputFilePath;
            });
        }