public static string Configure() { XmlElement xe = XmlHelpers.RootElement(); StringBuilder sb = new StringBuilder(); var configProcessor = new ConfigProcessor(); configProcessor.ProcessRoot(xe, sb); return sb.ToString(); }
private void RunTest(string configXml) { var sb = new StringBuilder(); XmlElement xe = JSNLog.Tests.Logic.Utils.ConfigToXe(configXml); var configProcessor = new ConfigProcessor(); configProcessor.ProcessRootExec(xe, sb, s => s, "23.89.450.1", "req", true); }
public static string SetupRequestIdTest(string requestId, string configXml) { var sb = new StringBuilder(); XmlElement xe = ConfigToXe(configXml); var configProcessor = new ConfigProcessor(); configProcessor.ProcessRoot(xe, requestId, sb); string js = sb.ToString(); return js; }
/// <summary> /// Returns all javascript to set up a test. /// The generated javascript is within an immediately executing function, so it sits in its own namespace. /// /// </summary> /// <param name="configXml"> /// String with xml with the JSNLog root element, as would be used in a web.config file. /// </param> /// <param name="userIp"> /// Simulated IP address of the client. /// </param> /// <param name="requestId"> /// Simulated request id. /// </param> /// <returns></returns> public static string SetupTest(string userIp, string requestId, string configXml, IEnumerable<T> tests) { var sb = new StringBuilder(); XmlElement xe = ConfigToXe(configXml); var configProcessor = new ConfigProcessor(); configProcessor.ProcessRootExec(xe, sb, s => s, userIp, requestId, false); sb.AppendLine(@"<script type=""text/javascript"">"); sb.AppendLine("(function () {"); int seq = 0; foreach (T t in tests) { if (t.Level > -1) { // Level given, so generate call to logger. string msg = t.LogObject ?? @"""" + Msg(seq, t.Level, t.Logger) + @""""; string logCallJs = string.Format(@"JL(""{0}"").log({1}, {2});", t.Logger, t.Level, msg); string storeTimestampJs = StoreTimestampJs(seq); sb.AppendLine(logCallJs + " " + storeTimestampJs); } if (t.CheckNbr > -1) { // CheckNbr given, so do a check // Create JSON object with all expected log entries string expected = Expected(t.CheckNbr, tests); // Generate check js string checkJs = string.Format("TestUtils.Check({0}, {1}, {2});", t.CheckAppender, t.CheckNbr, expected); sb.AppendLine(""); sb.AppendLine(checkJs); sb.AppendLine("// ----------------------"); sb.AppendLine(""); } if (!string.IsNullOrEmpty(t.Header)) { sb.AppendLine(string.Format("$('body').append('<h3>{0}</h3>');", t.Header)); } seq++; } // Remove the "running" heading. If the tests somehow crash, we won't get here and the running header will remain, // showing something is wrong. sb.AppendLine("$('#running').remove();"); sb.AppendLine("})();"); sb.AppendLine("</script>"); string js = sb.ToString(); return js; }
private void RunTest(string configXml) { var sb = new StringBuilder(); CommonTestHelpers.SetConfigCache(configXml); var configProcessor = new ConfigProcessor(); configProcessor.ProcessRootExec(sb, s => s, "23.89.450.1", "req", true); }