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

#FeatureMatcher

A FeatureMatcher<T, U> allows you to focus in on one part of an object:

    public class PostcodeMatcher : FeatureMatcher<Address, string>
    {
        public PostcodeMatcher(IMatcher<string> subMatcher, string featureDescription)
            : base(subMatcher, featureDescription, "Postcode")
        { }

        protected override string FeatureValueOf(Address actual)
        {
            return address.Postcode;
        }
    }

    [Test]
    public void Match_postcode()
    {
        var matchesPostcode = new PostcodeMatcher(Is.EqualTo("N1 5TF"), "Postcode is N1 5TF");
        var address = new Address { Postcode = "N15TF" };

        Assert.That(address, matchesPostcode);
    }
Clone this wiki locally