Пример #1
0
        protected override void DoExecute()
        {
            if (DebugTask)
            {
                System.Diagnostics.Debugger.Launch();
            }

            ITraceListener traceListener = VerboseOutput ? (ITraceListener) new TextWriterTraceListener(GetMessageWriter(MessageImportance.High), "SpecFlow: ") : new NullListener();

            SpecFlowProject specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(ProjectPath);

            BatchGenerator batchGenerator = new MsBuildBatchGenerator(traceListener, new TestGeneratorFactory(), this);

            batchGenerator.OnError +=
                delegate(FeatureFileInput featureFileInput, TestGeneratorResult result)
            {
                foreach (var testGenerationError in result.Errors)
                {
                    RecordError(testGenerationError.Message,
                                featureFileInput.GetFullPath(specFlowProject.ProjectSettings), testGenerationError.Line, testGenerationError.LinePosition);
                }
            };
            batchGenerator.OnSuccess +=
                (featureFileInput, result) => generatedFiles.Add(
                    new TaskItem(featureFileInput.GetGeneratedTestFullPath(specFlowProject.ProjectSettings)));

            batchGenerator.ProcessProject(specFlowProject, ForceGeneration);
        }
Пример #2
0
        private void Should_parse_csproj_file_correctly(string csprojPath, string language, string assemblyName, string rootNamespace, string projectName)
        {
            var directoryName       = Path.GetDirectoryName(GetType().Assembly.Location);
            var projectFilePath     = Path.Combine(directoryName, csprojPath);
            var specflowProjectfile = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(projectFilePath);


            specflowProjectfile.ProjectSettings.AssemblyName.Should().Be(assemblyName);
            specflowProjectfile.ProjectSettings.DefaultNamespace.Should().Be(rootNamespace);
            specflowProjectfile.ProjectSettings.ProjectName.Should().Be(projectName);

            specflowProjectfile.ProjectSettings.ProjectPlatformSettings.Language.Should().Be(language);

            specflowProjectfile.FeatureFiles.Count.Should().Be(4);
            specflowProjectfile.FeatureFiles.Single(x => x.ProjectRelativePath == @"Features\Login\SocialLogins.feature").Should().NotBeNull();
            specflowProjectfile.FeatureFiles.Single(x => x.ProjectRelativePath == @"Features\WorkflowDefinition\CreateWorkflowDefinition.feature").Should().NotBeNull();
            specflowProjectfile.FeatureFiles.Single(x => x.ProjectRelativePath == @"Features\WorkflowDefinition\CreateWorkflowDefinition.feature").CustomNamespace.Should().Be("CustomNameSpace");
            specflowProjectfile.FeatureFiles.Single(x => x.ProjectRelativePath == @"Features\WorkflowInstance\WorkflowInstance.feature").Should().NotBeNull();
            specflowProjectfile.FeatureFiles.Single(x => x.ProjectRelativePath == @"..\..\LinkedFeature.feature").Should().NotBeNull();


            specflowProjectfile.Configuration.GeneratorConfiguration.AllowDebugGeneratedFiles.Should().BeFalse();
            specflowProjectfile.Configuration.GeneratorConfiguration.AllowRowTests.Should().BeTrue();
            specflowProjectfile.Configuration.GeneratorConfiguration.GeneratorUnitTestProvider.Should().Be("MSTest");
            specflowProjectfile.Configuration.GeneratorConfiguration.FeatureLanguage.Name.Should().Be("en-US");
        }
Пример #3
0
        public void Should_parse_csproj_file_correctly()
        {
            var             directoryName       = Path.GetDirectoryName(this.GetType().Assembly.Location);
            string          projectFilePath     = Path.Combine(directoryName, "Data\\sampleCsProjectfile.csproj");
            SpecFlowProject specflowProjectfile = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(projectFilePath);

            specflowProjectfile.FeatureFiles.Count.Should().Be(3);
            specflowProjectfile.FeatureFiles.Single(x => x.ProjectRelativePath == @"Features\Login\SocialLogins.feature").Should().NotBeNull();
            specflowProjectfile.FeatureFiles.Single(x => x.ProjectRelativePath == @"Features\WorkflowDefinition\CreateWorkflowDefinition.feature").Should().NotBeNull();
            specflowProjectfile.FeatureFiles.Single(x => x.ProjectRelativePath == @"Features\WorkflowInstance\WorkflowInstance.feature").Should().NotBeNull();

            specflowProjectfile.ProjectSettings.AssemblyName.Should().Be("Hacapp.Web.Tests.UI");
            specflowProjectfile.ProjectSettings.DefaultNamespace.Should().Be("Hacapp.Web.Tests.UI");
            specflowProjectfile.ProjectSettings.ProjectName.Should().Be("sampleCsProjectfile");

            specflowProjectfile.ProjectSettings.ProjectPlatformSettings.Language.Should().Be("C#");
            specflowProjectfile.ProjectSettings.ProjectPlatformSettings.LanguageVersion.Should().Be(new Version(3, 0));
            specflowProjectfile.ProjectSettings.ProjectPlatformSettings.Platform.Should().Be(".NET");
            specflowProjectfile.ProjectSettings.ProjectPlatformSettings.PlatformVersion.Should().Be(new Version(3, 5));

            specflowProjectfile.Configuration.GeneratorConfiguration.AllowDebugGeneratedFiles.Should().BeFalse();
            specflowProjectfile.Configuration.GeneratorConfiguration.AllowRowTests.Should().BeTrue();
            specflowProjectfile.Configuration.GeneratorConfiguration.GeneratorUnitTestProvider.Should().Be("MSTest");
            specflowProjectfile.Configuration.GeneratorConfiguration.FeatureLanguage.Name.Should().Be("en-US");
        }
Пример #4
0
        public void GenerateAndTransformReport()
        {
            var specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(ReportParameters.ProjectFile);

            var report = GenerateReport(specFlowProject);

            TransformReport(report, specFlowProject);
        }
Пример #5
0
        protected override void DoExecute()
        {
            SpecFlowProject specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(ProjectPath);

            BatchGenerator batchGenerator = new MsBuildBatchGenerator(
                GetMessageWriter(MessageImportance.High), VerboseOutput, this);

            batchGenerator.ProcessProject(specFlowProject, ForceGeneration);
        }
Пример #6
0
        protected override void DoExecute()
        {
            SpecFlowProject specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(ProjectPath);

            ITraceListener traceListener  = VerboseOutput ? (ITraceListener) new TextWriterTraceListener(GetMessageWriter(MessageImportance.High), "SpecFlow: ") : new NullListener();
            BatchGenerator batchGenerator = new MsBuildBatchGenerator(traceListener, new TestGeneratorFactory(), this);

            batchGenerator.ProcessProject(specFlowProject, ForceGeneration);
        }
Пример #7
0
        public void InitializeProject(string projectPath, string rootNamespace, IEnumerable <string> generatorPlugins)
        {
            _specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(Path.GetFullPath(projectPath), rootNamespace);

            var projectSettings = _specFlowProject.ProjectSettings;

            var testGeneratorFactory = new TestGeneratorFactory();

            _testGenerator = testGeneratorFactory.CreateGenerator(projectSettings, generatorPlugins);
        }
Пример #8
0
        public StepDefinitionReportGenerator(StepDefinitionReportParameters reportParameters)
        {
            ReportParameters = reportParameters;

            specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(reportParameters.ProjectFile);
            parsedFeatures = ParserHelper.GetParsedFeatures(specFlowProject);

            var basePath = Path.Combine(specFlowProject.ProjectSettings.ProjectFolder, reportParameters.BinFolder);
            bindings = BindingCollector.CollectBindings(specFlowProject, basePath);
        }
        private void Should_parse_csproj_file_correctly(string csprojPath, string language, string assemblyName, string rootNamespace, string projectName)
        {
            var directoryName       = Path.GetDirectoryName(new Uri(GetType().Assembly.CodeBase).LocalPath);
            var projectFilePath     = Path.Combine(directoryName, csprojPath);
            var specflowProjectfile = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(projectFilePath, rootNamespace);


            specflowProjectfile.ProjectSettings.DefaultNamespace.Should().Be(rootNamespace);
            specflowProjectfile.ProjectSettings.ProjectName.Should().Be(projectName);

            specflowProjectfile.ProjectSettings.ProjectPlatformSettings.Language.Should().Be(language);

            specflowProjectfile.Configuration.SpecFlowConfiguration.AllowDebugGeneratedFiles.Should().BeFalse();
            specflowProjectfile.Configuration.SpecFlowConfiguration.AllowRowTests.Should().BeTrue();
            specflowProjectfile.Configuration.SpecFlowConfiguration.FeatureLanguage.Name.Should().Be("en-US");
        }
Пример #10
0
        public override bool Execute()
        {
            try
            {
                try
                {
                    var currentProcess = Process.GetCurrentProcess();

                    Log.LogWithNameTag(Log.LogMessage, $"process: {currentProcess.ProcessName}, pid: {currentProcess.Id}, CD: {Environment.CurrentDirectory}");

                    foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        Log.LogWithNameTag(Log.LogMessage, "  " + assembly.FullName);
                    }
                }
                catch (Exception e)
                {
                    Log.LogWithNameTag(Log.LogMessage, $"Error when dumping process info: {e}");
                }

                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

                Log.LogWithNameTag(Log.LogMessage, "Starting GenerateFeatureFileCodeBehind");

                var generatorPlugins = GeneratorPlugins?.Select(gp => gp.ItemSpec).ToList() ?? new List <string>();

                var featureFiles = FeatureFiles?.Select(i => i.ItemSpec).ToList() ?? new List <string>();

                var specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(Path.GetFullPath(ProjectPath), RootNamespace);
                using (var container = GeneratorContainerBuilder.CreateContainer(specFlowProject.ProjectSettings.ConfigurationHolder, specFlowProject.ProjectSettings, generatorPlugins))
                {
                    RegisterGenerationAndAnalyticsSpecific(container);

                    GeneratedFiles = GenerateCodeBehindFilesForProject(container, featureFiles);

                    TransmitProjectCompilingEvent(container);
                }

                return(!Log.HasLoggedErrors);
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    if (e.InnerException is FileLoadException fle)
                    {
                        Log?.LogWithNameTag(Log.LogError, $"FileLoadException Filename: {fle.FileName}");
                        Log?.LogWithNameTag(Log.LogError, $"FileLoadException FusionLog: {fle.FusionLog}");
                        Log?.LogWithNameTag(Log.LogError, $"FileLoadException Message: {fle.Message}");
                    }

                    Log?.LogWithNameTag(Log.LogError, e.InnerException.ToString());
                }

                Log?.LogWithNameTag(Log.LogError, e.ToString());
                return(false);
            }
            finally
            {
                AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
            }
        }
        protected override void DoExecute()
        {
            //System.Diagnostics.Debugger.Launch();

            var traceListener = this.VerboseOutput
                                ? (TechTalk.SpecFlow.Tracing.ITraceListener) new TechTalk.SpecFlow.Tracing.TextWriterTraceListener(GetMessageWriter(MessageImportance.High), "SpecFlow: ")
                                : new NullListener();

            var specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(this.ProjectPath);

            specFlowProject.ProjectSettings.ConfigurationHolder = new SpecFlowConfigurationHolder(
                specFlowProject.ProjectSettings.ConfigurationHolder.ConfigSource,
                Environment.ExpandEnvironmentVariables(specFlowProject.ProjectSettings.ConfigurationHolder.Content)
                );

            FixPluginPaths(specFlowProject.Configuration.SpecFlowConfiguration);

            traceListener.WriteToolOutput("Processing project: " + specFlowProject.ProjectSettings.ProjectName);
            var generationSettings = new GenerationSettings
            {
                CheckUpToDate     = false,
                WriteResultToFile = true
            };

            using (var container = GeneratorContainerBuilder.CreateContainer(specFlowProject.ProjectSettings.ConfigurationHolder, specFlowProject.ProjectSettings))
                using (var generator = container.Resolve <ITestGenerator>())
                {
                    traceListener.WriteToolOutput("Using Generator: {0}", generator.GetType().FullName);

                    var featureFiles = this.FeatureFiles
                                       .Select(x => new FeatureFileInput(FileSystemHelper.GetRelativePath(x.ItemSpec, specFlowProject.ProjectSettings.ProjectFolder)))
                                       .ToList();

                    foreach (var featureFile in featureFiles)
                    {
                        var outputFilePath = generator.GetTestFullPath(featureFile);
                        featureFile.GeneratedTestProjectRelativePath = FileSystemHelper.GetRelativePath(outputFilePath, specFlowProject.ProjectSettings.ProjectFolder);

                        var generationResult = generator.GenerateTestFile(featureFile, generationSettings);
                        if (!generationResult.Success)
                        {
                            traceListener.WriteToolOutput("{0} -> test generation failed", featureFile.ProjectRelativePath);

                            foreach (var testGenerationError in generationResult.Errors)
                            {
                                this.RecordError(testGenerationError.Message, featureFile.GetFullPath(specFlowProject.ProjectSettings), testGenerationError.Line, testGenerationError.LinePosition);
                            }
                        }
                        else if (generationResult.IsUpToDate)
                        {
                            traceListener.WriteToolOutput("{0} -> test up-to-date", featureFile.ProjectRelativePath);
                        }
                        else
                        {
                            traceListener.WriteToolOutput("{0} -> test updated", featureFile.ProjectRelativePath);
                        }

                        if (generationResult.Success)
                        {
                            this.generatedFiles.Add(new TaskItem(featureFile.GetGeneratedTestFullPath(specFlowProject.ProjectSettings)));
                        }
                    }

                    this.Log.LogMessage(MessageImportance.High, $"Generated {this.generatedFiles.Count} feature files.");
                }
        }