Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private Scenario InternalAnd([NotNull] string testCase, Table table)
        {
            if (!TestChain.Any())
            {
                throw new InvalidOperationException("There is no action to add to.");
            }

            ChainedTestMethod lastChainedTestMethod = TestChain.Last();

            switch (lastChainedTestMethod.TestMethod.TestMethodType)
            {
            case TestMethodType.Given:
                return(Given(testCase, table));

            case TestMethodType.When:
                return(When(testCase, table));

            case TestMethodType.Then:
                return(Then(testCase, table));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }