public void InstantiationWithCopy () {
     ISortDefinition copy = new MutableSortDefinition ("Bing!", false, false);
     MutableSortDefinition def = new MutableSortDefinition (copy);
     Assert.IsFalse (def.IgnoreCase);
     Assert.IsFalse (def.Ascending);
     Assert.IsNotNull (def.Property);
     Assert.AreEqual (copy.Property, def.Property);
 }
 public void TestEquals () {
     ISortDefinition copy = new MutableSortDefinition ("Rab", false, false);
     MutableSortDefinition def = new MutableSortDefinition ("Bing!", false, false);
     def.Property = "Rab";
     Assert.AreEqual (copy, def);
     Assert.AreEqual (copy.GetHashCode (), def.GetHashCode ());
     Assert.IsFalse (def.Equals (null));
 }
 public void TogglesOkWhenPropertyIsSetAgain () 
 {
     MutableSortDefinition def = new MutableSortDefinition (true);
     bool originalAscendingValue = def.Ascending;
     def.Property = "Name";
     def.Property = "Name"; // sort order should (must!) be reversed now...
     Assert.IsFalse (def.Ascending == originalAscendingValue);
 }
 public void DoesNotTogglesWhenPropertyIsSetAgain () 
 {
     MutableSortDefinition def = new MutableSortDefinition (true);
     bool originalAscendingValue = def.Ascending;
     def.Property = "Name";
     def.Property = "Age"; // sort order must not be toggled (different property)
     Assert.IsTrue (def.Ascending == originalAscendingValue);
 }
        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
        }
        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
        }
//        [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);
            }
        }
        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);
            }
        }
        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);
            }
        }
        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 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);
            }
        }
 public void PropertySetter () {
     MutableSortDefinition def = new MutableSortDefinition ();
     def.Property = null;
     Assert.IsNotNull (def.Property);
     Assert.AreEqual (string.Empty, def.Property);
 }
        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);
            }
        }
//        [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);
            }
        }
        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 Instantiation () {
     MutableSortDefinition def = new MutableSortDefinition ();
     Assert.IsTrue (def.IgnoreCase);
     Assert.IsTrue (def.Ascending);
     Assert.IsNotNull (def.Property);
 }
Ejemplo n.º 19
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);
            int actual = cmp.Compare(one, two);
            Assert.IsTrue(actual == 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);
        }