public void SerializerTest() { HTMLSerializer target = new HTMLSerializer(); HttpRequest request = new HttpRequest("~/", "http://localhost/test/appinternals/FeatureContingencies/centrallogging", "action=view"); HttpResponse response = new HttpResponse(new StringWriter()); HttpContext.Current = new HttpContext(request, response); Arch.CFramework.AppInternals.Configuration.Bean.ConfigBeanBase configBean = null; Encoding encode = null; string expected = string.Empty; string actual; //序列化不存在Bean 抛出异常 bool ret = false; try { actual = target.Serializer(configBean, encode); } catch (Exception) { ret = true; } Assert.IsTrue(ret); //序列化实例Bean AppSettingsBean appsettingsBean = new AppSettingsBean(); actual = target.Serializer(appsettingsBean, encode); Assert.AreNotEqual(expected, actual); actual = target.Serializer(MenusContainer.Current.GetMenus(), encode); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); actual = target.Serializer(ConfigManager.Current.GetConfigCollection(), encode); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); actual = target.Serializer(new BuildInfo(), encode); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); request = new HttpRequest("~/", "http://localhost/test/appinternals/locallog/applog", "action=view"); FeatureContingency.FeatureContingencyManager.Current.GetFCS(); HttpContext.Current = new HttpContext(request, response); actual = target.Serializer(LocalLogManager.Current.GetLogs(), encode); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); request = new HttpRequest("~/", "http://localhost/test/appinternals/fcs", ""); FeatureContingency.FeatureContingencyManager.Current.GetFCS(); HttpContext.Current = new HttpContext(request, response); actual = FeatureContingency.FeatureContingencyManager.Current.GetFeatureContingencies(new HTMLSerializer()); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); var fc = FeatureContingency.FeatureContingencyManager.Current.FeatureContingency("centrallogging"); actual = fc.Read(new HTMLSerializer()); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); }
public void SerializerTest() { HTMLSerializer target = new HTMLSerializer(); // TODO: Initialize to an appropriate value Arch.CFramework.ConfigBean.Bean.ConfigBean configBean = null; // TODO: Initialize to an appropriate value Encoding encode = null; // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value string actual; //序列化实例Bean AppSettingsBean appsettingsBean = new AppSettingsBean(); actual = target.Serializer(appsettingsBean, encode); Assert.AreNotEqual(expected, actual); //序列化不存在Bean actual = target.Serializer(configBean, encode); Assert.AreEqual(expected, actual); }
public void DoComponetsContentTest() { AppInernalsManager_Accessor target = new AppInernalsManager_Accessor(); string name = "buildinfo"; string actual; //HttpRequest request = new HttpRequest("~/", "http://localhost/test/appinternals/components/buildinfo", ""); //HttpResponse response = new HttpResponse(new StringWriter()); //HttpContext context = new HttpContext(request, response); Thread.GetDomain().SetData(".appPath", AppDomain.CurrentDomain.BaseDirectory); Thread.GetDomain().SetData(".appVPath", "/"); Thread.GetDomain().SetData(".appDomain", "*"); TextWriter tw = new StringWriter(); TestWorkerRequest wr = new TestWorkerRequest("/test/appinternals/components/buildinfo", "", tw); wr.SetRemoteAddress("127.0.0.1"); HttpContext.Current = new HttpContext(wr); ISerializer serializer = new JSONSerializer(); actual = target.DoComponetsContent(name, serializer); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); serializer = new HTMLSerializer(); actual = target.DoComponetsContent(name, serializer); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); serializer = new XMLSerializer(); actual = target.DoComponetsContent(name, serializer); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); }
public void GetContextTest() { AppInernalsManager_Accessor target = new AppInernalsManager_Accessor(); // TODO: Initialize to an appropriate value string menu = string.Empty; // TODO: Initialize to an appropriate value ISerializer serializer = new HTMLSerializer(); // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value HttpRequest request = new HttpRequest("~/", "http://localhost/test/appinternals/configurations/beans/appsettingsbean", "action=view"); //HttpResponse response = new HttpResponse(new StringWriter()); //HttpContext context = new HttpContext(request, response); //HttpContext.Current = context; Thread.GetDomain().SetData(".appPath", AppDomain.CurrentDomain.BaseDirectory); Thread.GetDomain().SetData(".appVPath", "/"); Thread.GetDomain().SetData(".appDomain", "*"); TextWriter tw = new StringWriter(); TestWorkerRequest wr = new TestWorkerRequest("/test/appinternals/configurations/beans/appsettingsbean", "action=view", tw); wr.SetRemoteAddress("127.0.0.1"); HttpContext.Current = new HttpContext(wr); string actual; actual = target.GetContext(menu, serializer); Assert.AreNotEqual(expected, actual); }
public void DoDefaultTest() { AppInernalsManager_Accessor target = new AppInernalsManager_Accessor(); // TODO: Initialize to an appropriate value ISerializer serializer = new HTMLSerializer(); //HttpRequest request = new HttpRequest("~/", "http://localhost/test/appinternals/configurations/beans/appsettingsbean", "action=view"); //HttpResponse response = new HttpResponse(new StringWriter()); //HttpContext context = new HttpContext(request, response); //HttpContext.Current = context; Thread.GetDomain().SetData(".appPath", AppDomain.CurrentDomain.BaseDirectory); Thread.GetDomain().SetData(".appVPath", "/"); Thread.GetDomain().SetData(".appDomain", "*"); TextWriter tw = new StringWriter(); TestWorkerRequest wr = new TestWorkerRequest("/test/appinternals/configurations/beans/appsettingsbean", "action=view", tw); wr.SetRemoteAddress("127.0.0.1"); HttpContext.Current = new HttpContext(wr); string actual; actual = target.DoDefault(serializer); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); serializer = new JSONSerializer(); actual = target.DoDefault(serializer); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); }
/// <summary> /// 得到序列化器 /// </summary> /// <param name="request">HttpRequest</param> /// <returns>序列化器</returns> private ISerializer GetSerializer(HttpRequest request) { string serType = (request.QueryString[AppConst.QueryFormat] ?? string.Empty).ToLowerInvariant(); ISerializer serializer; if (!formatStr.Contains(serType) && string.IsNullOrEmpty(request.UserAgent)) serType = "json"; switch (serType) { case "xml": serializer = new XMLSerializer(); break; case "json": serializer = new JSONSerializer(); break; case "text": serializer = new TextSerializer(); break; default: serializer = new HTMLSerializer(); break; } return serializer; }
public void DoComponetsContentTest() { AppInernalsManager_Accessor target = new AppInernalsManager_Accessor(); string name = "buildinfo"; string actual; HttpRequest request = new HttpRequest("~/", "http://localhost/test/appinternals/components/buildinfo", ""); HttpResponse response = new HttpResponse(new StringWriter()); HttpContext context = new HttpContext(request, response); HttpContext.Current = context; ISerializer serializer = new JSONSerializer(); actual = target.DoComponetsContent(name, serializer); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); serializer = new HTMLSerializer(); actual = target.DoComponetsContent(name, serializer); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); serializer = new XMLSerializer(); actual = target.DoComponetsContent(name, serializer); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); }
public void GetContextTest() { AppInernalsManager_Accessor target = new AppInernalsManager_Accessor(); // TODO: Initialize to an appropriate value string menu = string.Empty; // TODO: Initialize to an appropriate value ISerializer serializer = new HTMLSerializer(); // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value HttpRequest request = new HttpRequest("~/", "http://localhost/test/appinternals/configurations/beans/appsettingsbean", "action=view"); HttpResponse response = new HttpResponse(new StringWriter()); HttpContext context = new HttpContext(request, response); HttpContext.Current = context; string actual; actual = target.GetContext(menu, serializer); Assert.AreNotEqual(expected, actual); }
public void DoDefaultTest() { AppInernalsManager_Accessor target = new AppInernalsManager_Accessor(); // TODO: Initialize to an appropriate value ISerializer serializer = new HTMLSerializer(); HttpRequest request = new HttpRequest("~/", "http://localhost/test/appinternals/configurations/beans/appsettingsbean", "action=view"); HttpResponse response = new HttpResponse(new StringWriter()); HttpContext context = new HttpContext(request, response); HttpContext.Current = context; string actual; actual = target.DoDefault(serializer); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); serializer = new JSONSerializer(); actual = target.DoDefault(serializer); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); }