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); } }
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); }
public int GetGeneratorVersion(GetGeneratorVersionParameters opts) { try { var testGeneratorFactory = new TestGeneratorFactory(); Console.WriteLine(testGeneratorFactory.GetGeneratorVersion().ToString()); return(0); } catch (Exception e) { Console.WriteLine(e); return(1); } }
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); } }
public override void Setup() { base.Setup(); factory = new TestGeneratorFactory(); }
public TestGeneratorFactoryTests() { _factory = new TestGeneratorFactory(); }
public TestGeneratorFactoryTests() : base() { factory = new TestGeneratorFactory(); }