Example #1
0
        public int GenerateTestFile(GenerateTestFileParameters opts)
        {
            try
            {
                var featureFileInput = DeserializeFeatureFileInput(opts);
                var projectSettings  = DeserializeProjectSettings(opts.ProjectSettingsFile);

                var codeDomHelper = GetCodeDomHelper(projectSettings);


                var testGeneratorFactory = new TestGeneratorFactory();
                var testGenerator        = testGeneratorFactory.CreateGenerator(projectSettings);
                var testGeneratorResult  = testGenerator.GenerateTestFile(featureFileInput, new GenerationSettings());

                string outputFileContent;
                if (testGeneratorResult.Success)
                {
                    outputFileContent = testGeneratorResult.GeneratedTestCode;
                }
                else
                {
                    outputFileContent = GenerateError(testGeneratorResult, codeDomHelper);
                }

                Console.WriteLine(WriteTempFile(opts, outputFileContent));

                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(1);
            }
        }
Example #2
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);
        }
Example #3
0
        protected virtual ITestGenerator CreateGenerator(string projectFolder, string configFilePath, string targetExtension, string projectDefaultNamespace)
        {
            ITestGeneratorFactory testGeneratorFactory = new TestGeneratorFactory();
            var projectSettings = new ProjectSettings(); //TODO: load settings

            projectSettings.ConfigurationHolder = configFilePath == null ? new SpecFlowConfigurationHolder()
                : CreateConfigHolder(configFilePath);
            projectSettings.ProjectFolder = projectFolder;
            projectSettings.ProjectPlatformSettings.Language = targetExtension == ".cs"
                ? GenerationTargetLanguage.CSharp
                : GenerationTargetLanguage.VB;
            projectSettings.DefaultNamespace = projectDefaultNamespace;

            return(testGeneratorFactory.CreateGenerator(projectSettings));
        }
        public string Generate(string projectFolder, string configFilePath, string targetExtension, string featureFilePath, string targetNamespace, string projectDefaultNamespace, bool saveResultToFile)
        {
            ITestGeneratorFactory testGeneratorFactory = new TestGeneratorFactory();
            var projectSettings = new ProjectSettings(); //TODO: load settings

            projectSettings.ConfigurationHolder = configFilePath == null ? new SpecFlowConfigurationHolder()
                : CreateConfigHolder(configFilePath);
            projectSettings.ProjectFolder = projectFolder;
            projectSettings.ProjectPlatformSettings.Language = targetExtension == ".cs"
                ? GenerationTargetLanguage.CSharp
                : GenerationTargetLanguage.VB;
            projectSettings.DefaultNamespace = projectDefaultNamespace;
            var generationSettings = new GenerationSettings
            {
                CheckUpToDate     = false,
                WriteResultToFile = saveResultToFile
            };

            using (var generator = testGeneratorFactory.CreateGenerator(projectSettings))
            {
                var featureFileInput =
                    new FeatureFileInput(FileSystemHelper.GetRelativePath(featureFilePath, projectFolder));
                featureFileInput.CustomNamespace = targetNamespace;
                var result          = generator.GenerateTestFile(featureFileInput, generationSettings);
                var connectorResult = new GenerationResult();
                if (result.Success)
                {
                    connectorResult.FeatureFileCodeBehind = new FeatureFileCodeBehind()
                    {
                        FeatureFilePath = featureFilePath,
                        Content         = result.GeneratedTestCode
                    };
                }
                else
                {
                    connectorResult.ErrorMessage =
                        string.Join(Environment.NewLine, result.Errors.Select(e => e.Message));
                }

                var resultJson = JsonSerialization.SerializeObject(connectorResult);
                return(resultJson);
            }
        }
        public int DetectGeneratedTestVersion(DetectGeneratedTestVersionParameters opts)
        {
            try
            {
                var featureFileInput = JsonConvert.DeserializeObject <FeatureFileInput>(File.ReadAllText(opts.FeatureFile));


                var testGeneratorFactory = new TestGeneratorFactory();
                var testGenerator        = testGeneratorFactory.CreateGenerator(new ProjectSettings());
                var version = testGenerator.DetectGeneratedTestVersion(featureFileInput);
                Console.WriteLine(version);
                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(1);
            }
        }
Example #6
0
 public void Should_be_able_to_create_generator_with_default_config()
 {
     factory.CreateGenerator(net35CSProjectSettings).ShouldNotBeNull();
 }
Example #7
0
 public void Should_be_able_to_create_generator_with_default_config()
 {
     net35CSProjectSettings.ConfigurationHolder = new SpecFlowConfigurationHolder(ConfigSource.Default, null);
     _factory.CreateGenerator(net35CSProjectSettings, Enumerable.Empty <GeneratorPluginInfo>()).Should().NotBeNull();
 }