public void CompareWithNullArguments() { ISortDefinition definition = new MutableSortDefinition("Nails", false, true); Funk one = new Funk(1, "long"); PropertyComparator cmp = new PropertyComparator(definition); Assert.AreEqual(0, cmp.Compare(null, null)); // nulls are always last (i.e. greater than) Assert.AreEqual(1, cmp.Compare(null, one)); // any non-null instance comes before null (i.e. less than). Assert.AreEqual(-1, cmp.Compare(one, null)); }
public void CompareWithNonExistantProperty() { ISortDefinition definition = new MutableSortDefinition("Deborahs.Banjo", true, true); PropertyComparator cmp = new PropertyComparator(definition); TestObject one = new TestObject("Rick", 19); TestObject two = new TestObject("Balzac", 205); Assert.Throws <InvalidPropertyException>(() => cmp.Compare(one, two)); }
public void Compare() { ISortDefinition definition = new MutableSortDefinition("Age", false, true); PropertyComparator cmp = new PropertyComparator(definition); TestObject one = new TestObject("Rick", 19); TestObject two = new TestObject("Balzac", 205); int actual = cmp.Compare(one, two); Assert.IsTrue(actual < 0); // 19 is less than 205 }
public void CompareWithNullProperty() { ISortDefinition definition = new MutableSortDefinition("Lawyer.Company", true, true); PropertyComparator cmp = new PropertyComparator(definition); TestObject one = new TestObject("Rick", 19); one.Lawyer = new NestedTestObject("Gizajoab"); TestObject two = new TestObject("Balzac", 205); // no Lawyer.Company property set on object two... int actual = cmp.Compare(one, two); Assert.IsTrue(actual > 0); // Gizajoab is greater than null }
public void CompareNestedProperty() { ISortDefinition definition = new MutableSortDefinition("Lawyer.Company", true, true); PropertyComparator cmp = new PropertyComparator(definition); TestObject one = new TestObject("Rick", 19); one.Lawyer = new NestedTestObject("Gizajoab"); TestObject two = new TestObject("Balzac", 205); two.Lawyer = new NestedTestObject("Wallpaperer"); int actual = cmp.Compare(one, two); Assert.IsTrue(actual < 0); // Gizajoab is less than Wallpaperer }