public void Test_CreateDisplayValueDictionary_WhenThreeBOsWithSameToString_WhenOrdered_ShouldAddIncrementedNumberToToString()
            {
                //---------------Set up test pack-------------------
                //---------NNB person.ToString returns the Surname.-----------------
                var person = new ContactPersonTestBO {
                    Surname = "A"
                };
                var person2 = new ContactPersonTestBO {
                    Surname = "A"
                };
                var person3 = new ContactPersonTestBO {
                    Surname = "A"
                };
                var col = new BusinessObjectCollection <ContactPersonTestBO> {
                    person, person2, person3
                };

                //---------------Assert Precondition----------------
                Assert.AreEqual(3, col.Count);
                //---------------Execute Test ----------------------
                var displayValueDictionary = BusinessObjectLookupList.CreateDisplayValueDictionary(col, true, Convert.ToString);

                //---------------Test Result -----------------------
                Assert.AreEqual(3, displayValueDictionary.Count);
                Assert.Contains("A", displayValueDictionary.Keys, "The first person in the list returns its ToString");
                Assert.Contains("A(2)", displayValueDictionary.Keys, "The second person in the list returns its ToString plus 2");
                Assert.Contains("A(3)", displayValueDictionary.Keys, "The third person in the list returns its ToString plus 3");
            }
            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]);
            }
            public void Test_CreateDisplayValueDictionary_WhenTwoBOsWithSameToString_ShouldIncrementANumber()
            {
                //---------------Set up test pack-------------------
                var person = new ContactPersonTestBO {
                    Surname = "A"
                };
                var person2 = new ContactPersonTestBO {
                    Surname = "A"
                };
                var col = new BusinessObjectCollection <ContactPersonTestBO> {
                    person, person2
                };

                //---------------Assert Precondition----------------
                Assert.AreEqual(2, col.Count);
                //---------------Execute Test ----------------------
                var displayValueDictionary = BusinessObjectLookupList.CreateDisplayValueDictionary(col, false, Convert.ToString);

                //---------------Test Result -----------------------
                Assert.AreEqual(2, displayValueDictionary.Count);
                var key1 = displayValueDictionary.Keys.FirstOrDefault();
                var key2 = displayValueDictionary.Keys.LastOrDefault();

                Assert.AreEqual("A", key1.ToString());
                Assert.AreEqual("A(2)", key2.ToString());
            }
        public void Test_CreateDisplayValueDictionary_NoSort()
        {
            //--------------- Set up test pack ------------------
            ClassDef.ClassDefs.Clear();
            MyBO.LoadDefaultClassDef();
            MyBO.DeleteAllMyBos();
            FixtureEnvironment.ClearBusinessObjectManager();
            TestUtil.WaitForGC();
            MyBO myBO1 = new MyBO();

            myBO1.Save();
            MyBO myBO2 = new MyBO();

            myBO2.Save();
            MyBO myBO3 = new MyBO();

            myBO3.Save();
            BusinessObjectCollection <MyBO> myBOs = new BusinessObjectCollection <MyBO>();

            myBOs.LoadAll();
            //--------------- Test Preconditions ----------------

            //--------------- Execute Test ----------------------
            Dictionary <string, string> dictionary = BusinessObjectLookupList.CreateDisplayValueDictionary(myBOs, false, Convert.ToString);

            //--------------- Test Result -----------------------
            Assert.AreEqual(3, dictionary.Count);
            Assert.IsTrue(dictionary.ContainsValue(myBO1.ID.ToString()));
            Assert.IsTrue(dictionary.ContainsValue(myBO2.ID.ToString()));
            Assert.IsTrue(dictionary.ContainsValue(myBO3.ID.ToString()));
        }
        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 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 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 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 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);
        }
        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 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_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 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_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_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);
            }
        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 TestSortingCollection_Descending()
        {
            //---------------Set up test pack-------------------
            BusinessObjectLookupList businessObjectLookupList =
                GetBusinessObjectLookupListForContactPerson("surname desc");
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            Dictionary <string, string> col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection);
            //---------------Test Result -----------------------
            ArrayList items = new ArrayList(col.Values);

            Assert.AreEqual(3, col.Count);
            AssertCorrectlySortedBusinessObjectInList(items, 0, "zzz");
            AssertCorrectlySortedBusinessObjectInList(items, 1, "abcd");
            AssertCorrectlySortedBusinessObjectInList(items, 2, "abc");
        }
        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_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);
            }
Ejemplo n.º 20
0
        public void Test_BusinessObjectLookupList_GetKey_NotExists_Int()
        {
            //---------------Set up test pack-------------------
            PropDef propDef = GetPropDef_Int_WithLookupList();
            BusinessObjectLookupList    businessObjectLookupList = (BusinessObjectLookupList)propDef.LookupList;
            Dictionary <string, string> list = businessObjectLookupList.GetLookupList();

            //---------------Assert Precondition----------------
            Assert.IsInstanceOf(typeof(BusinessObjectLookupList), propDef.LookupList);
            Assert.AreSame(propDef, businessObjectLookupList.PropDef);
            //---------------Execute Test ----------------------
            string returnedKey;
            bool   keyReturned = list.TryGetValue("InvalidValue", out returnedKey);

            //---------------Test Result -----------------------
            Assert.IsFalse(keyReturned);
            Assert.IsNull(returnedKey);
        }
Ejemplo n.º 21
0
        public void Test_BusinessObjectLookupList_GetKey_Exists_Int()
        {
            //---------------Set up test pack-------------------
            PropDef propDef = GetPropDef_Int_WithLookupList();
            BusinessObjectLookupList    businessObjectLookupList = (BusinessObjectLookupList)propDef.LookupList;
            Dictionary <string, string> list = businessObjectLookupList.GetLookupList();

            //---------------Assert Precondition----------------
            Assert.IsInstanceOf(typeof(BusinessObjectLookupList), propDef.LookupList);
            Assert.AreSame(propDef, businessObjectLookupList.PropDef);
            //---------------Execute Test ----------------------
            string returnedKey;
            bool   keyReturned = list.TryGetValue(_validLookupValue, out returnedKey);

            //---------------Test Result -----------------------
            Assert.IsTrue(keyReturned);
            Assert.AreEqual(_validBusinessObject.ID.GetAsValue().ToString(), returnedKey);
        }
        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_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 TestSortingCollection_PropOnlySpecified()
        {
            //---------------Set up test pack-------------------
            BusinessObjectLookupList businessObjectLookupList =
                GetBusinessObjectLookupListForContactPerson("surname");
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Dictionary <string, string> col = businessObjectLookupList.GetLookupList(DatabaseConnection.CurrentConnection);
            //---------------Test Result -----------------------
            ArrayList items = new ArrayList(col.Values);

            Assert.AreEqual(3, col.Count);
            object          item           = items[0];
            IBusinessObject businessObject = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectByValue(typeof(ContactPersonTestBO), item);

            Assert.AreEqual("abc", businessObject.ToString());
            AssertCorrectlySortedBusinessObjectInList(items, 0, "abc");
            AssertCorrectlySortedBusinessObjectInList(items, 1, "abcd");
            AssertCorrectlySortedBusinessObjectInList(items, 2, "zzz");
        }
        public void Test_CreateDisplayValueDictionary_WhenToStringIsNull_ShouldNotRaiseError()
        {
            //--------------- Set up test pack ------------------
            MyBO.LoadDefaultClassDef();
            MyBO.DeleteAllMyBos();
            FixtureEnvironment.ClearBusinessObjectManager();
            TestUtil.WaitForGC();
            MyBO myBO1 = new MyBO();

            myBO1.SetToString(null);
            BusinessObjectCollection <MyBO> myBOs = new BusinessObjectCollection <MyBO> {
                myBO1
            };

            //--------------- Test Preconditions ----------------
            Assert.IsNull(myBO1.ToString());
            //--------------- Execute Test ----------------------
            Dictionary <string, string> dictionary = BusinessObjectLookupList.CreateDisplayValueDictionary(myBOs, false, Convert.ToString);

            //--------------- Test Result -----------------------
            Assert.AreEqual(1, dictionary.Count);
        }
        public override object GenerateValidValue()
        {
            var lookupList         = base.SingleValueDef.LookupList;
            var generateValidValue = GetLookupListValue(lookupList);

            if (generateValidValue == null && lookupList is BusinessObjectLookupList)
            {
                BusinessObjectLookupList boLList = (BusinessObjectLookupList)lookupList;
                var             boTestFactory    = BOTestFactoryRegistry.Instance.Resolve(boLList.BoType);
                IBusinessObject businessObject   = boTestFactory.CreateSavedBusinessObject();
                generateValidValue = businessObject.ID.GetAsValue();
            }
            object   value;
            IPropDef propDef = this.SingleValueDef as IPropDef;

            if (propDef == null)
            {
                return(generateValidValue);
            }
            var tryParsePropValue = propDef.TryParsePropValue(generateValidValue, out value);

            return(tryParsePropValue? value: generateValidValue);
        }
            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);
            }
Ejemplo n.º 28
0
 protected virtual Dictionary <string, object> GetBusinessObjectDisplayValueDictionary()
 {
     return(BusinessObjectLookupList.CreateDisplayValueDictionary(_businessObjectCollection, false));
 }