public void SetupTest()
        {
            ClassDef.ClassDefs.Clear();
            this.SetupDBConnection();

            BORegistry.DataAccessor = new DataAccessorDB();
            _propDef_int = new PropDef("PropName", typeof(int), PropReadWriteRule.ReadWrite, null);
            DatabaseLookupList databaseLookupList = new DatabaseLookupList(_sql, 10000, "", "", true);
            _propDef_int.LookupList = databaseLookupList;
            databaseLookupList.GetLookupList();

        }
        public void SetupTestFixture()
        {
            //Code that is executed before any test is run in this class. If multiple tests
            // are executed then it will still only be called once.
            ClassDef.ClassDefs.Clear();
            this.SetupDBConnection();

            BORegistry.DataAccessor = new DataAccessorDB();
            _propDef_guid = new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null);
            DatabaseLookupList databaseLookupList = new DatabaseLookupList(_sql) {PropDef = _propDef_guid};
            databaseLookupList.GetLookupList();
            _propDef_guid.LookupList = databaseLookupList;
        }
        public void Test_SetLookupListForPropDef()
        {
            //---------------Set up test pack-------------------
            PropDef propDef = new PropDef("PropName", typeof (int), PropReadWriteRule.ReadWrite, null);
            DatabaseLookupList databaseLookupList = new DatabaseLookupList(_sql);

            //---------------Assert Precondition----------------
            Assert.IsInstanceOf(typeof (NullLookupList), propDef.LookupList);
            //---------------Execute Test ----------------------
            propDef.LookupList = databaseLookupList;
            //---------------Test Result -----------------------
            Assert.IsNotNull(propDef.LookupList);
            Assert.AreSame(propDef, databaseLookupList.PropDef);
        }
        public void Test_GetKey_FromLookupList()
        {
            //---------------Set up test pack-------------------
            PropDef propDef = new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null);
            DatabaseLookupList databaseLookupList = new DatabaseLookupList(_sql);
            propDef.LookupList = databaseLookupList;
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            Dictionary<string, string> lookupList = databaseLookupList.GetLookupList();

            //---------------Test Result -----------------------
            Assert.AreEqual(2, lookupList.Count, "There should be two item in the lookup list");
            Assert.IsTrue(lookupList.ContainsKey(_validLookupValue));
            string objectIDAsString = lookupList[_validLookupValue];
            Assert.AreEqual(_validID.ToString(), objectIDAsString);
        }
        public void Test_NoPropDefSet_ThrowsError()
        {
            //---------------Set up test pack-------------------
            DatabaseLookupList source = new DatabaseLookupList(Sql);
            
            //---------------Assert Precondition----------------
            
            //---------------Execute Test ----------------------
            try
            {
                source.GetLookupList(conn);
                Assert.Fail("expected Err");
            }
                //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains("There is an application setup error. There is no propdef set for the database lookup list.", ex.Message);
            }
            //---------------Test Result -----------------------

        }
 private static PropDef GetPropDef_WithDatabaseLookupList(out DatabaseLookupList databaseLookupList)
 {
     PropDef propDef = new PropDef("PropName", typeof (int), PropReadWriteRule.ReadWrite, null);
     databaseLookupList = new DatabaseLookupList(_sql);
     propDef.LookupList = databaseLookupList;
     return propDef;
 }
 public void Test_LimitToList_Attribute_Default()
 {
     //---------------Set up test pack-------------------
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     DatabaseLookupList source = new DatabaseLookupList("");
     //---------------Test Result -----------------------
     Assert.IsFalse(source.LimitToList);
 }
        public void Test_Constructor_WithLimitToList_AsFalse()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            DatabaseLookupList source = new DatabaseLookupList("", 10000, null, null, false);

            //---------------Test Result -----------------------
            Assert.IsFalse(source.LimitToList);
        }
        public void Test_SetTimeOut_ShouldUpdateNewTimeOut()
        {
            //---------------Set up test pack-------------------
            DatabaseLookupList source = new DatabaseLookupList(Sql,10000,  null, null, false);
            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 TestLookupListTimeout()
 {
     PropDef propDef = new PropDef("PropName", typeof(Guid), PropReadWriteRule.ReadWrite, null);
     DatabaseLookupList source = new DatabaseLookupList(Sql, 100, null, null, false);
     source.PropDef = propDef;
     Dictionary<string, string> col = source.GetLookupList(conn);
     Thread.Sleep(250);
     Dictionary<string, string> col2 = source.GetLookupList(conn);
     Assert.AreNotSame(col2, col);
 }
 public void TestGetLookupList()
 {
     PropDef propDef = new PropDef("PropName", typeof(Guid), PropReadWriteRule.ReadWrite, null);
     DatabaseLookupList source = new DatabaseLookupList(Sql) {PropDef = propDef};
     Dictionary<string, string> col = source.GetLookupList(conn);
     Assert.AreEqual(3, col.Count);
     string str = "";
     foreach (KeyValuePair<string, string> pair in col)
     {
         if (pair.Value != null && pair.Value.Equals(_guid1.ToString()))
         {
             str = pair.Key;
         }
     }
     Assert.AreEqual("Test1", str);
 }
 public void TestCallingGetLookupListTwiceOnlyAccessesDbOnce()
 {
     PropDef propDef = new PropDef("PropName", typeof(Guid), PropReadWriteRule.ReadWrite, null);
     DatabaseLookupList source = new DatabaseLookupList(Sql);
     source.PropDef = propDef;
     Dictionary<string, string> col = source.GetLookupList(conn);
     Dictionary<string, string> col2 = source.GetLookupList(conn);
     Assert.AreSame(col2, col);
 }
        public void Test_GetValue_FromKeyValueList()
        {
            //---------------Set up test pack-------------------
            PropDef propDef = new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null);
            DatabaseLookupList databaseLookupList = new DatabaseLookupList(_sql);
            propDef.LookupList = databaseLookupList;
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            Dictionary<string, string> idValueLookupList = databaseLookupList.GetIDValueLookupList();

            //---------------Test Result -----------------------
            Assert.AreEqual(2, idValueLookupList.Count, "There should be two item in the lookup list");
            string guidToString = _validID.ToString();
            Assert.IsTrue(idValueLookupList.ContainsKey(guidToString));
            string returnedValue = idValueLookupList[guidToString];
            Assert.AreEqual(_validLookupValue, returnedValue);
        }
 public void TestLookupListTimeout()
 {
     dbConnMock.ExpectAndReturn("LoadDataTable", dt, new object[] {statement, "", ""});
     dbConnMock.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection(),
                                new object[] {});
     PropDef propDef = new PropDef("PropName", typeof(Guid), PropReadWriteRule.ReadWrite, null);
     DatabaseLookupList source = new DatabaseLookupList(Sql, 100, null, null, false);
     source.PropDef = propDef;
     Dictionary<string, string> col = source.GetLookupList(conn);
     Thread.Sleep(250);
     Dictionary<string, string> col2 = source.GetLookupList(conn);
     Assert.AreNotSame(col2, col);
     dbConnMock.Verify();
 }
 private DatabaseLookupList GetDatabaseLookupList()
 {
     DatabaseLookupList databaseLookupList = new DatabaseLookupList(_sql);
     _propDef_guid.LookupList = databaseLookupList;
     return databaseLookupList;
 }
 public void Test_GetIDValueLookupList()
 {
     //---------------Set up test pack-------------------
     PropDef propDef = new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null);
     DatabaseLookupList databaseLookupList = new DatabaseLookupList(_sql);
     propDef.LookupList = databaseLookupList;
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     Dictionary<string, string> idValueLookupList = databaseLookupList.GetIDValueLookupList();
     //---------------Test Result -----------------------
     Assert.IsNotNull(idValueLookupList);
 }
        public void Test_SetLookupList_SetsUpKeyLookupList()
        {
            //---------------Set up test pack------------------

            PropDef propDef = new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null);
            DatabaseLookupList databaseLookupList = new DatabaseLookupList(_sql);
            //---------------Assert Precondition----------------
            Assert.IsInstanceOf(typeof (NullLookupList), propDef.LookupList);
            //---------------Execute Test ----------------------
            propDef.LookupList = databaseLookupList;
            //---------------Test Result -----------------------
            Assert.IsInstanceOf(typeof (DatabaseLookupList), propDef.LookupList);
            Assert.AreSame(propDef, databaseLookupList.PropDef);
            Assert.AreEqual(2, databaseLookupList.GetLookupList().Count);
            Assert.AreEqual(2, databaseLookupList.GetIDValueLookupList().Count);
        }
        public void Test_GetLookupList_LookupListIncorrectType()
        {
            //---------------Set up test pack------------------

            PropDef propDef = new PropDef("PropName", typeof (int), PropReadWriteRule.ReadWrite, null);
            DatabaseLookupList databaseLookupList = new DatabaseLookupList(_sql);
            propDef.LookupList = databaseLookupList;
            //---------------Assert Precondition----------------
            Assert.IsInstanceOf(typeof (DatabaseLookupList), propDef.LookupList);
            //---------------Execute Test ----------------------
            try
            {
                databaseLookupList.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 database lookup list has lookup value items that are not of type",
                     ex.DeveloperMessage);
                StringAssert.Contains("Int32", ex.DeveloperMessage);
            }
        }
 public void Test_BusinessObjectLookupList_GetValue_NotExists()
 {
     //---------------Set up test pack-------------------
     PropDef propDef = GetPropDef_Guid_WithLookupList();
     DatabaseLookupList databaseLookupList = new DatabaseLookupList(_sql);
     propDef.LookupList = databaseLookupList;
     databaseLookupList.GetLookupList();
     Dictionary<string, string> list = databaseLookupList.GetIDValueLookupList();
     //---------------Assert Precondition----------------
     Assert.IsInstanceOf(typeof (DatabaseLookupList), propDef.LookupList);
     Assert.AreSame(propDef, databaseLookupList.PropDef);
     //---------------Execute Test ----------------------
     string returnedValue;
     bool keyReturned = list.TryGetValue(Guid.NewGuid().ToString("N").ToUpperInvariant(), out returnedValue);
     //---------------Test Result -----------------------
     Assert.IsFalse(keyReturned);
     Assert.IsNull(returnedValue);
 }
 public void Test_BusinessObjectLookupList_GetValue_Exists()
 {
     //---------------Set up test pack-------------------
     PropDef propDef = new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null);
     DatabaseLookupList databaseLookupList = new DatabaseLookupList(_sql);
     propDef.LookupList = databaseLookupList;
     databaseLookupList.GetLookupList();
     Dictionary<string, string> list = databaseLookupList.GetIDValueLookupList();
     //---------------Assert Precondition----------------
     Assert.IsInstanceOf(typeof (DatabaseLookupList), propDef.LookupList);
     Assert.AreSame(propDef, databaseLookupList.PropDef);
     //---------------Execute Test ----------------------
     string returnedValue;
     bool keyReturned = list.TryGetValue(_validID.ToString(), out returnedValue);
     //---------------Test Result -----------------------
     Assert.IsTrue(keyReturned);
     Assert.AreEqual(_validLookupValue, returnedValue);
 }
 public void Test_BusinessObjectLookupList_GetKey_NotExists()
 {
     //---------------Set up test pack-------------------
     PropDef propDef = new PropDef("PropName", typeof (Guid), PropReadWriteRule.ReadWrite, null);
     DatabaseLookupList databaseLookupList = new DatabaseLookupList(_sql);
     propDef.LookupList = databaseLookupList;
     Dictionary<string, string> list = databaseLookupList.GetLookupList();
     //---------------Assert Precondition----------------
     Assert.IsInstanceOf(typeof (DatabaseLookupList), propDef.LookupList);
     Assert.AreSame(propDef, databaseLookupList.PropDef);
     //---------------Execute Test ----------------------
     string returnedKey;
     bool keyReturned = list.TryGetValue("InvalidValue", out returnedKey);
     //---------------Test Result -----------------------
     Assert.IsFalse(keyReturned);
     Assert.IsNull(returnedKey);
 }