public void TestBothNull() { _comparer = new ReflectedPropertyComparer <MultiPropBO>("IntProp"); _boCol.Sort(_comparer); Assert.IsNull(_boCol[0].IntProp); Assert.IsNull(_boCol[1].IntProp); }
public void TestDateTimeComparer() { string propName = "DateTimeProp"; DateTime dt1 = new DateTime(2006, 4, 1); DateTime dt2 = new DateTime(2005, 4, 2); DateTime dt3 = new DateTime(2005, 4, 1); _boCol[0].SetPropertyValue(propName, dt1); _boCol[1].SetPropertyValue(propName, dt2); _boCol[2].SetPropertyValue(propName, dt3); DateTimeComparer <MultiPropBO> comparer = new DateTimeComparer <MultiPropBO>(propName); _boCol.Sort(comparer); Assert.IsNull(_boCol[0].GetPropertyValue(propName)); Assert.AreEqual(dt3, _boCol[1].GetPropertyValue(propName)); Assert.AreEqual(dt2, _boCol[2].GetPropertyValue(propName)); Assert.AreEqual(dt1, _boCol[3].GetPropertyValue(propName)); }
public void Test_CollectionLoad_Load_CriteriaString_Untyped() { //---------------Set up test pack------------------- SetupDefaultContactPersonBO(); // DateTime now = DateTime.Now; const string firstName = "abab"; ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson("zzzz", firstName); ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson("aaaa", firstName); // Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now); const string criteria = "FirstName = '" + firstName + "'"; //---------------Execute Test ---------------------- BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>(); col.Load(criteria, "Surname"); //---------------Test Result ----------------------- Assert.AreEqual(2, col.Count); col.Sort("Surname", true, true); Assert.AreSame(cp2, col[0]); Assert.AreSame(cp1, col[1]); }
private static BusinessObjectCollection<ContactPersonTestBO> CreateCollectionWithTestPack(string firstName, out ContactPersonTestBO cp1, out ContactPersonTestBO cp2, out ContactPersonTestBO cp3) { ContactPersonTestBO.LoadDefaultClassDef(); cp1 = ContactPersonTestBO.CreateSavedContactPerson("zzaaaa", firstName); cp2 = ContactPersonTestBO.CreateSavedContactPerson("aaaa", firstName); cp3 = ContactPersonTestBO.CreateSavedContactPerson("ZZZZZ", "FirstName"); BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>(); col.Load("", "Surname"); col.Sort("Surname", true, true); return col; }
public void Test_Find_ShouldReturnObject() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); // DateTime now = DateTime.Now; const string firstName = "abab"; ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson("zzzz", firstName); ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson("aaaa", firstName); // Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now); const string criteria = "FirstName = '" + firstName + "'"; BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>(); col.Load(criteria, "Surname"); col.Sort("Surname", true, true); //---------------Assert Precondition---------------- Assert.AreEqual(2, col.Count); Assert.AreSame(cp2, col[0], "Collection should be in Surname Asc Order"); Assert.AreSame(cp1, col[1], "Collection should be in Surname Asc Order"); //---------------Execute Test ---------------------- ContactPersonTestBO foundCp = col.Find(bo => bo.Surname == "zzzz"); //---------------Test Result ----------------------- Assert.IsNotNull(foundCp); Assert.AreSame(cp1, foundCp); }
public void Test_Sort_WhenOrderCriteriaSetup_AndCollectionSorted_ShouldNotChangeOrder() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); // DateTime now = DateTime.Now; const string firstName = "abab"; ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson("zzzz", firstName); ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson("aaaa", firstName); // Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now); const string criteria = "FirstName = '" + firstName + "'"; BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>(); col.Load(criteria, "Surname"); col.Sort("Surname", true, true); //---------------Assert Precondition---------------- Assert.AreEqual(2, col.Count); Assert.AreSame(cp2, col[0], "Collection should be in Surname Asc Order"); Assert.AreSame(cp1, col[1], "Collection should be in Surname Asc Order"); //---------------Execute Test ---------------------- col.Sort(); //---------------Test Result ----------------------- Assert.AreEqual(2, col.Count); Assert.AreSame(cp2, col[0], "Collection should b sorted by the Surname Property as per the origional collection.Load"); Assert.AreSame(cp1, col[1]); }
public void Test_Sort_WithoutOrderCriteria_ShouldDoNothing() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); // DateTime now = DateTime.Now; const string firstName = "abab"; ContactPersonTestBO cp1 = ContactPersonTestBO.CreateSavedContactPerson("zzzz", firstName); ContactPersonTestBO cp2 = ContactPersonTestBO.CreateSavedContactPerson("aaaa", firstName); // Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now); const string criteria = "FirstName = '" + firstName + "'"; BusinessObjectCollection<ContactPersonTestBO> col = new BusinessObjectCollection<ContactPersonTestBO>(); col.Load(criteria, ""); col.Sort("Surname", true, false); //---------------Assert Precondition---------------- Assert.AreEqual(2, col.Count); Assert.AreSame(cp1, col[0], "Collection should be in Surname Desc Order"); Assert.AreSame(cp2, col[1], "Collection should be in Surname Desc Order"); //---------------Execute Test ---------------------- col.Sort(); //---------------Test Result ----------------------- Assert.AreEqual(2, col.Count); Assert.AreSame(cp1, col[0], "Collection Should not change the order since no default Sort criteria where set up"); Assert.AreSame(cp2, col[1]); }
public void Test_Sort_WithExpression_AndReflectiveProperty_ShouldSortCollection() { //---------------Set up test pack------------------- ContactPersonTestBO.LoadDefaultClassDef(); // DateTime now = DateTime.Now; const string firstName = "abab"; var cp1 = ContactPersonTestBO.CreateSavedContactPerson("zzzz", firstName); cp1.ReflectiveProp = "ccc"; var cp2 = ContactPersonTestBO.CreateSavedContactPerson("aaaa", firstName); cp2.ReflectiveProp = "bbb"; // Criteria criteria = new Criteria("DateOfBirth", Criteria.ComparisonOp.Equals, now); const string criteria = "FirstName = '" + firstName + "'"; var col = new BusinessObjectCollection<ContactPersonTestBO>(); col.Load(criteria, "Surname DESC"); //---------------Assert Precondition---------------- Assert.AreEqual(2, col.Count); Assert.AreSame(cp1, col[0], "Collection should be in Surname DESC Order"); Assert.AreSame(cp2, col[1], "Collection should be in Surname DESC Order"); //---------------Execute Test ---------------------- col.Sort(contact => contact.ReflectiveProp, false, true); //---------------Test Result ----------------------- Assert.AreEqual(2, col.Count); Assert.AreSame(cp2, col[0], "Collection should be sorted by the ReflectiveProp Property ASC"); Assert.AreSame(cp1, col[1]); }