public void ErrorsSinceTime_FiltersDate() { // ARRANGE var logEntries = new List <LogEntry>(); logEntries.Add(new LogEntry { HostName = "Test", Message = "Test Log Entry 1", LogTime = new DateTime(2015, 2, 1), LogType = Convert.ToInt32(LogType.Error) }); logEntries.Add(new LogEntry { HostName = "Test", Message = "Test Log Entry 2", LogTime = new DateTime(2016, 2, 1), LogType = Convert.ToInt32(LogType.Error) }); logEntries.Add(new LogEntry { HostName = "Test", Message = "Test Log Entry 3", LogTime = new DateTime(2017, 2, 1), LogType = Convert.ToInt32(LogType.Error) }); logEntries.Add(new LogEntry { HostName = "Test", Message = "Test Log Entry 4", LogTime = new DateTime(2017, 2, 1), LogType = Convert.ToInt32(LogType.Error) }); logEntries.Add(new LogEntry { HostName = "Test", Message = "Test Log Entry 5", LogTime = new DateTime(2017, 2, 1), LogType = Convert.ToInt32(LogType.Error) }); _mockContext.LogEntries.AddRange(logEntries); _mockContext.SaveChanges(); // ACT var actualErrorCount = _readService.ErrorsSinceTime(new DateTime(2017, 2, 1)); // ASSERT Assert.AreEqual(3, actualErrorCount); }
internal void WriteLog(LogType logType, string source, Exception exception, string message, string userName) { var logEntry = new LogEntry { LogType = Convert.ToInt32(logType), HostName = Environment.MachineName, Source = source, Message = message, UserName = userName, LogTime = DateTime.Now }; if (exception != null) { var logException = new LogException { LogEntry = logEntry, ExceptionDetail = exception.ToString() }; _context.LogExceptions.Add(logException); } _context.LogEntries.Add(logEntry); _context.SaveChanges(); }