private string GetSuggestionText(StepBinding stepBinding) { string suggestionTextBase = stepBinding.Regex == null ? "[...]" : "[" + RegexSampler.GetRegexSample(stepBinding.Regex.ToString(), stepBinding.Method.Parameters.Select(p => p.ParameterName).ToArray()) + "]"; return(string.Format("{0} -> {1}", suggestionTextBase, stepBinding.Method.ShortDisplayText)); }
private async Task <TestResultMessage[]> PerformEventuallyConsistentStepsTest(MethodInfo method) { var scenarioStep = new WhenStep("When an exception is thrown", DataTable.Empty, null); var testFeature = new Feature( "Feature", null, Background.Empty, new[] { new Scenario( "Scenario", new[] { scenarioStep }, 1, Enumerable.Empty <Tag>()) }, Enumerable.Empty <ScenarioOutline>(), Enumerable.Empty <Rule>(), Enumerable.Empty <Tag>()); var testData = new DiscoveredTestData(testAssembly, testFeature, null, testFeature.Scenarios.First()); var binding = new StepBinding(scenarioStep, method, Array.Empty <object>()); mockStepBinder .Setup(m => m.GetBindingFor(scenarioStep, testAssembly)) .Returns(binding); var testResult = await stepsExecutor.Execute(testCase, testData, testRunContext, mockLogger.Object); return(testResult .Messages .Where( message => message.Category == TestResultMessage.StandardOutCategory) .ToArray()); }
public void IdentifyStepsNotMarkedAsMustNotEventuallyFail() { var step = new GivenStep("a plain text match", null, null); var method = typeof(StepBindingStaticSamples).GetMethod("GivenAPlainTextMatch"); var binding = new StepBinding(step, method, Array.Empty <object>()); Assert.IsFalse(binding.IsMarkedMustNotEventuallyFail); }
public void IdentifyStepsMarkedAsMustNotEventuallyFail() { var step = new ThenStep("this eventually succeeds", null, null); var method = typeof(StepBindingEventuallyConsistentStepSamples).GetMethod("FailsOnSecondCallMarkedAsMustNotEventuallyFail"); var binding = new StepBinding(step, method, Array.Empty <object>()); Assert.IsTrue(binding.IsMarkedMustNotEventuallyFail); }
public void IdentifyStepsMarkedAsEventuallySuccessfull() { var step = new ThenStep("this eventually succeeds", null, null); var method = typeof(StepBindingEventuallyConsistentStepSamples).GetMethod("ThenThisEventuallySucceeds"); var binding = new StepBinding(step, method, Array.Empty <object>()); Assert.IsTrue(binding.IsSuccessEventual); }
private string GetInsertionText(StepBinding stepBinding) { if (stepBinding.Regex == null) { return("..."); } var paramNames = stepBinding.Method.Parameters.Select(p => p.ParameterName); return(RegexSampler.GetRegexSample(stepBinding.Regex.ToString(), paramNames.ToArray())); }
public async Task NotWrapExceptionsInATargetInvocationExceptionWhenInvokedMethodThrowsAnException() { var step = new WhenStep("an exception is thrown", null, null); var method = typeof(StepBindingStaticSamples).GetMethod("WhenAnExceptionIsThrown"); var binding = new StepBinding(step, method, Array.Empty <object>()); var exception = await Assert.ThrowsExceptionAsync <InvalidOperationException>( () => binding.Execute( mockServiceProvider.Object, new Collection <TestResultMessage>())); Assert.AreEqual("Hello", exception.Message); }
public bool Match(StepBinding binding, bool includeRegexCheck, IBindingMatchService bindingMatchService) { if (binding.BindingType != BindingType) { return(false); } if (instances.Count == 0) { return(false); } return(instances.Any(i => i.Match(binding, true, bindingMatchService))); }
public BoundStepSuggestions(StepBinding stepBinding, INativeSuggestionItemFactory <TNativeSuggestionItem> nativeSuggestionItemFactory) { if (stepBinding == null) { throw new ArgumentNullException("stepBinding"); } StepBinding = stepBinding; BindingType = stepBinding.BindingType; string suggestionText = GetSuggestionText(stepBinding); NativeSuggestionItem = nativeSuggestionItemFactory.Create(suggestionText, GetInsertionText(StepBinding), 0, BindingType.ToString().Substring(0, 1) + "-b", this); suggestions = new StepSuggestionList <TNativeSuggestionItem>(nativeSuggestionItemFactory); }
private async Task <TestResultMessage[]> PerformEventuallyConsistentScenarioTest(MethodInfo givenMethod, MethodInfo whenMethod, MethodInfo thenMethod) { var givenStep = new GivenStep("Given", DataTable.Empty, null); var whenStep = new WhenStep("When", DataTable.Empty, null); var thenStep = new ThenStep("Then", DataTable.Empty, null); var testFeature = new Feature( "Feature", null, Background.Empty, new[] { new Scenario( "Scenario", new IStep[] { givenStep, whenStep, thenStep }, 1, new List <Tag> { new Tag("eventuallyConsistent(retryInterval=00:00:01;within=00:00:05)") }) }, Enumerable.Empty <ScenarioOutline>(), Enumerable.Empty <Rule>(), Enumerable.Empty <Tag>()); var testData = new DiscoveredTestData(testAssembly, testFeature, null, testFeature.Scenarios.First()); var givenStepBinding = new StepBinding(givenStep, givenMethod, Array.Empty <object>()); var whenStepBinding = new StepBinding(whenStep, whenMethod, Array.Empty <object>()); var thenStepBinding = new StepBinding(thenStep, thenMethod, Array.Empty <object>()); mockStepBinder .Setup(m => m.GetBindingFor(givenStep, testAssembly)) .Returns(givenStepBinding); mockStepBinder .Setup(m => m.GetBindingFor(whenStep, testAssembly)) .Returns(whenStepBinding); mockStepBinder .Setup(m => m.GetBindingFor(thenStep, testAssembly)) .Returns(thenStepBinding); var testResult = await stepsExecutor.Execute(testCase, testData, testRunContext, mockLogger.Object); return(testResult .Messages .Where( message => message.Category == TestResultMessage.StandardOutCategory) .ToArray()); }
public void RemoveBinding(StepBinding stepBinding) { var item = boundStepSuggestions.GetRelatedItems(stepBinding.Regex).FirstOrDefault(it => it.StepBinding == stepBinding); if (item == null) { return; } foreach (var stepSuggestion in item.Suggestions.ToArray()) { item.RemoveSuggestion(stepSuggestion); if (!stepSuggestion.MatchGroups.Any()) { notMatchingSteps[item.BindingType].AddSuggestion(stepSuggestion); } } boundStepSuggestions.Remove(item); }
public void AddBinding(StepBinding stepBinding) { var item = new BoundStepSuggestions <TNativeSuggestionItem>(stepBinding, nativeSuggestionItemFactory); var affectedSuggestions = new List <IBoundStepSuggestion <TNativeSuggestionItem> >( boundStepSuggestions.GetRelatedItems(stepBinding.Regex).SelectMany(relatedItem => relatedItem.Suggestions).Where(s => s.Match(stepBinding, true, BindingMatchService))); affectedSuggestions.AddRange(notMatchingSteps[item.BindingType].Suggestions.Where(s => s.Match(stepBinding, true, BindingMatchService))); foreach (var affectedSuggestion in affectedSuggestions) { RemoveBoundStepSuggestion(affectedSuggestion); } boundStepSuggestions.Add(item); foreach (var affectedSuggestion in affectedSuggestions) { AddStepSuggestion(affectedSuggestion); } }
private BindingMatch Match(StepBinding stepBinding, StepArgs stepArgs, bool useParamMatching, bool useScopeMatching) { Match match = stepBinding.Regex.Match(stepArgs.Text); // Check if regexp is a match if (!match.Success) { return(null); } int scopeMatches = 0; if (useScopeMatching && stepBinding.IsScoped) { if (!stepBinding.BindingScope.Match(stepArgs.StepContext, out scopeMatches)) { return(null); } } var bindingMatch = new BindingMatch(stepBinding, match, CalculateExtraArgs(stepArgs), stepArgs, scopeMatches); if (useParamMatching) { // check if the regex + extra arguments match to the binding method parameters if (bindingMatch.Arguments.Length != stepBinding.ParameterTypes.Length) { return(null); } // Check if regex & extra arguments can be converted to the method parameters if (bindingMatch.Arguments.Where( (arg, argIndex) => !CanConvertArg(arg, stepBinding.ParameterTypes[argIndex])).Any()) { return(null); } } return(bindingMatch); }
public BindingMatch(StepBinding stepBinding, int scopeMatches) { StepBinding = stepBinding; ScopeMatches = scopeMatches; }
private BindingMatch Match(StepBinding stepBinding, StepArgs stepArgs, bool useParamMatching, bool useScopeMatching) { Match match = stepBinding.Regex.Match(stepArgs.Text); // Check if regexp is a match if (!match.Success) return null; var extraArgs = CalculateExtraArgs(stepArgs); int scopeMatches = 0; if (useParamMatching) { var regexArgs = match.Groups.Cast<Group>().Skip(1).Select(g => g.Value).ToArray(); // check if the regex + extra arguments match to the binding method parameters if (regexArgs.Length + extraArgs.Length != stepBinding.ParameterTypes.Length) return null; // Check if regex arguments can be converted to the method parameters CultureInfo cultureInfo = FeatureContext.Current.BindingCulture; for (int regexArgIndex = 0; regexArgIndex < regexArgs.Length; regexArgIndex++) { Type parameterType = stepBinding.ParameterTypes[regexArgIndex]; if (!stepArgumentTypeConverter.CanConvert(regexArgs[regexArgIndex], parameterType, cultureInfo)) return null; } // Check if there are corresponting parameters defined for the extra arguments for (int extraArgIndex = 0; extraArgIndex < extraArgs.Length; extraArgIndex++) { Type parameterType = stepBinding.ParameterTypes[extraArgIndex + regexArgs.Length]; Type argType = extraArgs[extraArgIndex].GetType(); if (argType != parameterType) return null; } } if (useScopeMatching && stepBinding.IsScoped) { if (!stepBinding.BindingScope.Match(stepArgs.StepContext, out scopeMatches)) return null; } return new BindingMatch(stepBinding, match, extraArgs, stepArgs, scopeMatches); }
private BindingMatch Match(StepBinding stepBinding, StepArgs stepArgs, bool useParamMatching, bool useScopeMatching) { Match match = stepBinding.Regex.Match(stepArgs.Text); // Check if regexp is a match if (!match.Success) return null; int scopeMatches = 0; if (useScopeMatching && stepBinding.IsScoped) { if (!stepBinding.BindingScope.Match(stepArgs.StepContext, out scopeMatches)) return null; } var bindingMatch = new BindingMatch(stepBinding, match, CalculateExtraArgs(stepArgs), stepArgs, scopeMatches); if (useParamMatching) { // check if the regex + extra arguments match to the binding method parameters if (bindingMatch.Arguments.Length != stepBinding.ParameterTypes.Length) return null; // Check if regex & extra arguments can be converted to the method parameters if (bindingMatch.Arguments.Where( (arg, argIndex) => !CanConvertArg(arg, stepBinding.ParameterTypes[argIndex])).Any()) return null; } return bindingMatch; }
public bool Match(StepBinding binding, bool includeRegexCheck, IBindingMatchService bindingMatchService) { return(bindingMatchService.Match(binding, this, useRegexMatching: includeRegexCheck, useParamMatching: false).Success); }