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()); }
public void For_unwinds_negation_support_test_matcher() { var wrapped = Matchers.Not(Matchers.BeEmpty()); Assert.Equal( "spec.empty.not", TestMatcherName.For(wrapped).Name ); }
public void For_unwinds_support_test_matcher() { var wrapped = TestMatcher.UnitWrapper(new ThrowsMatcher()); Assert.Equal( "spec.throws", TestMatcherName.For(wrapped).Name ); }
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 ); }
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))); }
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); }
public void FromType_gets_type_names(Type type, string expected) { Assert.Equal( expected, TestMatcherName.FromType(type).Name ); }