public void Explore()
        {
            Property2ChainableComparer inheritor = new Property2ChainableComparer();

            Assert.That(inheritor, Is.InstanceOf <IComparer <ComparisonSubject> >(), "is a proper comparer");

            ComparisonSubject x = new ComparisonSubject("x", 1, 1m), y = new ComparisonSubject("y", 1, 2m);

            Assert.That(inheritor.Compare(x, y), Is.EqualTo(0), "x.Property2 == y.Property2");

            ChainableComparer <ComparisonSubject> asc  = inheritor.Then(new Property3ChainableComparer());

            Assert.That(x, Is.LessThan(y).Using(asc), "x.Properyty3 < y.Property2");

            ChainableComparer <ComparisonSubject> desc = new Property2ChainableComparer()
                                                         .Then(new Property3ChainableComparer(Direction.Descending));

            Assert.That(x, Is.GreaterThan(y).Using(desc), "x.Properyty3 > y.Property2");

            var chainable = new Property2ChainableComparer();

            Assert.That(chainable.Compare(x, null), Is.GreaterThan(0));
            Assert.That(chainable.Compare(null, y), Is.LessThan(0));
            Assert.That(chainable.Compare(null, null), Is.EqualTo(0));
        }
Exemple #2
0
        public void Clients_DoNotHaveToCareAboutNulls()
        {
            var notNull   = new ComparisonSubject("a", 1, 1m);
            var chainable = new ReversedComparer <ComparisonSubject>(new Property2Comparer());

            Assert.That(chainable.Compare(notNull, null), Is.GreaterThan(0));
            Assert.That(chainable.Compare(null, notNull), Is.LessThan(0));
            Assert.That(chainable.Compare(null, null), Is.EqualTo(0));
        }
        public void Clients_DoNotHaveToCareAboutNulls()
        {
            var notNull   = new ComparisonSubject("a", 1, 1m);
            var chainable = new SelectorComparer <ComparisonSubject, int>(s => s.Property2);

            Assert.That(chainable.Compare(notNull, null), Is.GreaterThan(0));
            Assert.That(chainable.Compare(null, notNull), Is.LessThan(0));
            Assert.That(chainable.Compare(null, null), Is.EqualTo(0));
        }
        public void Inheritors_DoNotHaveToCareAboutNulls()
        {
            var notNull  = new ComparisonSubject("a", 1, 1m);
            var comparer = new Property2Comparer();

            Assert.That(() => comparer.Compare(notNull, null), Throws.InstanceOf <NullReferenceException>());

            var chainable = new Property2ChainableComparer();

            Assert.That(chainable.Compare(notNull, null), Is.GreaterThan(0));
            Assert.That(chainable.Compare(null, notNull), Is.LessThan(0));
            Assert.That(chainable.Compare(null, null), Is.EqualTo(0));
        }
 public static void Setup(Action<ComparisonSubject<ComparisonAgainstValue, int>> comparison)
 {
     _comparison = new ComparisonSubject<ComparisonAgainstValue, int>();
     comparison(_comparison);
 }
 public static void Setup(Action<ComparisonSubject<ComparisonAgainstSelf, ComparisonAgainstSelf>> comparison)
 {
     _comparison = new ComparisonSubject<ComparisonAgainstSelf, ComparisonAgainstSelf>();
     comparison(_comparison);
 }
 public static void SetupInverse(Action<ComparisonSubject<string, ComparisonAgainstReference>> comparison)
 {
     _inverse = new ComparisonSubject<string, ComparisonAgainstReference>();
     comparison(_inverse);
 }
 public static void Setup(Action<ComparisonSubject<ComparisonAgainstReference, string>> comparison)
 {
     _comparison = new ComparisonSubject<ComparisonAgainstReference, string>();
     comparison(_comparison);
 }