Skip to content
grahamrhay edited this page Nov 11, 2010 · 1 revision

#DiagnosingMatcher

A diagnosing matcher allows a better description of any mismatch:

    public class NullOrEmptyString : DiagnosingMatcher<string>
    {
        protected override bool Matches(string item, IDescription mismatchDescription)
        {
            if (string.IsNullOrEmpty(item) == false)
            {
                mismatchDescription.AppendText(item);
                return false;
            }

            return true;
        }

        public override void DescribeTo(IDescription description)
        {
            description.AppendText("a null or empty string");
        }
    }
Clone this wiki locally