public void TestSortingByDefault() { BusinessObjectLookupList source = new BusinessObjectLookupList("Habanero.Test.BO", "ContactPersonTestBO"); new PropDef("N", typeof(Guid), PropReadWriteRule.ReadWrite, null) {LookupList = source}; Dictionary<string, string> col = source.GetLookupList(DatabaseConnection.CurrentConnection); ArrayList items = new ArrayList(col.Values); Assert.AreEqual(3, col.Count); AssertCorrectlySortedBusinessObjectInList(items, 0, "abc"); AssertCorrectlySortedBusinessObjectInList(items, 1, "abcd"); AssertCorrectlySortedBusinessObjectInList(items, 2, "zzz"); }
public void Test_Constructor_WithLimitToList_AsFalse() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- BusinessObjectLookupList source = new BusinessObjectLookupList( "Habanero.Test.BO", "ContactPersonTestBO", "", "surname", false); //---------------Test Result ----------------------- Assert.IsFalse(source.LimitToList); }
public void TestSortAttribute() { //---------------Set up test pack------------------- BusinessObjectLookupList source = new BusinessObjectLookupList(typeof(ContactPersonTestBO)); //---------------Assert Precondition---------------- Assert.IsNull(source.OrderCriteria); //---------------Execute Test ---------------------- source = new BusinessObjectLookupList("Habanero.Test.BO", "ContactPersonTestBO", "", "surname"); //---------------Test Result ----------------------- Assert.AreEqual(1, source.OrderCriteria.Fields.Count); IOrderCriteriaField orderOrderCriteriaField = source.OrderCriteria.Fields[0]; Assert.AreEqual("surname", orderOrderCriteriaField.PropertyName); Assert.AreEqual(SortDirection.Ascending, orderOrderCriteriaField.SortDirection); Assert.AreEqual("ContactPersonTestBO", orderOrderCriteriaField.Source.Name); }
public void Test_GetLookupList_WhenTimeoutExpired_ShouldReloadList() { BusinessObjectLookupList source = new BusinessObjectLookupList(typeof(ContactPersonTestBO), 100); source.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null); Dictionary<string, string> col = source.GetLookupList(DatabaseConnection.CurrentConnection); Thread.Sleep(250); Dictionary<string, string> col2 = source.GetLookupList(DatabaseConnection.CurrentConnection); Assert.AreNotSame(col2, col); }
public void Test_Constructor_WithLimitToList_Timeout() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- BusinessObjectLookupList source = new BusinessObjectLookupList( "Habanero.Test.BO", "ContactPersonTestBO", "", "surname", 55000); //---------------Test Result ----------------------- Assert.AreEqual(55000, source.TimeOut); }
public void Test_GetValueCollection_When3Items_AndOrderCriteriaIsNull_ShouldReturnAValueListCollectionForTheBusinessObjects() { //---------------Set up test pack------------------- SetupDataAccessor();//Clear any other loaded data (See Test Setup) new ContactPersonTestBO { Surname = "zzz" }.Save(); new ContactPersonTestBO { Surname = "abc" }.Save(); new ContactPersonTestBO { Surname = "abcd" }.Save(); var lookupList = new BusinessObjectLookupList(typeof(ContactPersonTestBO)); //---------------Assert Precondition---------------- Assert.IsNull(lookupList.OrderCriteria); //---------------Execute Test ---------------------- var valueCollection = lookupList.GetValueCollection(); //---------------Test Result ----------------------- Assert.IsInstanceOf<SortedStringCollection>(valueCollection); Assert.AreEqual(3, valueCollection.Count); }
public void Test_GetIDValueLookupList_WhenTimeOutHasNotExpired_ShouldNotReload() { //---------------Set up test pack------------------- BusinessObjectLookupList source = new BusinessObjectLookupList(typeof(ContactPersonTestBO)); source.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null); const int timeout = 200000; source.TimeOut = timeout; Dictionary<string, string> col = source.GetIDValueLookupList(); //---------------Assert Precondition---------------- Assert.AreEqual(timeout, source.TimeOut); Assert.IsNotNull(col); //---------------Execute Test ---------------------- Dictionary<string, string> col2 = source.GetIDValueLookupList(); //---------------Test Result ----------------------- Assert.AreSame(col, col2, "Both collections should be the same since the timeout has not been reached"); }
public void TestNowDateStringCriteria() { DeleteAllContactPeople(); BusinessObjectCollection<ContactPersonTestBO> myCol = new BusinessObjectCollection<ContactPersonTestBO>(); myCol.LoadAll(); Assert.AreEqual(0, myCol.Count); ContactPersonTestBO contactPerson1 = new ContactPersonTestBO(); contactPerson1.Surname = "aaa"; contactPerson1.DateOfBirth = DateTime.Now.AddMinutes(-1); contactPerson1.Save(); ContactPersonTestBO contactPerson2 = new ContactPersonTestBO(); contactPerson2.Surname = "bbb"; contactPerson2.DateOfBirth = DateTime.Now.AddMinutes(-1); contactPerson2.Save(); ContactPersonTestBO contactPerson3 = new ContactPersonTestBO(); contactPerson3.Surname = "ccc"; contactPerson3.DateOfBirth = DateTime.Now.AddMinutes(-1); contactPerson3.Save(); //ContactPersonTestBO.ClearObjectManager(); BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO", "ContactPersonTestBO", "DateOfBirth < 'Now'", ""); businessObjectLookupList.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null); Dictionary<string, string> col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection); Assert.AreEqual(3, col.Count); Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson1.ID.GetAsGuid()))); Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson2.ID.GetAsGuid()))); Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson3.ID.GetAsGuid()))); businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO", "ContactPersonTestBO", "DateOfBirth > 'now'", "") { PropDef = new PropDef ("name", typeof (string), PropReadWriteRule.ReadWrite, null) }; col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection); Assert.AreEqual(0, col.Count); ContactPersonTestBO contactPerson4 = new ContactPersonTestBO(); contactPerson4.Surname = "ddd"; contactPerson4.DateOfBirth = DateTime.Now.AddMinutes(5); contactPerson4.Save(); businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO", "ContactPersonTestBO", "DateOfBirth > NOW", ""); businessObjectLookupList.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null); col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection); Assert.AreEqual(1, col.Count); Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson4.ID.GetAsGuid()))); }
public void Test_LimitToList_Attribute_Default() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- BusinessObjectLookupList source = new BusinessObjectLookupList(typeof(ContactPersonTestBO)); //---------------Test Result ----------------------- Assert.IsFalse(source.LimitToList); }
public void TestCriteria() { BusinessObjectLookupList source = new BusinessObjectLookupList("Habanero.Test.BO", "ContactPersonTestBO", "Surname='zzz'", ""); source.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null); Dictionary<string, string> col = source.GetLookupList(DatabaseConnection.CurrentConnection); Assert.AreEqual(1, col.Count); }
public void TestTodayDateStringCriteria_GreaterThanOrEqualTo() { //-------------Setup Test Pack ------------------ DeleteAllContactPeople(); BusinessObjectCollection<ContactPersonTestBO> myCol = new BusinessObjectCollection<ContactPersonTestBO>(); myCol.LoadAll(); DateTime today = DateTime.Today; ContactPersonTestBO.CreateSavedContactPerson(today.AddDays(-1), "aaa"); ContactPersonTestBO.CreateSavedContactPerson(today, "bbb"); ContactPersonTestBO contactPerson3 = ContactPersonTestBO.CreateSavedContactPerson(today.AddDays(1), "ccc"); //ContactPersonTestBO.ClearObjectManager(); BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupList("Habanero.Test.BO", "ContactPersonTestBO", "DateOfBirth > 'TODAY'", ""); businessObjectLookupList.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null); //-------------Test Pre-conditions -------------- Assert.AreEqual(0, myCol.Count); //-------------Execute test --------------------- Dictionary<string, string> col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection); //-------------Test Result ---------------------- Assert.AreEqual(1, col.Count); Assert.IsTrue(col.ContainsValue(GuidToString(contactPerson3.ID.GetAsGuid()))); }
public void TestCallingGetLookupListTwiceOnlyAccessesDbOnce() { BusinessObjectLookupList source = new BusinessObjectLookupList(typeof(ContactPersonTestBO)); source.PropDef = new PropDef("name", typeof(string), PropReadWriteRule.ReadWrite, null); Dictionary<string, string> col = source.GetLookupList(DatabaseConnection.CurrentConnection); Dictionary<string, string> col2 = source.GetLookupList(DatabaseConnection.CurrentConnection); Assert.AreSame(col2, col); }
public void TestGetLookupList() { BusinessObjectLookupList source = new BusinessObjectLookupList(typeof (ContactPersonTestBO)); source.PropDef = new PropDef("name", typeof (string), PropReadWriteRule.ReadWrite, null); Dictionary<string, string> col = source.GetLookupList(DatabaseConnection.CurrentConnection); Assert.AreEqual(3, col.Count); foreach (string o in col.Values) { Assert.AreSame(typeof(string), o.GetType()); Guid parsedGuid; Assert.IsTrue(StringUtilities.GuidTryParse(o, out parsedGuid)); } }
public void Test_GetValueCollection_When3Items_AndCriteriaIsNotNull_ShouldStillReturnAllBusinessObjects() { //---------------Set up test pack------------------- SetupDataAccessor();//Clear any other loaded data (See Test Setup) new ContactPersonTestBO { Surname = "zzz" }.Save(); new ContactPersonTestBO { Surname = "abc" }.Save(); new ContactPersonTestBO { Surname = "abcd" }.Save(); var lookupList = new BusinessObjectLookupList(typeof(ContactPersonTestBO), "Surname like 'abc'", "Surname", true); //---------------Assert Precondition---------------- Assert.IsNotNull(lookupList.OrderCriteria); //---------------Execute Test ---------------------- var valueCollection = lookupList.GetValueCollection() as ArrayList; //---------------Test Result ----------------------- Assert.IsNotNull(valueCollection); Assert.AreEqual(3, valueCollection.Count); Assert.AreEqual("abc", valueCollection[0]); Assert.AreEqual("abcd", valueCollection[1]); Assert.AreEqual("zzz", valueCollection[2]); }
private static BusinessObjectLookupList GetBusinessObjectLookupListForContactPerson(string sortCriteria) { BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupList( "Habanero.Test.BO", "ContactPersonTestBO", "", sortCriteria); new PropDef("N", typeof(Guid), PropReadWriteRule.ReadWrite, null) { LookupList = businessObjectLookupList }; return businessObjectLookupList; }
public void Test_SetTimeOut_ShouldUpdateNewTimeOut() { //---------------Set up test pack------------------- BusinessObjectLookupList source = new BusinessObjectLookupList(typeof(ContactPersonTestBO)); const int expectedTimeout = 200000; //---------------Assert Precondition---------------- Assert.AreEqual(10000, source.TimeOut); //---------------Execute Test ---------------------- source.TimeOut = expectedTimeout; //---------------Test Result ----------------------- Assert.AreEqual(expectedTimeout, source.TimeOut); }
public void Test_GetLookupList_WhenSubType_AndIDDeclaredOnTheParent_ShouldLoad_FixBug867() { //---------------Set up test pack------------------- BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupList(typeof(SubClass)); new PropDef("N", typeof(Guid), PropReadWriteRule.ReadWrite, null) { LookupList = businessObjectLookupList }; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var lookupList = businessObjectLookupList.GetLookupList(false); //---------------Test Result ----------------------- Assert.IsNotNull(lookupList); }
public void Test_GetValueCollection_WhenNoBOs_ShouldReturnEmptyCollection() { //---------------Set up test pack------------------- SetupDataAccessor();//Clear any other loaded data (See Test Setup) var lookupList = new BusinessObjectLookupList(typeof(ContactPersonTestBO)); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var valueCollection = lookupList.GetValueCollection(); //---------------Test Result ----------------------- Assert.AreEqual(0, valueCollection.Count); }