[Adapdev-commits] Adapdev/src/Adapdev.Tests Person.cs,NONE,1.1 SortableCollectionBaseTest.cs,NONE,1.
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2006-03-03 05:29:59
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8050/src/Adapdev.Tests Added Files: Person.cs SortableCollectionBaseTest.cs Log Message: --- NEW FILE: SortableCollectionBaseTest.cs --- using System; using System.Collections; using Adapdev; using NUnit.Framework; namespace Adapdev.Tests { [TestFixture] public class SortableCollectionBaseTest { [Test] public void SortArrayListByAge() { PersonCollection personArray = this.GetPersonCollection(); Assert.AreEqual("Johnny", (personArray[1] as Person).Name); personArray.Sort("Age"); Assert.AreEqual("Joey", (personArray[1] as Person).Name); Assert.AreEqual(25, (personArray[1] as Person).Age); } [Test] public void SortArrayByNameAndAge() { PersonCollection personArray = this.GetPersonCollection(); Assert.AreEqual("Johnny", personArray[1].Name); personArray.Sort("Name, Age"); Assert.AreEqual("C.J.", personArray[0].Name); Assert.AreEqual("Joey", personArray[2].Name); Assert.AreEqual(21, personArray[2].Age); Assert.AreEqual("Joey", personArray[3].Name); Assert.AreEqual(25, personArray[3].Age); } [Test] public void SortArrayByNameAndAgeDESC() { PersonCollection personArray = this.GetPersonCollection(); Assert.AreEqual("Johnny", personArray[1].Name); personArray.Sort("Name, Age DESC"); Assert.AreEqual("C.J.", personArray[0].Name); Assert.AreEqual("Joey", personArray[2].Name); Assert.AreEqual(25, personArray[2].Age); Assert.AreEqual("Joey", personArray[3].Name); Assert.AreEqual(21, personArray[3].Age); } private PersonCollection GetPersonCollection() { PersonCollection personArray = new PersonCollection(); personArray.Add(new Person("Joey", 21)); personArray.Add(new Person("Johnny", 30)); personArray.Add(new Person("Marky", 28)); personArray.Add(new Person("C.J.", 28)); personArray.Add(new Person("Joey", 25)); personArray.Add(new Person("Dee Dee", 33)); return personArray; } } public class PersonCollection : Adapdev.Collections.SortableCollectionBase { public Person this[int index] { get { return this.List[index] as Person; } set { this.List[index] = value; } } public void Add(Person item) { if (!this.List.Contains(item)) this.List.Add(item); } } } --- NEW FILE: Person.cs --- using System; namespace Adapdev.Tests { /// <summary> /// Summary description for Person. /// </summary> public class Person { public string Name { get { return _name; } set { _name = value; } } public int Age { get { return _age; } set { _age = value; } } public Person(string name, int age) { _name = name; _age = age; } public override string ToString() { return Name + ", " + Age; } protected string _name; protected int _age; } } |