Пример #1
0
        /// <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);
        }