87 lines
2.9 KiB
C#
87 lines
2.9 KiB
C#
// /**
|
|
// * File: HtmlTests.cs
|
|
// * Author: haraldwolff
|
|
// *
|
|
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
|
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
|
// *
|
|
// *
|
|
// **/
|
|
using NUnit.Framework;
|
|
using System;
|
|
using ln.templates.html;
|
|
using System.IO;
|
|
using System.Text;
|
|
using Jint;
|
|
using Jint.Native;
|
|
using Jint.Native.Json;
|
|
using Jint.Native.Object;
|
|
using ln.templates.service;
|
|
|
|
namespace ln.templates.test
|
|
{
|
|
[TestFixture()]
|
|
public class HtmlTests
|
|
{
|
|
|
|
[TestCase()]
|
|
public void Test_Base()
|
|
{
|
|
Template template = new Template("tests/test_base.html", null);
|
|
Console.WriteLine("Template Source:\n{0}", template.Document.ToString());
|
|
|
|
StringWriter targetWriter = new StringWriter();
|
|
template.Render(targetWriter);
|
|
|
|
Console.WriteLine("Rendered Document:\n{0}", targetWriter.ToString());
|
|
}
|
|
|
|
[TestCase()]
|
|
public void Test_Slots()
|
|
{
|
|
FileSystemTemplateSource templateSource = new FileSystemTemplateSource("tests");
|
|
Template template = templateSource.GetTemplateByPath("test_slots.html");
|
|
|
|
Console.WriteLine("Template Source:\n{0}", template.Document.ToString());
|
|
|
|
StringWriter targetWriter = new StringWriter();
|
|
template.Render(targetWriter);
|
|
|
|
using (StreamWriter sw = new StreamWriter("test.out.slots.html"))
|
|
sw.Write(targetWriter.ToString());
|
|
|
|
Console.WriteLine("Rendered Document:\n{0}", targetWriter.ToString());
|
|
}
|
|
|
|
[TestCase()]
|
|
public void Test_Slots_Recursive()
|
|
{
|
|
RecursiveResolver templateSource = new RecursiveResolver("tests");
|
|
|
|
foreach (var prefix in new string[] { "", "custom/option1", "custom/option2" })
|
|
{
|
|
RecursiveResolver finalResolver = templateSource.FindResolver(prefix);
|
|
StringWriter targetWriter = new StringWriter();
|
|
Template template = finalResolver.GetTemplateByPath("test_slots_recursive.html");
|
|
|
|
template.Render(targetWriter);
|
|
|
|
template = null;
|
|
Console.WriteLine("Rendered Document (prefixed: {1}):\n{0}", targetWriter.ToString(), prefix);
|
|
}
|
|
}
|
|
|
|
[TestCase()]
|
|
public void Test_MetaData()
|
|
{
|
|
TemplateService templateService = new TemplateService("__templates__");
|
|
JsValue o = new JsonParser(new Engine()).Parse("{ \"title\": \"Some Title\", \"some_number\": 5342.23 }");
|
|
templateService.RenderTemplate("test_meta.html", o as ObjectInstance, out Stream memoryStream);
|
|
Console.WriteLine("META TEST:\n{0}", new StreamReader(memoryStream).ReadToEnd());
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|