Inheritance: Habanero.BO.BusinessObjectLookupList
Example #1
0
        private PropDef GetPropDef_Int_WithLookupList()
        {
            PropDef propDef = new PropDef("PropName", typeof(int), PropReadWriteRule.ReadWrite, null);
            BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
                                                                    (typeof(BOWithIntID), _collection_IntId);

            propDef.LookupList = businessObjectLookupList;
            return(propDef);
        }
        public void Test_GetKey_FromLookupList_Sorted()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
                (typeof (MyBO), _collection);
            new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null)
                {LookupList = businessObjectLookupList};
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            Dictionary<string, string> lookupList = businessObjectLookupList.GetLookupList();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, lookupList.Count, "There should be one item in the lookup list");
            Assert.IsTrue(lookupList.ContainsKey(_validLookupValue));
            string objectIDAsString = lookupList[_validLookupValue];
            //Assert.AreEqual(GuidToUpper(_validBusinessObject.ID.GetAsGuid()), objectIDAsString);
            Assert.AreEqual(_validBusinessObject.ID.GetAsGuid().ToString(), objectIDAsString);
        }
 private PropDef GetPropDef_Int_WithLookupList()
 {
     PropDef propDef = new PropDef("PropName", typeof (int), PropReadWriteRule.ReadWrite, null);
     BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
         (typeof (BOWithIntID), _collection_IntId);
     propDef.LookupList = businessObjectLookupList;
     return propDef;
 }
        public void Test_GetValue_FromKeyValueList_Sorted()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
                (typeof (MyBO), _collection, "TestProp");
            new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null)
                {LookupList = businessObjectLookupList};
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            Dictionary<string, string> idValueLookupList = businessObjectLookupList.GetIDValueLookupList();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, idValueLookupList.Count, "There should be one item in the lookup list");
            string guid = _validBusinessObject.ID.GetAsGuid().ToString();
            Assert.IsTrue(idValueLookupList.ContainsKey(guid));
            string returnedValue = idValueLookupList[guid];
            Assert.AreEqual(_validLookupValue, returnedValue);
        }
        public void Test_NoPropDefSet_ThrowsError()
        {
            //---------------Set up test pack-------------------
            MyBO.LoadDefaultClassDef();
            BusinessObjectLookupListStub businessObjectLookupListStub = new BusinessObjectLookupListStub
                (typeof (MyBO), _collection);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            try
            {
                businessObjectLookupListStub.GetLookupList();
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains
                    ("There is an application setup error. There is no propdef set for the business object lookup list.",
                     ex.Message);
            }
            //---------------Test Result -----------------------
        }
 private BOProp GetProp_String_WithLookupList()
 {
     MyBO.LoadDefaultClassDef();
     PropDef propDef = new PropDef("PropName", typeof (string), PropReadWriteRule.ReadWrite, null);
     BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
         (typeof (MyBO), _collection);
     propDef.LookupList = businessObjectLookupList;
     return new BOPropLookupList(propDef);
 }
 public void Test_GetLookupList_LookupList_IncorrectIdentifierType()
 {
     //---------------Set up test pack------------------
     MyBO.LoadDefaultClassDef();
     PropDef propDef = new PropDef("PropName", typeof (int), PropReadWriteRule.ReadWrite, null);
     BusinessObjectLookupListStub businessObjectLookupListStub = new BusinessObjectLookupListStub
         (typeof (MyBO), _collection);
     propDef.LookupList = businessObjectLookupListStub;
     //---------------Assert Precondition----------------
     Assert.IsInstanceOf(typeof (BusinessObjectLookupList), propDef.LookupList);
     //---------------Execute Test ----------------------
     try
     {
         businessObjectLookupListStub.GetLookupList();
         Assert.Fail("expected Err");
     }
         //---------------Test Result -----------------------
     catch (HabaneroDeveloperException ex)
     {
         StringAssert.Contains
             ("There is an application setup error Please contact your system administrator", ex.Message);
         StringAssert.Contains
             ("There is a class definition setup error the business object lookup list has lookup value items that are not of type",
              ex.DeveloperMessage);
         StringAssert.Contains("Int32", ex.DeveloperMessage);
     }
 }
 public void Test_BusinessObjectLookupList_GetValue_Exists()
 {
     //---------------Set up test pack-------------------
     MyBO.LoadDefaultClassDef();
     PropDef propDef = new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null);
     BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
         (typeof (MyBO), _collection);
     propDef.LookupList = businessObjectLookupList;
     Dictionary<string, string> list = businessObjectLookupList.GetIDValueLookupList();
     //---------------Assert Precondition----------------
     Assert.IsInstanceOf(typeof (BusinessObjectLookupList), propDef.LookupList);
     Assert.AreSame(propDef, businessObjectLookupList.PropDef);
     //---------------Execute Test ----------------------
     string returnedValue;
     bool keyReturned = list.TryGetValue(_validBusinessObject.ID.GetAsGuid().ToString(), out returnedValue);
     //---------------Test Result -----------------------
     Assert.IsTrue(keyReturned);
     Assert.AreEqual(_validLookupValue, returnedValue);
 }
 private PropDef GetPropDef_Guid_WithLookupList()
 {
     MyBO.LoadDefaultClassDef();
     PropDef propDef = new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null);
     BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
         (typeof (MyBO), _collection);
     propDef.LookupList = businessObjectLookupList;
     return propDef;
 }
 public void Test_InitialisePropNoDefault_DoesNotLoadLookupList()
 {
     //---------------Set up test pack-------------------
     MyBO.LoadDefaultClassDef();
     PropDef propDef = new PropDef("PropName", typeof(Guid), PropReadWriteRule.ReadWrite, null);
     BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
         (typeof(MyBO), _collection) { PropDef = _propDefGuid };
     propDef.LookupList = businessObjectLookupList;
     BOPropLookupList_Stub prop = new BOPropLookupList_Stub(propDef);
     //---------------Assert Precondition----------------
     Assert.IsInstanceOf(typeof(BusinessObjectLookupListStub), propDef.LookupList);
     Assert.AreNotEqual(0, _collection.Count);
     Assert.IsNull(businessObjectLookupList.DisplayValueDictionary);
     //---------------Execute Test ----------------------
     prop.InitialiseProp(Guid.NewGuid());
     //---------------Test Result -----------------------
     Assert.IsNull(businessObjectLookupList.DisplayValueDictionary);
     Assert.IsFalse(prop.Loading);
 }
 public void Test_BusinessObjectLookupList_GetKey_NotExists()
 {
     //---------------Set up test pack-------------------
     MyBO.LoadDefaultClassDef();
     PropDef propDef = new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null);
     BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
         (typeof (MyBO), _collection);
     propDef.LookupList = businessObjectLookupList;
     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);
 }
 public void Test_SetLookupList_SetsUpKeyLookupList()
 {
     //---------------Set up test pack-------------------
     MyBO.LoadDefaultClassDef();
     PropDef propDef = new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null);
     BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
         (typeof (MyBO), _collection) {PropDef = _propDefGuid};
     //---------------Assert Precondition----------------
     Assert.IsInstanceOf(typeof (NullLookupList), propDef.LookupList);
     Assert.AreEqual(_collection.Count, businessObjectLookupList.GetLookupList().Count);
     //---------------Execute Test ----------------------
     propDef.LookupList = businessObjectLookupList;
     //---------------Test Result -----------------------
     Assert.IsInstanceOf(typeof (BusinessObjectLookupList), propDef.LookupList);
     Assert.AreSame(propDef, businessObjectLookupList.PropDef);
     Assert.AreEqual(_collection.Count, businessObjectLookupList.GetLookupList().Count);
     Assert.AreEqual(_collection.Count, businessObjectLookupList.GetIDValueLookupList().Count);
 }
 public void Test_SimpleLookup_Create_SetsUpKeyLookupList_BO_PrimaryKeyNotSet()
 {
     //---------------Set up test pack-------------------
     OrganisationTestBO.LoadDefaultClassDef_WithSingleRelationship();
     OrganisationTestBO bo = new OrganisationTestBO {OrganisationID = null};
     BusinessObjectCollection<OrganisationTestBO> collectionBO =
         new BusinessObjectCollection<OrganisationTestBO> {bo};
     //---------------Assert Precondition----------------
     Assert.IsNull(bo.ID.GetAsValue());
     //---------------Execute Test ----------------------
     try
     {
         BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
             (typeof (OrganisationTestBO), collectionBO) {PropDef = _propDefGuid};
         businessObjectLookupList.GetIDValueLookupList();
         Assert.Fail("expected Err");
     }
         //---------------Test Result -----------------------
     catch (HabaneroDeveloperException ex)
     {
         string developerMessage = string.Format
             ("A business object of '{0}' is being added to a lookup list for {1} it "
              + "does not have a value for its primary key set", _propDefGuid.PropertyTypeName,
              _propDefGuid.PropertyName);
         StringAssert.Contains(developerMessage, ex.DeveloperMessage);
     }
 }
 public void Test_SimpleLookup_Create_SetsUpKeyLookupList()
 {
     //---------------Set up test pack-------------------
     MyBO.LoadDefaultClassDef();
     //---------------Assert Precondition----------------
     Assert.AreEqual(1, _collection.Count);
     //---------------Execute Test ----------------------
     BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
         (typeof (MyBO), _collection);
     businessObjectLookupList.PropDef = _propDefGuid;
     //---------------Assert Precondition----------------
     Assert.AreEqual(_collection.Count, businessObjectLookupList.GetLookupList().Count);
     Assert.IsNotNull(businessObjectLookupList.GetIDValueLookupList());
     Assert.AreEqual(_collection.Count, businessObjectLookupList.GetIDValueLookupList().Count);
 }
 public void Test_SetLookupListForPropDef()
 {
     //---------------Set up test pack-------------------
     PropDef propDef = new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null);
     BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
         (typeof (MyBO), _collection);
     //---------------Assert Precondition----------------
     Assert.IsInstanceOf(typeof (NullLookupList), propDef.LookupList);
     //---------------Execute Test ----------------------
     propDef.LookupList = businessObjectLookupList;
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDef.LookupList);
     Assert.AreSame(propDef, businessObjectLookupList.PropDef);
 }
 public void Test_CompositeKey_ThrowsError()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO.LoadClassDefWithCompositePrimaryKey();
     BusinessObjectCollection<ContactPersonTestBO> collection =
         new BusinessObjectCollection<ContactPersonTestBO>();
     BusinessObjectLookupList businessObjectLookupList = new BusinessObjectLookupListStub
         (typeof (ContactPersonTestBO), collection);
     new PropDef("PropName", typeof (string), PropReadWriteRule.ReadWrite, null)
         {LookupList = businessObjectLookupList};
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     try
     {
         businessObjectLookupList.GetLookupList();
         Assert.Fail("expected Err");
     }
         //---------------Test Result -----------------------
     catch (HabaneroDeveloperException ex)
     {
         StringAssert.Contains("There is an application setup error", ex.Message);
         StringAssert.Contains
             ("The lookup list cannot contain business objects 'ContactPersonTestBO' with a composite primary key.",
              ex.DeveloperMessage);
     }
 }