public void GetMatches_Should_Be_Able_To_Feed_Into_Multiple_Transforms() { var stepDefinition = new StepDefinition { Regex = new Regex("^((?:[Uu]ser )?\"(?:[^\"]*)\"|the (?:most|least) senior user) is logged in$"), Action = new Action<int>(x => { }) }; var stepDefinitions = new List<StepDefinition> { stepDefinition }; var transformDefinition1 = new TransformDefinition { Regex = new Regex("^(?:[Uu]ser )?\"([^\"]*)\"$"), Action = new Func<string, string>(s => s) }; var transformDefinition2 = new TransformDefinition { Regex = new Regex("^the (most|least) senior user$"), Action = new Func<string, string>(s => s) }; var transformDefinitions = new Dictionary<Type, IList<TransformDefinition>> { { typeof(int), new List<TransformDefinition> { transformDefinition1, transformDefinition2 } } }; var stepSet = new Mock<IStepSet>(); stepSet.Setup(ss => ss.StepDefinitions).Returns(stepDefinitions); stepSet.Setup(ss => ss.TransformDefinitions).Returns(transformDefinitions); stepMother.StepSets = new List<IStepSet> { stepSet.Object }; stepMother.BuildStepCollection(); var step = "the most senior user is logged in"; stepMother.GetMatches(step); }
public void GetMatches_Should_Ignore_NonCapuring_And_Match_Capturing_For_Complex_StepDefinition() { var stepDefinition = new StepDefinition { Regex = new Regex("^I go (on (?:a )?holiday|home)$"), Action = new Action<string>(s => { }) }; var stepSet = new Mock<IStepSet>(); stepSet.Setup(ss => ss.StepDefinitions).Returns(new List<StepDefinition> { stepDefinition }); stepSet.Setup(ss => ss.TransformDefinitions).Returns(new Dictionary<Type, IList<TransformDefinition>>()); stepMother.StepSets = new List<IStepSet> { stepSet.Object }; stepMother.BuildStepCollection(); var step = "I go on a holiday"; var match = stepMother.GetMatches(step).Single(); (match.StepDefinition).Should().Be.EqualTo(stepDefinition); (match.MatchedArguments).Should().Have.SameSequenceAs(new[] { new MatchedArgument { Text = "on a holiday", Value="on a holiday", Position = 5 } }); }
public void GetMatches_Should_Ignore_NonCapuring_And_Match_Capturing_For_Simple_StepDefinition() { var stepDefinition = new StepDefinition { Regex = new Regex("^I (?:am|be) blowing the (soul|shit) out of this horn$"), Action = new Action<string> (s => { }) }; var stepSet = new Mock<IStepSet>(); stepSet.Setup(ss => ss.StepDefinitions).Returns(new List<StepDefinition> { stepDefinition }); stepSet.Setup(ss => ss.TransformDefinitions).Returns(new Dictionary<Type, IList<TransformDefinition>>()); stepMother.StepSets = new List<IStepSet> { stepSet.Object }; stepMother.BuildStepCollection(); var step = "I be blowing the soul out of this horn"; var match = stepMother.GetMatches(step).Single(); (match.StepDefinition).Should().Be.EqualTo(stepDefinition); (match.MatchedArguments).Should().Have.SameSequenceAs(new[] { new MatchedArgument { Text = "soul", Value = "soul", Position = 17 } }); }
public void GetMatches_Should_Return_NoMatch_For_Missing_Transform() { var stepDefinition = new StepDefinition { Regex = new Regex("^I print the integer (\\d*)$"), Action = new Action<int>(Console.WriteLine) }; var stepDefinitions = new List<StepDefinition> { stepDefinition }; var stepSet = new Mock<IStepSet>(); stepSet.Setup(ss => ss.StepDefinitions).Returns(stepDefinitions); stepSet.Setup(ss => ss.TransformDefinitions).Returns(new Dictionary<Type, IList<TransformDefinition>>()); stepMother.StepSets = new List<IStepSet> { stepSet.Object }; stepMother.BuildStepCollection(); var step = "I print the integer 5"; stepMother.GetMatches(step).Should().Be.Empty(); }
public void GetMatches_Should_Return_NoMatch_For_Ambiguous_Transform() { var stepDefinition = new StepDefinition { Regex = new Regex("^I print the integer (\\d*)$"), Action = new Action<int>(Console.WriteLine) }; var stepDefinitions = new List<StepDefinition> { stepDefinition }; var transformDefinition1 = new TransformDefinition { Regex = new Regex("^(\\d)$"), Action = new Func<string, int>(int.Parse) }; var transformDefinition2 = new TransformDefinition { Regex = new Regex("^(\\d+)$"), Action = new Func<string, int>(x => int.Parse(x) + 1) }; var transformDefinitions = new Dictionary<Type, IList<TransformDefinition>> { { typeof(int), new List<TransformDefinition> { transformDefinition1, transformDefinition2 } } }; var stepSet = new Mock<IStepSet>(); stepSet.Setup(ss => ss.StepDefinitions).Returns(stepDefinitions); stepSet.Setup(ss => ss.TransformDefinitions).Returns(transformDefinitions); stepMother.StepSets = new List<IStepSet> { stepSet.Object }; stepMother.BuildStepCollection(); var step = "I print the integer 5"; stepMother.GetMatches(step).Should().Be.Empty(); }
public void GetMatches_Should_Process_Unambiguous_Transform() { var stepDefinition = new StepDefinition { Regex = new Regex("^I print the integer (\\d*)$"), Action = new Action<int>(Console.WriteLine) }; var stepDefinitions = new List<StepDefinition> { stepDefinition }; var transformDefinition = new TransformDefinition { Regex = new Regex("^(\\d*)$"), Action = new Func<string, int>(int.Parse) }; var transformDefinitions = new Dictionary<Type, IList<TransformDefinition>> { { typeof(int), new List<TransformDefinition> { transformDefinition } } }; var stepSet = new Mock<IStepSet>(); stepSet.Setup(ss => ss.StepDefinitions).Returns(stepDefinitions); stepSet.Setup(ss => ss.TransformDefinitions).Returns(transformDefinitions); stepMother.StepSets = new List<IStepSet> { stepSet.Object }; stepMother.BuildStepCollection(); var step = "I print the integer 5"; var match = stepMother.GetMatches(step).Single(); (match.StepDefinition).Should().Be.EqualTo(stepDefinition); (match.MatchedArguments).Should().Have.SameSequenceAs(new[] { new MatchedArgument { Text = "5", Value = 5, Position = 20 } }); }
private Guid GetOrCreateStepId(StepDefinition stepDefinition) { if (StepIds.ContainsKey(stepDefinition)) return StepIds[stepDefinition]; else { var stepId = Guid.NewGuid(); StepIds[stepDefinition] = stepId; InvokableStepDefinitions[stepId] = stepDefinition; return stepId; } }
public void SetUp() { stepDefinition = new StepDefinition { Regex = new Regex("^everybody does the (.*)$"), Action = new Action<string>(s => { }) }; this.step1 = "everybody does the Bartman"; this.matchesRequest1 = new StepMatchesRequest { NameToMatch = this.step1 }; this.step2 = "everybody does the Dew"; this.matchesRequest2 = new StepMatchesRequest { NameToMatch = this.step2 }; this.stepMatch1 = new StepMatch { StepDefinition = this.stepDefinition }; this.stepMatch2 = new StepMatch { StepDefinition = this.stepDefinition }; stepMatcher = new Mock<IMatchSteps>(); stepRunner = new Mock<IRunSteps>(); processor = new Processor(stepMatcher.Object, stepRunner.Object); }