private void SaveAsStepDefinitionClass(IProjectScope projectScope, string combinedSnippet, string className, string indent, string newLine) { string targetFolder = projectScope.ProjectFolder; var projectSettings = projectScope.GetProjectSettings(); var defaultNamespace = projectSettings.DefaultNamespace ?? projectScope.ProjectName; var fileNamespace = defaultNamespace; var stepDefinitionsFolder = Path.Combine(targetFolder, "StepDefinitions"); if (projectScope.IdeScope.FileSystem.Directory.Exists(stepDefinitionsFolder)) { targetFolder = stepDefinitionsFolder; fileNamespace = fileNamespace + ".StepDefinitions"; } var targetFilePath = Path.Combine(targetFolder, className + ".cs"); var template = $"using System;" + newLine + $"using TechTalk.SpecFlow;" + newLine + newLine + $"namespace {fileNamespace}" + newLine + $"{{" + newLine + $"{indent}[Binding]" + newLine + $"{indent}public class {className}" + newLine + $"{indent}{{" + newLine + combinedSnippet + $"{indent}}}" + newLine + $"}}" + newLine; projectScope.AddFile(targetFilePath, template); projectScope.IdeScope.Actions.NavigateTo(new SourceLocation(targetFilePath, 9, 1)); }
private void SaveAsStepDefinitionClass(IProjectScope projectScope, string combinedSnippet, string className, string indent, string newLine) { string targetFolder = projectScope.ProjectFolder; var projectSettings = projectScope.GetProjectSettings(); var defaultNamespace = projectSettings.DefaultNamespace ?? projectScope.ProjectName; var fileNamespace = defaultNamespace; var stepDefinitionsFolder = Path.Combine(targetFolder, "StepDefinitions"); if (IdeScope.FileSystem.Directory.Exists(stepDefinitionsFolder)) { targetFolder = stepDefinitionsFolder; fileNamespace = fileNamespace + ".StepDefinitions"; } var targetFilePath = Path.Combine(targetFolder, className + ".cs"); if (IdeScope.FileSystem.File.Exists(targetFilePath)) { if (IdeScope.Actions.ShowSyncQuestion("Overwrite file?", $"The selected step definition file '{targetFilePath}' already exists. By overwriting the existing file you might loose work. {Environment.NewLine}Do you want to overwrite the file?", defaultButton: MessageBoxResult.No) != MessageBoxResult.Yes) { return; } } var template = $"using System;" + newLine + $"using TechTalk.SpecFlow;" + newLine + newLine + $"namespace {fileNamespace}" + newLine + $"{{" + newLine + $"{indent}[Binding]" + newLine + $"{indent}public class {className}" + newLine + $"{indent}{{" + newLine + combinedSnippet + $"{indent}}}" + newLine + $"}}" + newLine; projectScope.AddFile(targetFilePath, template); projectScope.IdeScope.Actions.NavigateTo(new SourceLocation(targetFilePath, 9, 1)); }