Exemple #1
0
        public List <Event> GetAllEvents()
        {
            List <Event> eventList = new List <Event>();

            try
            {
                List <EventDataModel> resultList = _databaseConnection.GetAllEventsFromDatabase();
                foreach (EventDataModel eventData in resultList)
                {
                    eventList.Add(new Event(eventData.EventNr, eventData.ExceptionType, eventData.Category, eventData.EventTimestamp, eventData.HResult, eventData.Message, eventData.Stacktrace));
                }
            }
            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(eventList);
        }
        public void TestAddAndGetEventFromDatabase()
        {
            List <EventDataModel> eventsBeforeAdd = databaseConnection.GetAllEventsFromDatabase();

            databaseConnection.AddEventToDatabase("FormatException", "HIGH", Convert.ToDateTime("07.05.2015 10:10:10"), "2", "Nice try", "Stacktrace");

            List <EventDataModel> eventsAfterAdd = databaseConnection.GetAllEventsFromDatabase();

            int lastIndex = 0;

            // Check added Event
            Assert.AreEqual("FormatException", eventsAfterAdd[lastIndex].ExceptionType);
            Assert.AreEqual("HIGH", eventsAfterAdd[lastIndex].Category);
            Assert.AreEqual("07.05.2015 10:10:10", eventsAfterAdd[lastIndex].EventTimestamp.ToString());
            Assert.AreEqual(2, eventsAfterAdd[lastIndex].HResult);
            Assert.AreEqual("Nice try", eventsAfterAdd[lastIndex].Message);
            Assert.AreEqual("Stacktrace", eventsAfterAdd[lastIndex].Stacktrace);
        }