Esempio n. 1
0
        private bool InternalTryMatch(Object actual, IMatcher childMatcher, ISelfDescribing selfDescribing)
        {
            //so we can print child diagnostics after
            var childDiag = new MatchDiagnostics();
            var matched   = childMatcher.Matches(actual, childDiag);

            Text(matched ? "Match":"Mismatch!");

            var desc = Description.With();

            if (selfDescribing != null)
            {
                desc.Value(selfDescribing);
            }
            if (!matched)
            {
                Expect.PrintExpectButGot(desc, actual, childMatcher);
                desc.Value(childDiag);
            }
            else
            {
                desc.Value(childMatcher);
            }
            Child(desc);
            return(matched);
        }
Esempio n. 2
0
        protected void MatchOrFail(Object actual, IMatcher matcher, Object label)
        {
            var diag = new MatchDiagnostics();

            if (!matcher.Matches(actual, diag))
            {
                GenerateAndThrowFailMsg(actual, matcher, diag, label);
            }
        }
Esempio n. 3
0
        private void GenerateAndThrowFailMsg(Object actual, IMatcher matcher, MatchDiagnostics diag, Object label)
        {
            var desc = new Description();

            if (label != null)
            {
                desc.Child("for", label);
            }
            Expect.PrintExpectButGot(desc, actual, matcher);
            desc.Text("==== Diagnostics ====");
            desc.Child(diag);
            TestFirstAssert.Fail(Environment.NewLine + desc.ToString());
        }
Esempio n. 4
0
            private static ThenStep InternalMatch <T>(Scenario scenario, T matcherArg, IMatcher <T> matcher)
            {
                bool passed;
                var  diagnostics = new MatchDiagnostics();

                try
                {
                    passed = matcher.Matches(matcherArg, diagnostics);
                }
                catch (Exception e)
                {
                    throw scenario.FailedWithError(e);
                }
                scenario.ThenAssertMatchPassed(passed, matcherArg, matcher, diagnostics);

                return(new ThenStep(scenario));
            }
Esempio n. 5
0
            private static GivenStep InternalMatch <T>(Scenario scenario, T result, IMatcher <T> matcher)
            {
                bool passed;
                var  diagnostics = new MatchDiagnostics();

                try
                {
                    passed = matcher.Matches(result, diagnostics);
                }
                catch (Exception e)
                {
                    throw scenario.FailedWithError(e);
                }
                scenario.FailIfNotPassed(passed, result, matcher, diagnostics);

                return(new GivenStep(scenario));
            }