Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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
        }
Esempio n. 3
0
        public void CanGetSortDefinition()
        {
            ISortDefinition definition = new MutableSortDefinition("Age", false, true);

            PropertyComparator cmp            = new PropertyComparator(definition);
            ISortDefinition    sortDefinition = cmp.SortDefinition;

            Assert.AreSame(definition, sortDefinition);
            Assert.AreEqual(definition.Property, sortDefinition.Property);
            Assert.AreEqual(definition.Ascending, sortDefinition.Ascending);
            Assert.AreEqual(definition.IgnoreCase, sortDefinition.IgnoreCase);
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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
        }
Esempio n. 6
0
        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
        }
Esempio n. 7
0
//        [Ignore("Sort ordering is not preserved (unstable) with equal elements (c.f. System.Array.Sort (Array, IComparer)))")]
        public void OrderingIsUnperturbedWithEqualProps()
        {
            ISortDefinition definition = new MutableSortDefinition("Age", false, true);

            TestObject one   = new TestObject("Rick", 19);
            TestObject two   = new TestObject("Balzac", 19);
            TestObject three = new TestObject("Jenny", 19);

            TestObject[] actual   = new TestObject[] { one, two, three };
            TestObject[] expected = new TestObject[] { one /*Rick*/, two /*Balzac*/, three /*Jenny*/ };
            PropertyComparator.Sort(actual, definition);
            for (int i = 0; i < actual.Length; ++i)
            {
                Assert.AreEqual(expected[i].Name, actual[i].Name);
            }
        }
Esempio n. 8
0
        public void Sort()
        {
            ISortDefinition definition = new MutableSortDefinition("NAmE", true, true);

            TestObject one   = new TestObject("Rick", 19);
            TestObject two   = new TestObject("Balzac", 205);
            TestObject three = new TestObject("Jenny", 89);

            TestObject[] actual   = new TestObject[] { one, two, three };
            TestObject[] expected = new TestObject[] { two /*Balzac*/, three /*Jenny*/, one /*Rick*/ };
            PropertyComparator.Sort(actual, definition);
            for (int i = 0; i < actual.Length; ++i)
            {
                Assert.AreEqual(expected[i].Name, actual[i].Name);
            }
        }
Esempio n. 9
0
        public void SortInDescendingOrder()
        {
            ISortDefinition definition = new MutableSortDefinition("NAmE", true, false);

            TestObject one   = new TestObject("Rick", 19);
            TestObject two   = new TestObject("Balzac", 205);
            TestObject three = new TestObject("Jenny", 89);

            TestObject[] actual = new TestObject[] { one, two, three };
            // Rick comes after Jenny comes after Balzac (descending sort order)...
            TestObject[] expected = new TestObject[] { one /*Rick*/, three /*Jenny*/, two /*Balzac*/ };
            PropertyComparator.Sort(actual, definition);
            for (int i = 0; i < actual.Length; ++i)
            {
                Assert.AreEqual(expected[i].Name, actual[i].Name);
            }
        }
Esempio n. 10
0
 public void SortWithNullDefinition()
 {
     Assert.Throws <ArgumentNullException>(() => PropertyComparator.Sort(Type.EmptyTypes, null));
 }