public void SetConfigWithJsnlogInWebConfig() { // Arrange string configXml = @" <jsnlog maxMessages=""5""> </jsnlog> "; XmlElement xe = CommonTestHelpers.ConfigToXe(configXml); JsnlogConfiguration jsnlogConfiguration = new JsnlogConfiguration(); // Act Exception ex = Assert.Throws <ConflictingConfigException>(() => JavascriptLogging.SetJsnlogConfiguration(() => xe, jsnlogConfiguration)); }
private void RunTest(string configXml, string json, string requestId, string userAgent, string userHostAddress, DateTime serverSideTimeUtc, string url, IEnumerable <LogData> expected) { XmlElement xe = CommonTestHelpers.ConfigToXe(configXml); // Act var jsnlogConfiguration = XmlHelpers.DeserialiseXml <JsnlogConfiguration>(xe); List <FinalLogData> actual = LoggerProcessor.ProcessLogRequestExec( json, new LogRequestBase(userAgent, userHostAddress, requestId, url, null, null, null), serverSideTimeUtc, jsnlogConfiguration); TestLogDatasEqual(expected, actual, serverSideTimeUtc); }
public void GetConfigFromWebConfig() { // Arrange string configXml = @" <jsnlog maxMessages=""5""> </jsnlog> "; XmlElement xe = CommonTestHelpers.ConfigToXe(configXml); JavascriptLogging.SetJsnlogConfiguration(null); JavascriptLogging.GetJsnlogConfiguration(() => xe); // Act JsnlogConfiguration retrievedJsnlogConfiguration = JavascriptLogging.GetJsnlogConfiguration(); // Assert // Retrieved object is expected to be the exact same object that was put in Assert.Equal((uint)5, retrievedJsnlogConfiguration.maxMessages); }
public void InternalError() { string configXml = @" <jsnlog></jsnlog> "; XmlElement xe = CommonTestHelpers.ConfigToXe(configXml); // Act var jsnlogConfiguration = XmlHelpers.DeserialiseXml <JsnlogConfiguration>(xe); List <FinalLogData> actual = LoggerProcessor.ProcessLogRequestExec( _json4, new LogRequestBase("my browser", "12.345.98.7", "", "http://mydomain.com/main", null, null, null), _dtServerUtc, jsnlogConfiguration); // Assert Assert.Equal(1, actual.Count); Assert.Equal(Constants.JSNLogInternalErrorLoggerName, actual.ElementAt(0).FinalLogger); }
/// <summary> /// Ensures that the xml will be serialised by JSNLog to the code in csharp. /// Also writes HTML to d:\temp\demos.html with premade html for example tabs. /// /// In that HTML, you may want to apply strikethrough or the "new code" style. /// To do that, use these meta tags: /// /// <![CDATA[ /// (S}...striked through text ...{S)"/> /// (N}...striked through text ...{N)"/> /// ]]> /// </summary> /// <param name="configXml"></param> /// <param name="csharp"></param> public void TestDemo(string configXml, string csharp, string demoId) { // Testing to ensure xml and code are the same XmlElement xe = CommonTestHelpers.ConfigToXe(CodeWithoutMeta(configXml)); var jsnlogConfigurationFromXml = XmlHelpers.DeserialiseXml <JsnlogConfiguration>(xe); JsnlogConfiguration jsnlogConfigurationFromCode = (JsnlogConfiguration)UnitTestHelpers.Eval(CodeWithoutMeta(csharp)); UnitTestHelpers.EnsureEqualJsnlogConfiguration(jsnlogConfigurationFromXml, jsnlogConfigurationFromCode); // Write partial var sb = new StringBuilder(); sb.AppendLine(string.Format("@* GENERATED CODE - by class DemoTests in JSNLog.Tests project. Demo {0}. *@", demoId)); sb.AppendLine(@"<div class=""commontabs""><div data-tab=""Web.config"">"); sb.AppendLine(@""); sb.AppendLine(string.Format(@"<pre>{0}</pre>", CodeToHtml(configXml))); sb.AppendLine(@""); sb.AppendLine(@"</div><div data-tab=""JsnlogConfiguration"">"); sb.AppendLine(@""); sb.AppendLine(string.Format(@"<pre>JavascriptLogging.{0}({1});</pre>", LinkedText("SetJsnlogConfiguration", _setJsnlogConfigurationUrl), CodeToHtml(csharp))); sb.AppendLine(@""); sb.AppendLine(@"</div></div>"); string path = Path.Combine(TestConstants._demosDirectory, string.Format("_{0}.cshtml", demoId)); string content = sb.ToString(); bool fileExists = File.Exists(path); Assert.False(fileExists, string.Format("{0} already exists", path)); System.IO.File.WriteAllText(path, content); }
public void EnsureDefaultDateFormatAllowsJsonDeserialization() { // Arrange string configXml = @" <jsnlog serverSideMessageFormat=""{ 'utcDate': '%utcDate', 'utcDateServer': '%utcDateServer', 'date': '%date', 'dateServer': '%dateServer' }""></jsnlog>"; XmlElement xe = CommonTestHelpers.ConfigToXe(configXml); // Act var jsnlogConfiguration = XmlHelpers.DeserialiseXml <JsnlogConfiguration>(xe); List <FinalLogData> actual = LoggerProcessor.ProcessLogRequestExec( _json1, new LogRequestBase("my browser", "12.345.98.7", "http://mydomain.com/main", "", null, null, null), _dtServerUtc, jsnlogConfiguration); string messageToBeLogged = actual.FirstOrDefault().FinalMessage; var datesBag1 = LogMessageHelpers.DeserializeJson <DatesBag>(messageToBeLogged); TestDatesEqual(datesBag1.utcDate, _dtFirstLogUtc); TestDatesEqual(datesBag1.utcDateServer, _dtServerUtc); TestDatesEqual(datesBag1.date, _dtFirstLog); TestDatesEqual(datesBag1.dateServer, _dtServer); var datesBag2 = Newtonsoft.Json.JsonConvert.DeserializeObject <DatesBag>(messageToBeLogged); TestDatesEqual(datesBag2.utcDate, _dtFirstLogUtc); TestDatesEqual(datesBag2.utcDateServer, _dtServerUtc); TestDatesEqual(datesBag2.date, _dtFirstLog); TestDatesEqual(datesBag2.dateServer, _dtServer); }
/// <summary> /// Ensures that the xml will be serialised by JSNLog to the code in csharp. /// Also writes HTML to d:\temp\demos.html with premade html for example tabs. /// /// In that HTML, you may want to apply strikethrough or the "new code" style. /// To do that, use these meta tags: /// /// <![CDATA[ /// (S}...striked through text ...{S)"/> /// (N}...striked through text ...{N)"/> /// ]]> /// </summary> /// <param name="configXml"></param> /// <param name="csharp"></param> public void TestDemo(string configXml, string csharp, string demoId) { // Testing to ensure xml and code are the same XmlElement xe = CommonTestHelpers.ConfigToXe(CodeWithoutMeta(configXml)); var jsnlogConfigurationFromXml = XmlHelpers.DeserialiseXml <JsnlogConfiguration>(xe); JsnlogConfiguration jsnlogConfigurationFromCode = (JsnlogConfiguration)UnitTestHelpers.Eval(CodeWithoutMeta(csharp)); UnitTestHelpers.EnsureEqualJsnlogConfiguration(jsnlogConfigurationFromXml, jsnlogConfigurationFromCode); // Write partial var sb = new StringBuilder(); sb.AppendLine(string.Format("@* GENERATED CODE - by class DemoTests in JSNLog.Tests project. Demo {0}. *@", demoId)); sb.AppendLine("@using ViewExtensions"); sb.AppendLine(@"<div class=""commontabs""><div data-tab=""Web.config"">"); sb.AppendLine(@""); sb.AppendLine(string.Format(@"<pre>{0}</pre>", CodeToHtml(configXml))); sb.AppendLine(@""); sb.AppendLine(@"</div><div data-tab=""JsnlogConfiguration"">"); sb.AppendLine(@""); string html = CodeToHtml(csharp, 2); sb.AppendLine(@" @{ bool isNetCore; bool isNetFramework; PageVersions.GetPageVersion(out isNetCore, out isNetFramework); } "); sb.AppendLine(@" @if (isNetFramework) { <pre class='net-framework-only'>JavascriptLogging." + LinkedText("SetJsnlogConfiguration", _setJsnlogConfigurationUrl) + "(" + html + @");</pre> } "); sb.AppendLine(@" @if (isNetCore) { <pre class='net-core-only'>// Use in " + LinkedText("Configure method in Startup class", _setJsnlogCoreConfigurationUrl) + @" var jsnlogConfiguration = " + html + @";</pre> } "); sb.AppendLine(@""); sb.AppendLine(@"</div></div>"); string path = Path.Combine(TestConstants._demosDirectory, string.Format("_{0}.cshtml", demoId)); string content = sb.ToString(); bool fileExists = File.Exists(path); Assert.False(fileExists, string.Format("{0} already exists", path)); System.IO.File.WriteAllText(path, content); }