Пример #1
0
        private static string mismatchDescription <T>(IMatcher <T> matcher, object arg)
        {
            Description description = new Description();

            matcher.DescribeMismatch(arg, description);
            return(description.ToString().Trim());
        }
Пример #2
0
        protected override bool MatchesSafely(IEnumerable <T> actual, IDescription description)
        {
            var enumerable = actual.ToList();

            if (isEmpty(enumerable))
            {
                description.AppendText("was empty");
                return(false);
            }

            if (doesOneMatch(enumerable))
            {
                return(true);
            }

            description.AppendText("mismatches were: [");

            bool isPastFirst = false;

            foreach (T item in enumerable)
            {
                if (isPastFirst)
                {
                    description.AppendText(", ");
                }
                _matcher.DescribeMismatch(item, description);

                isPastFirst = true;
            }

            description.AppendText("]");
            return(false);
        }
Пример #3
0
        public override void DescribeMismatch(object actual, IDescription mismatch)
        {
            var converted = ConvertToString(actual);

            mismatch.AppendText("ToString()").AppendText(" ");
            _subMatcher.DescribeMismatch(converted, mismatch);
        }
Пример #4
0
        public static void ShouldHaveMismatchDescriptionForValue <TMatched>(this IMatcher <TMatched> matcher, TMatched value, string expected)
        {
            var description = new StringDescription();

            matcher.DescribeMismatch(value, description);
            var actual = description.ToString();

            Xunit.Assert.Equal(expected, actual);
        }
Пример #5
0
        public static void ShouldHaveMismatchDescriptionForValue <TMatched>(this IMatcher <TMatched> matcher, TMatched value, IMatcher <string> expectedMatcher)
        {
            var description = new StringDescription();

            matcher.DescribeMismatch(value, description);
            var actual = description.ToString();

            Assert.That(actual, expectedMatcher);
        }
Пример #6
0
 protected override bool MatchesSafely(T item, IDescription mismatchDescription)
 {
     if (!_matcher.Matches(item))
     {
         _matcher.DescribeMismatch(item, mismatchDescription);
         return(false);
     }
     return(true);
 }
Пример #7
0
        private static void WriteActual <T>(T actual, IMatcher <T> matcher, TextWriter writer)
        {
            writer.Write("  But ");
            var mismatchDescription = new StringDescription();

            matcher.DescribeMismatch(actual, mismatchDescription);
            writer.Write(mismatchDescription.ToString());
            writer.WriteLine();
        }
        public void MismatchDescriptionMustBeCorrect()
        {
            var description = new StringDescription();

            _matcher.DescribeMismatch(_matched, description);
            var expected = ExpectMismatchDescription();
            var actual   = description.ToString();

            Xunit.Assert.Equal(expected, actual);
        }
Пример #9
0
        protected override bool MatchesSafely(IEnumerable <T> actual, IDescription description)
        {
            T invalid = actual.FirstOrDefault(value => !_matcher.Matches(value));

            if (invalid != null)
            {
                description.AppendText("an item ");
                _matcher.DescribeMismatch(invalid, description);
                return(false);
            }
            return(true);
        }
Пример #10
0
        protected override bool MatchesSafely(TSafe actual, IDescription mismatch)
        {
            TSub featureValue = FeatureValueOf(actual);

            if (!_subMatcher.Matches(featureValue))
            {
                mismatch.AppendText(_featureName).AppendText(" ");
                _subMatcher.DescribeMismatch(featureValue, mismatch);
                return(false);
            }
            return(true);
        }
Пример #11
0
        protected override bool MatchesSafely(T collection, IDescription mismatchDescription)
        {
            var featureValue = FeatureValueOf(collection);

            if (subMatcher.Matches(featureValue) == false)
            {
                mismatchDescription.AppendText(featureName).AppendText(" ");
                subMatcher.DescribeMismatch(featureValue, mismatchDescription);
                return(false);
            }

            return(true);
        }
Пример #12
0
        public static void That <T>(String reason, Func <T> func, IMatcher <T> matcher)
        {
            T actual = WaitAndGetActualValue(func, matcher, _timeout, _delay);

            if (!matcher.Matches(actual))
            {
                StringDescription stringDescription1 = new StringDescription();
                matcher.DescribeTo(stringDescription1);
                StringDescription stringDescription2 = new StringDescription();
                matcher.DescribeMismatch(actual, stringDescription2);
                throw new MatchException(stringDescription1.ToString(), stringDescription2.ToString(), reason);
            }
        }
Пример #13
0
        public static void That <T>(string message, T actual, IMatcher <T> matcher)
        {
            if (!matcher.Matches(actual))
            {
                Description description = new Description();
                description.AppendText(message)
                .AppendText("\nExpected: ")
                .AppendDescribable(matcher)
                .AppendText("\n     But: ");
                matcher.DescribeMismatch(actual, description);

                throw new ArgumentException(description.ToString());
            }
        }
Пример #14
0
        protected override bool MatchesSafely(IEnumerable <T> collection, IDescription mismatchDescription)
        {
            foreach (var item in collection)
            {
                if (matcher.Matches(item))
                {
                    continue;
                }

                mismatchDescription.AppendText("an item ");
                matcher.DescribeMismatch(item, mismatchDescription);
                return(false);
            }
            return(true);
        }
Пример #15
0
        private static void That <T>(T actual, IMatcher <T> matcher, string reason)
        {
            if (matcher.Matches(actual))
            {
                return;
            }

            var description = new StringDescription();

            description.AppendText(reason)
            .AppendText("\nExpected: ")
            .AppendDescriptionOf(matcher)
            .AppendText("\n     but: ");
            matcher.DescribeMismatch(actual, description);

            throw new AssertionError(description.ToString());
        }
Пример #16
0
        public static void That <T>(T actual, IMatcher <T> matcher)
        {
            if (matcher.Matches(actual))
            {
                return;
            }

            var description = new StringDescription();

            matcher.DescribeTo(description);

            var mismatchDescription = new StringDescription();

            matcher.DescribeMismatch(actual, mismatchDescription);

            throw new MatchException(description.ToString(), mismatchDescription.ToString(), null);
        }
Пример #17
0
        private bool Matches(TSource o, IDescription mismatchDescription)
        {
            if (!(o is TDest))
            {
                mismatchDescription.AppendText("it was not of type {0}", typeof(TDest).Name);
                return(false);
            }

            var cast = (TDest)(object)o;

            if (!_innerMatcher.Matches(cast))
            {
                _innerMatcher.DescribeMismatch(cast, mismatchDescription);
                return(false);
            }

            return(true);
        }
Пример #18
0
        protected override bool MatchesSafely(IEnumerable <T> collection, IDescription mismatchDescription)
        {
            var isPastFirst = false;

            foreach (var item in collection)
            {
                if (elementMatcher.Matches(item))
                {
                    return(true);
                }
                if (isPastFirst)
                {
                    mismatchDescription.AppendText(", ");
                }
                elementMatcher.DescribeMismatch(item, mismatchDescription);
                isPastFirst = true;
            }
            return(false);
        }
Пример #19
0
        ///<summary>
        /// Asserts that an item satisfies the condition specified by matcher.
        ///</summary>
        ///<param name="item">The item to test.</param>
        ///<param name="matcher">A <see cref="IMatcher{T}">matcher</see>.</param>
        ///<param name="messageFormat">The custom assertion message format, or null if none.</param>
        ///<param name="messageArgs">The custom assertion message arguments, or null if none.</param>
        ///<typeparam name="T">The static type accepted by the matcher.</typeparam>
        public static void That <T>(T item, IMatcher <T> matcher, string messageFormat, params object[] messageArgs)
        {
            AssertionHelper.Verify(() =>
            {
                if (matcher.Matches(item))
                {
                    return(null);
                }

                var description         = new StringDescription();
                var mismatchDescription = new StringDescription();

                matcher.DescribeTo(description);
                matcher.DescribeMismatch(item, mismatchDescription);

                return(new AssertionFailureBuilder("Expected " + description)
                       .SetMessage(messageFormat, messageArgs)
                       .AddLabeledValue("Expected", description.ToString())
                       .AddLabeledValue("But", mismatchDescription.ToString())
                       .ToAssertionFailure());
            });
        }
Пример #20
0
        private bool Matches(TObject o, IDescription mismatchDescription)
        {
            try
            {
                var value = _propertyAccessor(o);

                if (!_propertyMatcher.Matches(value))
                {
                    mismatchDescription.AppendText("member {0} value ", _property);
                    _propertyMatcher.DescribeMismatch(value, mismatchDescription);
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                mismatchDescription.AppendText("and exception has been thrown while accessing property {0}:", _property)
                .AppendNewLine()
                .AppendText(ex.ToString());

                return(false);
            }
        }
Пример #21
0
 public override void DescribeMismatch(T item, IDescription mismatchDescription)
 {
     _toDecorate.DescribeMismatch(item, mismatchDescription);
 }
Пример #22
0
 public override void DescribeMismatch(T item, IDescription mismatchDescription)
 {
     _decoratedMatcher.DescribeMismatch(item, mismatchDescription);
 }
 public void DescribeMismatch(T item, IDescription mismatchDescription)
 {
     _createdMatcher.DescribeMismatch(item, mismatchDescription);
 }
Пример #24
0
 public override void DescribeMismatch(object actual, IDescription description)
 {
     _matcher.DescribeMismatch(actual, description);
 }
 private void DescribeMismatch(IMatcher <T> matcher, T item)
 {
     _description.AppendText("item " + _nextMatchIndex + ": ");
     matcher.DescribeMismatch(item, _description);
 }