private bool MethodCheck(TestMethod method, TestMethodType expectedMethodType, string expectedMethodName) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse return(method.MethodInfo != null && method.MatchingPattern != null && method.TestMethodType == expectedMethodType && string.Equals(method.MethodInfo.Name, expectedMethodName, StringComparison.Ordinal)); }
public TestMethod(TestMethodType testMethodType, [NotNull] MethodInfo methodInfo, [NotNull] string regexPattern) { TestMethodType = testMethodType; MethodInfo = methodInfo; RegexPattern = regexPattern; MatchingPattern = new Regex(regexPattern); }
protected ChainedTestMethod FindTestMethod(TestMethodType testMethodType, [NotNull] string testCase, [CanBeNull] Table table) { _foundTestMethods.Clear(); foreach (TestMethod testMethod in TestMethods) { if (testMethod.TestMethodType == testMethodType) { Match match = testMethod.MatchingPattern.Match(testCase); if (match.Success) { _foundTestMethods.Add(new Tuple <TestMethod, Match>(testMethod, match)); } } } if (_foundTestMethods.Count == 0) { throw new TestMethodNotFoundException($"Test method for test case '{testCase}' hasn't been found"); } if (_foundTestMethods.Count > 1) { string matchedTestMethods = string.Join(", ", _foundTestMethods.Select(item => $"'{item.Item1.RegexPattern}'")); throw new AmbiguousTestMethodFoundException( $"Following test methods match to '{testCase}':{Environment.NewLine}{matchedTestMethods}"); } Tuple <TestMethod, Match> matchingTestMethod = _foundTestMethods.First(); object[] parameters = BuildParameters(matchingTestMethod.Item1, matchingTestMethod.Item2, table).ToArray(); ChainedTestMethod chainedTestMethod = new ChainedTestMethod(matchingTestMethod.Item1, testCase, parameters); return(chainedTestMethod); }