public void Test2()
        {
            // 测试 HTTP 请求执行超时场景
            using (WebContext context = HttpInfoTest.CreateWebContext()) {
                context.SetUserName("fish li");
                // 测试 SQL 执行超时场景

                PerformanceModule module = new PerformanceModule();

                System.Threading.Thread.Sleep(WriterFactory.Config.TimerPeriod + 1000);
                // 暂停异步写入
                SetAsyncWriteEnabled(false);


                TimeSpan  timeSpan = TimeSpan.FromSeconds(2d);
                DbCommand command  = SqlInfoTest.CreateDbCommand();

                // 第一次调用,第一个参数command = null
                PerformanceModule.CheckDbExecuteTime(null, timeSpan);

                // 第二次调用
                PerformanceModule.CheckDbExecuteTime(command, timeSpan);



                // 获取调用 LogHelper.Write(info); 的数据
                List <PerformanceInfo> list = GetQueueData();

                Assert.AreEqual(1, list.Count);

                PerformanceInfo performanceInfo = list[0];
                Assert.AreEqual(command.CommandText, performanceInfo.SqlInfo.SqlText.ToString());

                Assert.IsNotNull(performanceInfo.HttpInfo);
                Assert.AreEqual(context.HttpContext.Request.Url.OriginalString, performanceInfo.HttpInfo.Url);
                Console.WriteLine(performanceInfo.HttpInfo.Url);
                Assert.AreEqual("fish li", performanceInfo.HttpInfo.UserName);

                // 启用异步写入
                SetAsyncWriteEnabled(true);
            }
        }
Exemple #2
0
        public void Test_LogHelper_Write_DbCommand()
        {
            using (WebContext context = HttpInfoTest.CreateWebContext()) {
                context.SetUserName("Fish Li");
                context.AddSession("session-1", "aaaaaaaaaaaa");
                context.AddSession("session-2", DateTime.Now);
                context.AddSession("session-3", null);
                context.Request.SetInputStream("a=1&b=2");

                DbCommand command = SqlInfoTest.CreateDbCommand();


                Exception     ex   = CreateException("Test: HttpInfo.Create");
                ExceptionInfo info = ExceptionInfo.Create(ex, context.HttpContext, command);
                info.Addition = Guid.NewGuid().ToString();

                LogHelper.SyncWrite(info);

                LogHelperTest.AssertWriteOK(info.Addition);

                AssertWriteOK(ex.Message);
            }
        }