Esempio n. 1
0
        public void Test2()
        {
            // 测试 s_initOK 的写入分支,检验方法就是查看代码覆盖率

            FieldInfo field        = typeof(WinLogWriter).GetField("s_initOK", BindingFlags.Static | BindingFlags.NonPublic);
            bool      currentValue = (bool)field.GetValue(null);

            field.SetValue(null, false);

            try {
                Exception ex = LogHelperTest.CreateException();
                //("TestMessage: 顺序拟安排如下:集成专项、建模专项、越秀专项、售楼+公共专项 ");
                ExceptionInfo exInfo = ExceptionInfo.Create(ex);


                WinLogWriter writer = new WinLogWriter();
                writer.Write(exInfo);


                List <ExceptionInfo> list = new List <ExceptionInfo> {
                    exInfo
                };
                writer.Write(list);

                // 不抛出异常就算是通过,所以没有断言
            }
            finally {
                field.SetValue(null, currentValue);
            }
        }
Esempio n. 2
0
        public void Test2()
        {
            // 测试有上传文件时,获取表单数据的逻辑

            using (WebContext context = CreateWebContext()) {
                context.SetUserName("Fish Li");


                Type            httpFileCollectionType = typeof(HttpContext).Assembly.GetType("System.Web.HttpFileCollection");
                ConstructorInfo ctor = httpFileCollectionType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null);
                var             httpFileCollection = ctor.Invoke(null);

                MethodInfo addFileMethod = httpFileCollectionType.GetMethod("AddFile", BindingFlags.Instance | BindingFlags.NonPublic);
                addFileMethod.Invoke(httpFileCollection, new object[] { "file1", null });

                FieldInfo field = typeof(HttpRequest).GetField("_files", BindingFlags.Instance | BindingFlags.NonPublic);
                field.SetValue(context.HttpContext.Request, httpFileCollection);


                context.Request.SetForm("a=1&b=2");


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

                LogHelper.SyncWrite(info);

                LogHelperTest.AssertWriteOK(info.Addition);
            }
        }
Esempio n. 3
0
        private List <ExceptionInfo> WriteList()
        {
            Exception     ex1            = LogHelperTest.CreateException("M1-" + Guid.NewGuid().ToString());
            ExceptionInfo exceptionInfo1 = ExceptionInfo.Create(ex1);

            exceptionInfo1.Addition = "If you liked Fiddler, we also recommend";
            //exceptionInfo1.A1 = "aaaaaaaaaaaa";


            System.Threading.Thread.Sleep(1000);


            Exception     ex2            = LogHelperTest.CreateException("M2-" + Guid.NewGuid().ToString());
            ExceptionInfo exceptionInfo2 = ExceptionInfo.Create(ex2);

            exceptionInfo2.Addition = "Test Studio - Create Automated Tests Quickly";
            //exceptionInfo2.A1 = "aaaaaaaaaaaa";


            MongoDbWriter        writer = new MongoDbWriter();
            List <ExceptionInfo> list1  = new List <ExceptionInfo> {
                exceptionInfo1, exceptionInfo2
            };

            writer.Write(list1);

            System.Threading.Thread.Sleep(1000);

            return(list1);
        }
Esempio n. 4
0
        public void Test_Write()
        {
            Exception     ex             = LogHelperTest.CreateException("M-" + Guid.NewGuid().ToString());
            ExceptionInfo exceptionInfo1 = ExceptionInfo.Create(ex);

            exceptionInfo1.Addition = "If you liked Fiddler, we also recommend";

            MongoDbWriter writer = new MongoDbWriter();

            writer.Write(exceptionInfo1);


            ExceptionInfo exceptionInfo2 = writer.Get <ExceptionInfo>(exceptionInfo1.InfoGuid);

            Assert.AreEqual(exceptionInfo1.Message.ToString(), exceptionInfo2.Message.ToString());
            Assert.AreEqual(exceptionInfo1.Addition.ToString(), exceptionInfo2.Addition.ToString());

            writer.Delete <ExceptionInfo>(exceptionInfo1.InfoGuid);
        }
Esempio n. 5
0
        public void Test1()
        {
            // 正常情况测试

            Exception     ex     = LogHelperTest.CreateException();
            ExceptionInfo exInfo = ExceptionInfo.Create(ex);

            WinLogWriter writer = new WinLogWriter();

            writer.Write(exInfo);



            List <ExceptionInfo> list = new List <ExceptionInfo> {
                exInfo
            };

            writer.Write(list);

            // 不抛出异常就算是通过,所以没有断言
        }
Esempio n. 6
0
        public void Test_ExceptionInfo_Addition()
        {
            // 测试普通情况

            using (WebContext context = 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");


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

                LogHelper.SyncWrite(info);

                LogHelperTest.AssertWriteOK(info.Addition);
            }
        }
Esempio n. 7
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);
            }
        }