private static string ExpectedMessage(
            TestMatcherName matcherName, UserDataCollection data)
        {
            if (matcherName.IsInvariant)
            {
                return("");
            }
            if (matcherName.IsAndOr)
            {
                return(matcherName.IsNegated ? SR.NotExpectedTo() : SR.ExpectedTo());
            }

            var msgCode = matcherName.ToSRKey();
            var msg     = SR.ResourceManager.GetString(msgCode);

            if (msg == null)
            {
                return(MissingLocalization(msgCode));
            }

            var fill = FillableMessage.Fill(msg, data);

            data.ExpectedConsumedInMessage = fill.Keys.Contains("Expected");
            return(fill.ToString());
        }
示例#2
0
        public void For_unwinds_negation_support_test_matcher()
        {
            var wrapped = Matchers.Not(Matchers.BeEmpty());

            Assert.Equal(
                "spec.empty.not", TestMatcherName.For(wrapped).Name
                );
        }
示例#3
0
        public void For_unwinds_support_test_matcher()
        {
            var wrapped = TestMatcher.UnitWrapper(new ThrowsMatcher());

            Assert.Equal(
                "spec.throws", TestMatcherName.For(wrapped).Name
                );
        }
示例#4
0
        public void For_supports_the_invariant_matchers()
        {
            Assert.Equal(
                "spec.nothing",
                TestMatcherName.For(TestMatcher.Nothing).Name
                );

            Assert.Equal(
                "spec.anything",
                TestMatcherName.For(TestMatcher.Anything).Name
                );
        }
示例#5
0
        public void For_supports_the_And_and_Or_matchers()
        {
            Assert.Equal(
                "spec.and",
                TestMatcherName.For(Matchers.And(Matchers.BeEmpty(), Matchers.BeEmpty())).Name
                );

            Assert.Equal(
                "spec.or",
                TestMatcherName.For(Matchers.Or(Matchers.BeEmpty(), Matchers.BeEmpty())).Name
                );
        }
                public bool Matches(ITestActualEvaluation <TFrom> actualFactory)
                {
                    var      real  = TestMatcherName.FromType(_real.GetType());
                    Func <T> thunk = () => {
                        try {
                            var actual = actualFactory.Value;
                            return((T)(object)actual);
                        } catch (InvalidCastException e) {
                            throw SpecFailure.CastRequiredByMatcherFailure(e, real);
                        }
                    };

                    return(_real.Matches(TestActual.Of(thunk)));
                }
示例#7
0
        public static AssertException UnusableComparer(TestMatcherName name, object comparer, Exception e)
        {
            var failure = new TestFailure(name)
            {
                Message  = SR.UnusableComparer(),
                UserData =
                {
                    { "Comparer", comparer }
                }
            };

            return(new AssertException(
                       SR.UnusableComparer(), failure, e
                       ));
        }
                public bool Matches(ITestActualEvaluation <IEnumerable> actualFactory)
                {
                    // When the matcher can already handle the input, no need to apply
                    // adapter logic
                    if (_real is ITestMatcher <IEnumerable> fast)
                    {
                        return(fast.Matches(actualFactory));
                    }

                    var real = TestMatcherName.FromType(_real.GetType());
                    Func <IEnumerable <object> > thunk = () => (
                        actualFactory.Value.Cast <object>()
                        );

                    return(_real.Matches(TestActual.Of(thunk)));
                }
        static TestFailure FailureMessageCore(object matcher, bool predicate)
        {
            var matcherName = TestMatcherName.For(matcher);

            if (predicate)
            {
                matcherName = matcherName.Predicate();
            }

            // We use the actual matcher to get the user data for the failure
            var failure = new TestFailure(matcherName, ActualMatcher(matcher));

            string message = ExpectedMessage(matcherName, failure.UserData);

            failure.Message = message;
            ChildrenMessages(failure, matcher);
            return(failure);
        }
示例#10
0
 public void FromType_gets_type_names(Type type, string expected)
 {
     Assert.Equal(
         expected, TestMatcherName.FromType(type).Name
         );
 }