Ejemplo n.º 1
0
        public void Should_be_able_to_construct_a_test_class()
        {
            const string testProject       = "TestSample.DefaultSettings";
            const string featureFile       = "BrowserRequiredTest.feature";
            var          testProjectFolder = Path.Combine(AssemblyDirectory, @"..\..\..\", testProject);

            var configurationHolder = new SpecFlowConfigurationHolder(AppConfig);
            var projectSettings     = new ProjectSettings
            {
                AssemblyName            = testProject,
                DefaultNamespace        = testProject,
                ProjectName             = testProject,
                ProjectFolder           = testProjectFolder,
                ConfigurationHolder     = configurationHolder,
                ProjectPlatformSettings = new ProjectPlatformSettings()
            };
            var specflowProject = new SpecFlowProject {
                ProjectSettings = projectSettings
            };
            var featurefileInput = specflowProject.GetOrCreateFeatureFile(featureFile);

            var container = GeneratorContainerBuilder.CreateContainer(configurationHolder, projectSettings);
            var generator = container.Resolve <ITestGenerator>();

            var testFile        = generator.GenerateTestFile(featurefileInput, new GenerationSettings());
            var testFileContent = testFile.GeneratedTestCode;

            Console.WriteLine(testFileContent);
            Assert.That(testFile.Success);
        }
Ejemplo n.º 2
0
        public void Should_FeatureGeneratorRegistry_be_registered_as_IFeatureGeneratorRegistry_by_default()
        {
            var testContainer = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder(), new ProjectSettings());

            var registry = testContainer.Resolve <IFeatureGeneratorRegistry>();

            registry.Should().BeOfType <FeatureGeneratorRegistry>();
        }
        public void Should_register_generator_with_custom_settings_when_configured()
        {
            var container = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder(ConfigSource.AppConfig, @"
                <specFlow>
                  <generator allowDebugGeneratedFiles=""true"" /><!-- default is false -->
                </specFlow>"), new ProjectSettings());

            container.Resolve <SpecFlowConfiguration>().AllowDebugGeneratedFiles.Should().Be(true);
        }
        public void Should_register_generator_with_custom_settings_when_configured()
        {
            var container = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder(@"
                <specFlow>
                  <generator allowDebugGeneratedFiles=""true"" /><!-- default is false -->
                </specFlow>"));

            container.Resolve <GeneratorConfiguration>().AllowDebugGeneratedFiles.ShouldBeTrue();
        }
Ejemplo n.º 5
0
        private static IFeatureGenerator CreateFeatureGenerator()
        {
            var container = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder(), new ProjectSettings());

            container.RegisterInstanceAs(CreateTestGeneratorProvider());

            var generator = container.Resolve <UnitTestFeatureGeneratorProvider>().CreateGenerator(ParserHelper.CreateAnyDocument());

            return(generator);
        }
Ejemplo n.º 6
0
        public IFeatureGenerator CreateFeatureGenerator(bool parallelCode, string[] ignoreParallelTags)
        {
            var container             = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder(ConfigSource.Default, null), new ProjectSettings(), Enumerable.Empty <string>());
            var specFlowConfiguration = container.Resolve <SpecFlowConfiguration>();

            specFlowConfiguration.MarkFeaturesParallelizable      = parallelCode;
            specFlowConfiguration.SkipParallelizableMarkerForTags = ignoreParallelTags ??
                                                                    Enumerable.Empty <string>().ToArray();
            container.RegisterInstanceAs(CreateTestGeneratorProvider());

            var generator = container.Resolve <UnitTestFeatureGeneratorProvider>().CreateGenerator(ParserHelper.CreateAnyDocument());

            return(generator);
        }
        public IObjectContainer BuildGeneratorContainer(
            SpecFlowConfigurationHolder specFlowConfigurationHolder,
            ProjectSettings projectSettings,
            IReadOnlyCollection <GeneratorPluginInfo> generatorPluginInfos,
            IObjectContainer rootObjectContainer)
        {
            var objectContainer = _generatorContainerBuilder.CreateContainer(specFlowConfigurationHolder, projectSettings, generatorPluginInfos, rootObjectContainer);

            objectContainer.RegisterTypeAs <ProjectCodeBehindGenerator, IProjectCodeBehindGenerator>();
            objectContainer.RegisterTypeAs <AnalyticsEventProvider, IAnalyticsEventProvider>();

            if (_generateFeatureFileCodeBehindTaskConfiguration.OverrideFeatureFileCodeBehindGenerator is null)
            {
                objectContainer.RegisterTypeAs <FeatureFileCodeBehindGenerator, IFeatureFileCodeBehindGenerator>();
            }
            else
            {
                objectContainer.RegisterInstanceAs(_generateFeatureFileCodeBehindTaskConfiguration.OverrideFeatureFileCodeBehindGenerator);
            }

            return(objectContainer);
        }
Ejemplo n.º 8
0
 private IObjectContainer CreateDefaultContainer(SpecFlowConfigurationHolder configurationHolder)
 {
     return(GeneratorContainerBuilder.CreateContainer(configurationHolder, new ProjectSettings(), Enumerable.Empty <string>()));
 }
Ejemplo n.º 9
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;
            }
        }
Ejemplo n.º 10
0
 public IgnoredTestGeneratorTests()
 {
     container = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder(ConfigSource.Default, null), new ProjectSettings(), Enumerable.Empty <string>());
     unitTestGeneratorProviderMock = new Mock <IUnitTestGeneratorProvider>();
     container.RegisterInstanceAs(unitTestGeneratorProviderMock.Object);
 }
Ejemplo n.º 11
0
 public void Setup()
 {
     container = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder(ConfigSource.Default, null), new ProjectSettings());
     unitTestGeneratorProviderMock = new Mock <IUnitTestGeneratorProvider>();
     container.RegisterInstanceAs(unitTestGeneratorProviderMock.Object);
 }
        public void Should_register_generator_configuration_with_default_config()
        {
            var container = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder());

            container.Resolve <GeneratorConfiguration>().ShouldNotBeNull();
        }
        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.");
                }
        }
 public FeatureGeneratorRegistryTests()
 {
     container = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder(ConfigSource.Default, null), new ProjectSettings(), Enumerable.Empty <string>());
 }
        public void Should_create_a_container()
        {
            var container = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder(ConfigSource.Default, null), new ProjectSettings());

            container.Should().NotBeNull();
        }
        public void Should_register_generator_configuration_with_default_config()
        {
            var container = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder(ConfigSource.Default, null), new ProjectSettings());

            container.Resolve <Configuration.SpecFlowConfiguration>().Should().NotBeNull();
        }
Ejemplo n.º 17
0
 public void Setup()
 {
     container = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder(), new ProjectSettings());
 }
 protected virtual void SetupInternal()
 {
     container = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder(), new ProjectSettings());
     unitTestGeneratorProviderMock = new Mock <IUnitTestGeneratorProvider>();
     container.RegisterInstanceAs(unitTestGeneratorProviderMock.Object);
 }
        public void Should_create_a_container()
        {
            var container = GeneratorContainerBuilder.CreateContainer(new SpecFlowConfigurationHolder());

            container.ShouldNotBeNull();
        }