public void BulkInsert10TracelogMessageсReceive10recordsTest()
        {
            var traceLogMessages = new List<TraceLogMessage>();
            for (int i = 0; i < 10; i++)
            {
                var traceLogMessage = new TraceLogMessage()
                {
                    Action = "Action",
                    Controller = "Controller",
                    Message = "Test",
                    Status = Status.Ok,
                    TimeStamp = DateTime.Now,
                    UserName = "******"
                };
               
                traceLogMessages.Add(traceLogMessage);
            }
            //act
            tlm.BulkInsert(traceLogMessages);

            dbContext.SaveChanges();

            //assert
            var actualTraceLogMessagesInDataBase = tlm.All().Where(x=>x.Action == "Action").ToList();
            Assert.AreEqual(10, actualTraceLogMessagesInDataBase.Count);
        }
 /// <summary>
 /// Creates the trace log message.
 /// </summary>
 /// <param name="filterContext">The filter context.</param>
 /// <param name="warning">The warning.</param>
 /// <param name="content">The content.</param>
 /// <returns></returns>
 private TraceLogMessage CreateTraceLogMessage(ResultExecutedContext filterContext, Status status, string message = "Ok")
 {
     var controller = filterContext.Controller;
     var traceLogMessage = new TraceLogMessage()
     {
         TimeStamp = DateTime.Now,
         UserName = controller.ControllerContext.RequestContext.HttpContext.User.Identity.Name,
         Controller = controller.ControllerContext.RouteData.Values["controller"].ToString(),
         Action = controller.ControllerContext.RouteData.Values["action"].ToString(),
         Message = message,
         Status = status,
     };
     SaveInTraceLog(filterContext, traceLogMessage);
     return traceLogMessage;
 }
 /// <summary>
 /// Saves the in trace log.
 /// </summary>
 /// <param name="filterContext">The filter context.</param>
 /// <param name="traceLogMessage">The trace log message.</param>
 private void SaveInTraceLog(ResultExecutedContext filterContext, TraceLogMessage traceLogMessage)
 {
     if (traceLogMessage.Status == Status.Ok)
     {
         filterContext.HttpContext.Trace.Write(string.Format("User {0} Controler {1} Action {2} Message{3}", 
             traceLogMessage.UserName,
             traceLogMessage.Controller,
             traceLogMessage.Action,
             traceLogMessage.Message));
     }
     else 
     {
         filterContext.HttpContext.Trace.Warn(string.Format("User {0} Controler {1} Action {2} Message{3}",
             traceLogMessage.UserName,
             traceLogMessage.Controller,
             traceLogMessage.Action,
             traceLogMessage.Message)); 
     }
 }
        public void AddSingleTracelogMessageTest()
        {
            //arrange
            string filename = "TestFileDescription" + DateTime.Today;
            var traceLogMessage = new TraceLogMessage()
                        {
                            Action = "Action",
                            Controller = "Controller",
                            Message = "Test",
                            Status = Status.Ok,
                            TimeStamp = DateTime.Now,
                            UserName = "******"
                        };
            //act

            this.tlm.Add(traceLogMessage);
            dbContext.SaveChanges();

            //assert
            Assert.IsFalse(traceLogMessage.Id == 0);
        }
 public void InsertTracelogMessageRecordWithoutControllerNameThrowExceptionTest()
 {
     //arrange
     var traceLogMessage = new TraceLogMessage()
     {
         Action = "Action",
         Controller = null,
         Message = "Test",
         Status = Status.Ok,
         TimeStamp = DateTime.Now,
         UserName = "******"
     };
     //act
     tlm.Add(traceLogMessage);
     dbContext.SaveChanges();
 }