public void Produces_VBasic_Class_File_Skeleton() { var expected = new StringBuilder(); expected.Append( @"Imports TechTalk.SpecFlow <Binding> _ Public Class StepsForTest <Given(""I have a new step"")> _ Public Sub GivenIHaveANewStep() ScenarioContext.Current.Pending() End Sub <TechTalk.SpecFlow.When(""I do not find a step binding"")> _ Public Sub WhenIDoNotFindAStepBinding() ScenarioContext.Current.Pending() End Sub <TechTalk.SpecFlow.Then(""I get a suggestion"")> _ Public Sub ThenIGetASuggestion() ScenarioContext.Current.Pending() End Sub End Class "); string expectedString = expected.ToString(); var stepScope = new StepScopeNew("TestFeature", "TestScenario", null); var steps = new List<StepInstance> { new StepInstance(BindingType.Given, StepDefinitionKeyword.Given, "Given", "I have a new step", stepScope), new StepInstance(BindingType.When, StepDefinitionKeyword.When, "When", "I do not find a step binding", stepScope), new StepInstance(BindingType.Then, StepDefinitionKeyword.Then, "Then", "I get a suggestion", stepScope) }; var skelInfo = new StepDefSkeletonInfo("StepsForTest", "namespace"); string output = skeletonProviderVB.GetFileSkeleton(steps, skelInfo); Assert.AreEqual(expectedString, output); }
public void Produces_CSharp_Class_File_Skeleton() { var expected = new StringBuilder(); expected.Append( @"using System; using System.Collections.Generic; using System.Linq; using System.Text; using TechTalk.SpecFlow; namespace SpecFlow.Testing { [Binding] public class StepsForTest { #region Given [Given(@""I have a new step"")] public void GivenIHaveANewStep() { ScenarioContext.Current.Pending(); } #endregion #region Then [Then(@""I get a suggestion"")] public void ThenIGetASuggestion() { ScenarioContext.Current.Pending(); } #endregion } } "); string expectedString = expected.ToString(); var stepScope = new StepScopeNew("TestFeature", "TestScenario", null); var steps = new List<StepInstance> { new StepInstance(BindingType.Given, StepDefinitionKeyword.Given, "Given", "I have a new step", stepScope), new StepInstance(BindingType.Then, StepDefinitionKeyword.Then, "Then", "I get a suggestion", stepScope), }; var skelInfo = new StepDefSkeletonInfo("StepsForTest", "SpecFlow.Testing"); string output = skeletonProviderCS.GetFileSkeleton(steps, skelInfo); Assert.AreEqual(expectedString, output); }
/// <summary> /// Creates a new file containing the missing steps and adds them to the visual studio /// solution. Then displays a message conveying whether it succeeded. /// </summary> private void WriteStepsToFile(IStepDefinitionSkeletonProvider skeletonProvider, List<StepInstance> missingSteps) { //Store info on file StepDefSkeletonInfo info = new StepDefSkeletonInfo(_suggestedStepDefName, _defaultNamespace); //Generate the skeleton for the new file string skeleton = skeletonProvider.GetFileSkeleton(missingSteps, info); string file; try { //Try to write the skeleton to a file file = _handler.WriteToFile(skeleton, false, _suggestedStepDefName, _featurePath); } catch (FileHandlerException fileHandlerException) { //If the file already existed, ask to overwrite var overwrite = MessageBox.Show(fileHandlerException.Message, MessageBoxHeader, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); //If they have selected to overwrite then add again, this time allowing overwrites if (overwrite == DialogResult.Yes) file = _handler.WriteToFile(skeleton, true, _suggestedStepDefName, _featurePath); else throw new FileGeneratorException("Cancelled creating step definition file."); } //Add the file generated to the visual studio solution if (!_handler.AddToSolution(_sln, _featurePath, file)) MessageBox.Show( "A step defintion file has been created but it could not be added to an existing visual studio project", MessageBoxHeader, MessageBoxButtons.OK, MessageBoxIcon.Warning); else MessageBox.Show("Success! A step definition file has been generated", MessageBoxHeader); }