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); } }
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); } }
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); } }