Exemple #1
0
        public List <Type> GetTypes()
        {
            List <Type> typeList = new List <Type>();

            try
            {
                List <TypeDataModel> resultList = _databaseConnection.GetTypesFromDatabase();
                foreach (TypeDataModel typeData in resultList)
                {
                    typeList.Add(new Type(typeData.TypeNr, typeData.Name));
                }
            }
            catch (SqlException e)
            {
                ExceptionCore.HandleException(ExceptionCategory.Fatal, e);
            }
            catch (InvalidCastException e)
            {
                ExceptionCore.HandleException(ExceptionCategory.High, e);
            }
            catch (Exception e)
            {
                ExceptionCore.HandleException(ExceptionCategory.Normal, e);
            }
            return(typeList);
        }
        public void TestGetTypesFromDatabase()
        {
            List <TypeDataModel> typesActual = databaseConnection.GetTypesFromDatabase();

            List <TypeDataModel> typesExpected = new List <TypeDataModel>()
            {
                new TypeDataModel(1, "Server"), new TypeDataModel(2, "Switch")
            };

            if (typesActual.Count == 2)
            {
                for (int i = 0; i < typesActual.Count; i++)
                {
                    Assert.AreEqual(typesActual[i].TypeNr, typesExpected[i].TypeNr);
                    Assert.AreEqual(typesActual[i].Name, typesExpected[i].Name);
                }
            }
            else
            {
                Assert.IsTrue(false);
            }
        }