Permalink
Browse files

Tried to fix some more tests, but ended up breaking others.

Ran out of time again, deployment will have to be put off for another night.
  • Loading branch information...
1 parent 9ea5df4 commit c49fe74091908d0439b434afa884f8554650d25f @mythz mythz committed Aug 28, 2012
Showing with 457 additions and 158 deletions.
  1. BIN lib/ServiceStack.OrmLite.SqlServer.dll
  2. BIN lib/ServiceStack.OrmLite.Sqlite.dll
  3. BIN lib/ServiceStack.OrmLite.dll
  4. BIN lib/ServiceStack.OrmLite.pdb
  5. +26 −6 src/ServiceStack.Razor/RazorFormat.cs
  6. +7 −0 src/ServiceStack.Razor/Templating/TemplateService.ServiceStack.cs
  7. +5 −4 src/ServiceStack/Html/TemplateProvider.cs
  8. +1 −0 src/ServiceStack/ServiceStack.csproj
  9. +6 −9 src/ServiceStack/VirtualPath/AbstractVirtualPathProviderBase.cs
  10. +162 −0 src/ServiceStack/VirtualPath/InMemoryVirtualPathProvider.cs
  11. +5 −1 src/ServiceStack/WebHost.Endpoints/Formats/MarkdownFormat.cs
  12. +3 −2 src/ServiceStack/WebHost.Endpoints/Support/Markdown/MarkdownHandler.cs
  13. +20 −9 src/ServiceStack/WebHost.Endpoints/Support/Markdown/TextBlock.cs
  14. +3 −1 tests/RazorRockstars.Console.Files/RazorRockstars.Console.Files.csproj
  15. +7 −5 tests/ServiceStack.Common.Tests/StringExtensionTests.cs
  16. 0 tests/ServiceStack.ServiceHost.Tests/AppData/Template/{default.shtml → _Layout.shtml}
  17. +15 −4 tests/ServiceStack.ServiceHost.Tests/Formats/IntroductionLayoutTests.cs
  18. +23 −0 tests/ServiceStack.ServiceHost.Tests/Formats/MarkdownFormatExtensions.cs
  19. +8 −4 tests/ServiceStack.ServiceHost.Tests/Formats/MarkdownFormatTests.cs
  20. +7 −3 tests/ServiceStack.ServiceHost.Tests/Formats/MarkdownTestBase.cs
  21. +18 −9 tests/ServiceStack.ServiceHost.Tests/Formats/TemplateTests.cs
  22. +5 −3 tests/ServiceStack.ServiceHost.Tests/Formats/ViewTests.cs
  23. +17 −4 tests/ServiceStack.ServiceHost.Tests/Formats_Razor/IntroductionExampleRazorTests.cs
  24. +14 −24 tests/ServiceStack.ServiceHost.Tests/Formats_Razor/IntroductionLayoutRazorTests.cs
  25. +57 −20 tests/ServiceStack.ServiceHost.Tests/Formats_Razor/RazorTestBase.cs
  26. +41 −44 tests/ServiceStack.ServiceHost.Tests/Formats_Razor/TemplateTests.cs
  27. +5 −4 tests/ServiceStack.ServiceHost.Tests/ServiceStack.ServiceHost.Tests.csproj
  28. +1 −1 tests/ServiceStack.ServiceHost.Tests/ServiceStack.ServiceHost.Tests.csproj.user
  29. 0 tests/ServiceStack.ServiceHost.Tests/Views/{Template → Shared}/_Layout.cshtml
  30. 0 tests/ServiceStack.ServiceHost.Tests/Views/{Template/default.shtml → Shared/_Layout.shtml}
  31. 0 tests/ServiceStack.ServiceHost.Tests/Views/{Template/alt-template.htm → Shared/alt-template.shtml}
  32. +1 −1 tests/ServiceStack.ServiceHost.Tests/Views/Template/Customer.md
View
BIN lib/ServiceStack.OrmLite.SqlServer.dll
Binary file not shown.
View
BIN lib/ServiceStack.OrmLite.Sqlite.dll
Binary file not shown.
View
BIN lib/ServiceStack.OrmLite.dll
Binary file not shown.
View
BIN lib/ServiceStack.OrmLite.pdb
Binary file not shown.
View
32 src/ServiceStack.Razor/RazorFormat.cs
@@ -75,7 +75,7 @@ public static bool IsRegistered
public Dictionary<string, Type> RazorExtensionBaseTypes { get; set; }
- readonly TemplateProvider templateProvider = new TemplateProvider(DefaultTemplateName);
+ public TemplateProvider TemplateProvider { get; set; }
public Type DefaultBaseType
{
@@ -115,6 +115,11 @@ public RazorFormat()
{"cshtml", typeof(ViewPage<>) },
{"rzr", typeof(ViewPage<>) },
};
+ this.TemplateProvider = new TemplateProvider(DefaultTemplateName) {
+ CompileInParallel = true,
+ CompileWithNoOfThreads = Environment.ProcessorCount * 2,
+ };
+ this.VirtualPathProvider = EndpointHost.VirtualPathProvider;
}
public void Register(IAppHost appHost)
@@ -134,7 +139,7 @@ public void Configure(IAppHost appHost)
foreach (var ns in EndpointHostConfig.RazorNamespaces)
TemplateNamespaces.Add(ns);
- this.ReplaceTokens = new Dictionary<string, string>(appHost.Config.MarkdownReplaceTokens);
+ this.ReplaceTokens = appHost.Config.MarkdownReplaceTokens ?? new Dictionary<string, string>();
if (!appHost.Config.WebHostUrl.IsNullOrEmpty())
this.ReplaceTokens["~/"] = appHost.Config.WebHostUrl.WithTrailingSlash();
@@ -362,6 +367,21 @@ public ViewPageRef GetViewPage(string pageName)
return razorPage;
}
+ private ViewPageRef GetTemplatePage(string pageName)
+ {
+ ViewPageRef razorPage;
+
+ var key = "Views/Shared/{0}.cshtml".Fmt(pageName);
+ MasterPageTemplates.TryGetValue(key, out razorPage);
+ if (razorPage != null)
+ {
+ razorPage.EnsureCompiled();
+ return razorPage;
+ }
+ return null;
+ }
+
+
private void RegisterRazorPages(string razorSearchPath)
{
foreach (var page in FindRazorPagesFn(razorSearchPath))
@@ -371,7 +391,7 @@ private void RegisterRazorPages(string razorSearchPath)
try
{
- templateProvider.CompileQueuedPages();
+ TemplateProvider.CompileQueuedPages();
}
catch (Exception ex)
{
@@ -404,7 +424,7 @@ public IEnumerable<ViewPageRef> FindRazorPages(string dirPath)
templateService.RegisterPage(csHtmlFile.VirtualPath, pageName);
var templatePath = pageType == RazorPageType.ContentPage
- ? templateProvider.GetTemplatePath(csHtmlFile.Directory)
+ ? TemplateProvider.GetTemplatePath(csHtmlFile.Directory)
: null;
yield return new ViewPageRef(this, csHtmlFile.VirtualPath, pageName, pageContents, pageType) {
@@ -423,7 +443,7 @@ public void AddPage(ViewPageRef page)
{
try
{
- templateProvider.QueuePageToCompile(page);
+ TemplateProvider.QueuePageToCompile(page);
AddViewPage(page);
}
catch (Exception ex)
@@ -518,7 +538,7 @@ public ViewPageRef AddTemplate(string templatePath, string templateContents)
try
{
//template.Compile();
- templateProvider.QueuePageToCompile(template);
+ TemplateProvider.QueuePageToCompile(template);
return template;
}
catch (Exception ex)
View
7 src/ServiceStack.Razor/Templating/TemplateService.ServiceStack.cs
@@ -85,6 +85,13 @@ public IRazorTemplate GetTemplate(string name)
if (!templateCache.TryGetValue(name, out instance))
{
var view = viewEngine.GetView(name);
+ if (view == null)
+ {
+ if (name == RazorFormat.DefaultTemplate)
+ return null;
+
+ throw new Exception("Could not find template " + name);
+ }
view.Compile(); //compiling adds to templateCache
templateCache.TryGetValue(name, out instance);
View
9 src/ServiceStack/Html/TemplateProvider.cs
@@ -11,8 +11,8 @@ namespace ServiceStack.Html
{
public class TemplateProvider
{
- public static bool CompileInParallel = false;
- public static int CompileWithNoOfThreads = Environment.ProcessorCount * 2;
+ public bool CompileInParallel { get; set; }
+ public int CompileWithNoOfThreads { get; set; }
private static readonly ILog Log = LogManager.GetLogger(typeof(TemplateProvider));
@@ -21,6 +21,7 @@ public class TemplateProvider
public TemplateProvider(string defaultTemplateName)
{
this.defaultTemplateName = defaultTemplateName;
+ this.CompileInParallel = false;
}
readonly Dictionary<string, IVirtualFile> templatePathsFound = new Dictionary<string, IVirtualFile>(StringComparer.InvariantCultureIgnoreCase);
@@ -78,9 +79,9 @@ public void QueuePageToCompile(IViewPage pageToCompile)
public void CompileQueuedPages()
{
Log.InfoFormat("Starting to compile {0}/{1} pages, {2}",
- compilePages.Count, priorityCompilePages.Count,
+ compilePages.Count, priorityCompilePages.Count,
CompileInParallel ? "In Parallel" : "Sequentially");
-
+
if (CompileInParallel)
{
var threadsToRun = Math.Min(CompileWithNoOfThreads, compilePages.Count);
View
1 src/ServiceStack/ServiceStack.csproj
@@ -182,6 +182,7 @@
<Compile Include="VirtualPath\FileSystemVirtualDirectory.cs" />
<Compile Include="VirtualPath\FileSystemVirtualFile.cs" />
<Compile Include="VirtualPath\FileSystemVirtualPathProvider.cs" />
+ <Compile Include="VirtualPath\InMemoryVirtualPathProvider.cs" />
<Compile Include="WebHost.Endpoints\AppHostExtensions.cs" />
<Compile Include="Markdown\CachedExpressionCompiler.cs" />
<Compile Include="Markdown\DynamicTypeGenerator .cs" />
View
15 src/ServiceStack/VirtualPath/AbstractVirtualPathProviderBase.cs
@@ -43,17 +43,14 @@ public virtual IVirtualFile GetFile(string virtualPath)
public virtual string GetFileHash(string virtualPath)
{
var f = GetFile(virtualPath);
- return GetFileHash(f); ;
- }
-
- public virtual string GetFileHash(IVirtualFile virtualFile)
- {
- if (virtualFile == null)
- return String.Empty;
-
- return virtualFile.GetFileHash();
+ return GetFileHash(f);
}
+ public virtual string GetFileHash(IVirtualFile virtualFile)
+ {
+ return virtualFile == null ? string.Empty : virtualFile.GetFileHash();
+ }
+
public virtual IVirtualDirectory GetDirectory(string virtualPath)
{
return RootDirectory.GetDirectory(virtualPath);
View
162 src/ServiceStack/VirtualPath/InMemoryVirtualPathProvider.cs
@@ -0,0 +1,162 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using ServiceStack.Text;
+using ServiceStack.WebHost.Endpoints;
+
+namespace ServiceStack.VirtualPath
+{
+ /// <summary>
+ /// In Memory repository for files. Useful for testing.
+ /// </summary>
+ public class InMemoryVirtualPathProvider : AbstractVirtualPathProviderBase
+ {
+ public InMemoryVirtualPathProvider(IAppHost appHost)
+ : base(appHost)
+ {
+ this.rootDirectory = new InMemoryVirtualDirectory(this);
+ }
+
+ public InMemoryVirtualDirectory rootDirectory;
+
+ public override IVirtualDirectory RootDirectory
+ {
+ get { return rootDirectory; }
+ }
+
+ public override string VirtualPathSeparator
+ {
+ get { return "/"; }
+ }
+
+ public override string RealPathSeparator
+ {
+ get { return "/"; }
+ }
+
+ protected override void Initialize()
+ {
+ }
+
+ public void AddFile(string filePath, string contents)
+ {
+ rootDirectory.AddFile(filePath, contents);
+ }
+
+ public override IVirtualFile GetFile(string virtualPath)
+ {
+ return rootDirectory.GetFile(virtualPath)
+ ?? base.GetFile(virtualPath);
+ }
+ }
+
+ public class InMemoryVirtualDirectory : AbstractVirtualDirectoryBase
+ {
+ public InMemoryVirtualDirectory(IVirtualPathProvider owningProvider)
+ : base(owningProvider)
+ {
+ this.files = new List<InMemoryVirtualFile>();
+ this.dirs = new List<InMemoryVirtualDirectory>();
+ this.DirLastModified = DateTime.MinValue;
+ }
+
+ public InMemoryVirtualDirectory(IVirtualPathProvider owningProvider, IVirtualDirectory parentDirectory)
+ : base(owningProvider, parentDirectory) {}
+
+ public DateTime DirLastModified { get; set; }
+ public override DateTime LastModified
+ {
+ get { return DirLastModified; }
+ }
+
+ public List<InMemoryVirtualFile> files;
+
+ public override IEnumerable<IVirtualFile> Files
+ {
+ get { return files.Cast<IVirtualFile>(); }
+ }
+
+ public List<InMemoryVirtualDirectory> dirs;
+
+ public override IEnumerable<IVirtualDirectory> Directories
+ {
+ get { return dirs.Cast<IVirtualDirectory>(); }
+ }
+
+ public string DirName { get; set; }
+ public override string Name
+ {
+ get { return DirName; }
+ }
+
+ public override IVirtualFile GetFile(string virtualPath)
+ {
+ return files.FirstOrDefault(x => x.FilePath == virtualPath);
+ }
+
+ public override IEnumerator<IVirtualNode> GetEnumerator()
+ {
+ throw new NotImplementedException();
+ }
+
+ protected override IVirtualFile GetFileFromBackingDirectoryOrDefault(string fileName)
+ {
+ return files.FirstOrDefault(x => x.FilePath == fileName);
+ }
+
+ protected override IEnumerable<IVirtualFile> GetMatchingFilesInDir(string globPattern)
+ {
+ throw new NotImplementedException();
+ }
+
+ protected override IVirtualDirectory GetDirectoryFromBackingDirectoryOrDefault(string directoryName)
+ {
+ return null;
+ }
+
+ static readonly char[] DirSeps = new[] { '\\', '/' };
+ public void AddFile(string filePath, string contents)
+ {
+ this.files.Add(new InMemoryVirtualFile(VirtualPathProvider, this) {
+ FilePath = filePath,
+ FileName = filePath.Split(DirSeps).Last(),
+ TextContents = contents,
+ });
+ }
+ }
+
+ public class InMemoryVirtualFile : AbstractVirtualFileBase
+ {
+ public InMemoryVirtualFile(IVirtualPathProvider owningProvider, IVirtualDirectory directory)
+ : base(owningProvider, directory)
+ {
+ this.FileLastModified = DateTime.MinValue;
+ }
+
+ public string FilePath { get; set; }
+
+ public string FileName { get; set; }
+ public override string Name
+ {
+ get { return FileName; }
+ }
+
+ public DateTime FileLastModified { get; set; }
+ public override DateTime LastModified
+ {
+ get { return FileLastModified; }
+ }
+
+ public string TextContents { get; set; }
+
+ public byte[] ByteContents { get; set; }
+
+ public override Stream OpenRead()
+ {
+ return new MemoryStream(ByteContents ?? (TextContents ?? "").ToUtf8Bytes());
+ }
+ }
+
+
+}
View
6 src/ServiceStack/WebHost.Endpoints/Formats/MarkdownFormat.cs
@@ -80,9 +80,10 @@ public MarkdownFormat()
this.MarkdownGlobalHelpers = new Dictionary<string, Type>();
this.FindMarkdownPagesFn = FindMarkdownPages;
this.MarkdownReplaceTokens = new Dictionary<string, string>();
+ this.VirtualPathProvider = EndpointHost.VirtualPathProvider;
}
- static readonly char[] DirSeps = new[] { '\\', '/' };
+ internal static readonly char[] DirSeps = new[] { '\\', '/' };
static HashSet<string> catchAllPathsNotFound = new HashSet<string>();
public void Register(IAppHost appHost)
@@ -525,6 +526,9 @@ private string RenderInTemplateIfAny(MarkdownPage markdownPage, Dictionary<strin
if (markdownTemplate == null)
{
+ if (templatePath == null)
+ return pageHtml;
+
throw new Exception("No template found for page: " + markdownPage.FilePath);
}
}
View
5 src/ServiceStack/WebHost.Endpoints/Support/Markdown/MarkdownHandler.cs
@@ -18,8 +18,9 @@ public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes,
var contentPage = MarkdownPage;
if (contentPage == null)
{
- var pageFilePath = this.FilePath.WithoutExtension();
- contentPage = MarkdownFormat.GetContentPage(pageFilePath);
+ contentPage = MarkdownFormat.GetContentPage(
+ this.FilePath.WithoutExtension(),
+ PathInfo.TrimStart(MarkdownFormat.DirSeps).WithoutExtension());
}
if (contentPage == null)
{
View
29 src/ServiceStack/WebHost.Endpoints/Support/Markdown/TextBlock.cs
@@ -939,15 +939,26 @@ private void Prepare(MarkdownPage markdownPage)
"Unable to resolve type '{0}'. Check type exists in Config.MarkdownBaseType or Page.Markdown.MarkdownGlobalHelpers",
typePropertyName));
- var mi = type.GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance);
- if (mi == null)
- {
- mi = HtmlHelper.GetMethod(methodName);
- if (mi == null)
- throw new ArgumentException("Unable to resolve method '" + methodExpr + "' on type " + type.Name);
- }
-
- base.ReturnType = mi.ReturnType;
+ try
+ {
+ var mi = methodName == "Partial"
+ ? type.GetMethods(BindingFlags.Public | BindingFlags.Instance)
+ .FirstOrDefault(m => m.GetParameters().Length == 2 && m.Name == methodName)
+ : type.GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance);
+
+ if (mi == null)
+ {
+ mi = HtmlHelper.GetMethod(methodName);
+ if (mi == null)
+ throw new ArgumentException("Unable to resolve method '" + methodExpr + "' on type " + type.Name);
+ }
+
+ base.ReturnType = mi.ReturnType;
+ }
+ catch (Exception ex)
+ {
+ throw;
+ }
var isMemberExpr = Condition.IndexOf('(') != -1;
if (!isMemberExpr || this.WriteRawHtml)
View
4 tests/RazorRockstars.Console.Files/RazorRockstars.Console.Files.csproj
@@ -66,7 +66,9 @@
<Compile Include="RazorRockstars_FilesTests.cs" />
</ItemGroup>
<ItemGroup>
- <None Include="App.config" />
+ <None Include="App.config">
+ <SubType>Designer</SubType>
+ </None>
<None Include="TypedModelNoController.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
View
12 tests/ServiceStack.Common.Tests/StringExtensionTests.cs
@@ -106,11 +106,13 @@ public void SafeVarName_strips_illegal_chars()
[Test]
public void Glob_finds_right_strings()
- {
- var input = new[] {"Foo, Boo, Hoo, Baz"};
- var expected = input.Where(s => s.EndsWith("oo")).ToArray();
-
- Assert.AreEqual(expected, input.Select(s => s.Glob("*oo")));
+ {
+ var input = new[] { "Foo", "Boo", "Hoo", "Baz" }.ToList();
+ var expected = input.Where(s => s.EndsWith("oo")).ToList();
+
+ var actual = input.Where(s => s.Glob("*oo")).ToList();
+
+ Assert.That(actual, Is.EquivalentTo(expected));
}
}
}
View
0 ...Host.Tests/AppData/Template/default.shtml → ...Host.Tests/AppData/Template/_Layout.shtml
File renamed without changes.
View
19 tests/ServiceStack.ServiceHost.Tests/Formats/IntroductionLayoutTests.cs
@@ -4,6 +4,9 @@
using NUnit.Framework;
using ServiceStack.Html;
using ServiceStack.Markdown;
+using ServiceStack.ServiceInterface.Testing;
+using ServiceStack.VirtualPath;
+using ServiceStack.WebHost.Endpoints;
using ServiceStack.WebHost.Endpoints.Formats;
using ServiceStack.WebHost.Endpoints.Support.Markdown;
@@ -41,6 +44,14 @@ public MvcHtmlString Field(string fieldName, string fieldValue)
[TestFixture]
public class IntroductionLayoutTests : MarkdownTestBase
{
+ private InMemoryVirtualPathProvider pathProvider;
+
+ [TestFixtureSetUp]
+ public void TestFixtureSetUp()
+ {
+ EndpointHost.VirtualPathProvider = pathProvider = new InMemoryVirtualPathProvider(new BasicAppHost());
+ }
+
[Test]
public void Simple_Layout_Example()
{
@@ -65,7 +76,7 @@ public void Simple_Layout_Example()
</html>".NormalizeNewLines();
var pageTemplate =
-@"@Layout ~/websiteTemplate
+@"@Layout websiteTemplate
# About this Site
@@ -112,7 +123,7 @@ public void Simple_Layout_Example()
markdownFormat.AddPage(
new MarkdownPage(markdownFormat, @"C:\path\to\page-tpl", PageName, pageTemplate));
- markdownFormat.AddTemplate(@"C:\path\to\websiteTemplate", websiteTemplate);
+ markdownFormat.AddFileAndTemplate(@"websiteTemplate", websiteTemplate);
var html = markdownFormat.RenderDynamicPageHtml(PageName);
@@ -154,7 +165,7 @@ public void Layout_MasterPage_Scenarios_Adding_Sections()
</html>".NormalizeNewLines();
var pageTemplate =
-@"@Layout ~/websiteTemplate
+@"@Layout websiteTemplate
# About this Site
@@ -225,7 +236,7 @@ public void Layout_MasterPage_Scenarios_Adding_Sections()
markdownFormat.AddPage(
new MarkdownPage(markdownFormat, @"C:\path\to\page-tpl", PageName, pageTemplate));
- markdownFormat.AddTemplate(@"C:\path\to\websiteTemplate", websiteTemplate);
+ markdownFormat.AddFileAndTemplate(@"websiteTemplate", websiteTemplate);
var html = markdownFormat.RenderDynamicPageHtml(PageName);
View
23 tests/ServiceStack.ServiceHost.Tests/Formats/MarkdownFormatExtensions.cs
@@ -0,0 +1,23 @@
+using ServiceStack.VirtualPath;
+using ServiceStack.WebHost.Endpoints.Formats;
+using ServiceStack.WebHost.Endpoints.Support.Markdown;
+
+namespace ServiceStack.ServiceHost.Tests.Formats
+{
+ public static class MarkdownFormatExtensions
+ {
+ public static void AddFileAndPage(this MarkdownFormat markdown, MarkdownPage markdownPage)
+ {
+ var pathProvider = (InMemoryVirtualPathProvider)markdown.VirtualPathProvider;
+ pathProvider.AddFile(markdownPage.FilePath, markdownPage.Contents);
+ markdown.AddPage(markdownPage);
+ }
+
+ public static void AddFileAndTemplate(this MarkdownFormat markdown, string filePath, string contents)
+ {
+ var pathProvider = (InMemoryVirtualPathProvider)markdown.VirtualPathProvider;
+ pathProvider.AddFile(filePath, contents);
+ markdown.AddTemplate(filePath, contents);
+ }
+ }
+}
View
12 tests/ServiceStack.ServiceHost.Tests/Formats/MarkdownFormatTests.cs
@@ -4,7 +4,9 @@
using NUnit.Framework;
using ServiceStack.Common;
using ServiceStack.Common.Utils;
+using ServiceStack.ServiceInterface.Testing;
using ServiceStack.Text;
+using ServiceStack.VirtualPath;
using ServiceStack.WebHost.Endpoints.Formats;
namespace ServiceStack.ServiceHost.Tests.Formats
@@ -55,7 +57,9 @@ public void TestFixtureSetUp()
[SetUp]
public void OnBeforeEachTest()
{
- markdownFormat = new MarkdownFormat();
+ markdownFormat = new MarkdownFormat {
+ VirtualPathProvider = new FileSystemVirtualPathProvider(new BasicAppHost(), "~/".MapProjectPath()),
+ };
}
[Test]
@@ -79,7 +83,7 @@ public void Can_load_all_markdown_files()
public void Can_Render_StaticPage()
{
markdownFormat.RegisterMarkdownPages("~/".MapProjectPath());
- var html = markdownFormat.RenderStaticPageHtml("~/AppData/NoTemplate/Static".MapProjectPath());
+ var html = markdownFormat.RenderStaticPageHtml("AppData/NoTemplate/Static");
Assert.That(html, Is.Not.Null);
Assert.That(html, Is.StringStarting("<h1>Static Markdown template</h1>"));
@@ -89,9 +93,9 @@ public void Can_Render_StaticPage()
public void Can_Render_StaticPage_WithTemplate()
{
markdownFormat.RegisterMarkdownPages("~/".MapProjectPath());
- var html = markdownFormat.RenderStaticPageHtml("~/AppData/Template/StaticTpl".MapProjectPath());
+ var html = markdownFormat.RenderStaticPageHtml("AppData/Template/StaticTpl");
- Console.WriteLine(html);
+ html.Print();
Assert.That(html, Is.Not.Null);
Assert.That(html, Is.StringStarting("<!doctype html>"));
View
10 tests/ServiceStack.ServiceHost.Tests/Formats/MarkdownTestBase.cs
@@ -1,4 +1,6 @@
using System.Collections.Generic;
+using ServiceStack.ServiceInterface.Testing;
+using ServiceStack.VirtualPath;
using ServiceStack.WebHost.Endpoints.Formats;
using ServiceStack.WebHost.Endpoints.Support.Markdown;
@@ -11,12 +13,14 @@ public class MarkdownTestBase
public MarkdownFormat Create(string websiteTemplate, string pageTemplate)
{
- var markdownFormat = new MarkdownFormat();
+ var markdownFormat = new MarkdownFormat {
+ VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost())
+ };
- markdownFormat.AddTemplate("/path/to/websitetpl", websiteTemplate);
+ markdownFormat.AddFileAndTemplate("websiteTemplate", websiteTemplate);
markdownFormat.AddPage(
new MarkdownPage(markdownFormat, "/path/to/tpl", PageName, pageTemplate) {
- Template = "/path/to/websitetpl",
+ Template = "websiteTemplate",
});
return markdownFormat;
View
27 tests/ServiceStack.ServiceHost.Tests/Formats/TemplateTests.cs
@@ -7,6 +7,9 @@
using ServiceStack.Common.Utils;
using ServiceStack.Html;
using ServiceStack.Markdown;
+using ServiceStack.ServiceInterface.Testing;
+using ServiceStack.Text;
+using ServiceStack.VirtualPath;
using ServiceStack.WebHost.Endpoints.Formats;
using ServiceStack.WebHost.Endpoints.Support.Markdown;
@@ -41,7 +44,9 @@ public void TestFixtureSetUp()
[SetUp]
public void OnBeforeEachTest()
{
- markdownFormat = new MarkdownFormat();
+ markdownFormat = new MarkdownFormat {
+ VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost())
+ };
templateArgs = new Dictionary<string, object> { { MarkdownPage.ModelName, person } };
}
@@ -360,7 +365,7 @@ public void Can_Render_Markdown_with_StaticMethods()
{"Ext", typeof(CustomMarkdownHelper)}
};
- markdownFormat.RegisterMarkdownPage(new MarkdownPage(markdownFormat,
+ markdownFormat.RegisterMarkdownPage(new MarkdownPage(markdownFormat,
"/path/to/page", "HeaderLinks", headerTemplate));
var dynamicPage = new MarkdownPage(markdownFormat, "/path/to/tpl", "DynamicIfTpl", template);
@@ -369,7 +374,7 @@ public void Can_Render_Markdown_with_StaticMethods()
var templateOutput = dynamicPage.RenderToHtml(templateArgs);
templateOutput = templateOutput.Replace("\r\n", "\n");
- Console.WriteLine(templateOutput);
+ templateOutput.Print();
Assert.That(templateOutput, Is.EqualTo(expectedHtml));
}
@@ -523,6 +528,7 @@ public void Can_Render_page_to_Markdown_only()
### Breadcrumbs
@Combine("" / "", Model.FirstName, Model.LastName)
+
### Menus
@foreach (var link in Model.Links) {
- @link.Name - @link.Href
@@ -577,10 +583,12 @@ public void Can_Render_Markdown_with_variable_statements()
Hello @Upper(lastName), @Model.FirstName
+
### Breadcrumbs
@Combine("" / "", Model.FirstName, lastName)
@var links = Model.Links
+
### Menus
@foreach (var link in links) {
- @link.Name - @link.Href
@@ -594,6 +602,7 @@ public void Can_Render_Markdown_with_variable_statements()
Hello BELLOT, Demis
+
### Breadcrumbs
Demis / Bellot
@@ -883,11 +892,11 @@ public void Can_Render_Template_with_section_and_variable_placeholders()
</body>
</html>".Replace("\r\n", "\n");
- markdownFormat.AddTemplate("/path/to/tpl", websiteTemplate);
+ markdownFormat.AddFileAndTemplate("websiteTemplate", websiteTemplate);
markdownFormat.AddPage(
new MarkdownPage(markdownFormat, "/path/to/page-tpl", "DynamicModelTpl", template) {
- Template = "/path/to/tpl"
+ Template = "websiteTemplate"
});
var templateOutput = markdownFormat.RenderDynamicPageHtml("DynamicModelTpl", person);
@@ -970,14 +979,14 @@ public void Can_Render_Static_ContentPage_that_populates_variable_and_displayed_
markdownFormat.MarkdownBaseType = typeof(CustomMarkdownViewBase);
- markdownFormat.AddTemplate("/path/to/tpl", websiteTemplate);
+ markdownFormat.AddFileAndTemplate("websiteTemplate", websiteTemplate);
markdownFormat.RegisterMarkdownPage(
- new MarkdownPage(markdownFormat, "/path/to/pagetpl", "StaticTpl", template, MarkdownPageType.ContentPage) {
- Template = "/path/to/tpl"
+ new MarkdownPage(markdownFormat, "pagetpl", "StaticTpl", template, MarkdownPageType.ContentPage) {
+ Template = "websiteTemplate"
});
- var templateOutput = markdownFormat.RenderStaticPage("/path/to/pagetpl", true);
+ var templateOutput = markdownFormat.RenderStaticPage("pagetpl", true);
Console.WriteLine(templateOutput);
Assert.That(templateOutput, Is.EqualTo(expectedHtml));
View
8 tests/ServiceStack.ServiceHost.Tests/Formats/ViewTests.cs
@@ -36,7 +36,9 @@ public void TestFixtureSetUp()
public void OnBeforeEachTest()
{
appHost = new AppHost();
- markdownFormat = new MarkdownFormat();
+ markdownFormat = new MarkdownFormat {
+ VirtualPathProvider = appHost.VirtualPathProvider
+ };
markdownFormat.Register(appHost);
}
@@ -52,7 +54,7 @@ public AppHost()
this.ResponseFilters = new List<Action<IHttpRequest, IHttpResponse, object>>();
this.ViewEngines = new List<IViewEngine>();
this.CatchAllHandlers = new List<HttpHandlerResolverDelegate>();
- this.VirtualPathProvider = new FileSystemVirtualPathProvider(this);
+ this.VirtualPathProvider = new FileSystemVirtualPathProvider(this, "~".MapProjectPath());
}
public void Register<T>(T instance)
@@ -181,7 +183,7 @@ public void Does_serve_dynamic_view_HTML_page_with_ALT_template()
{
var html = GetHtml(response.Customer);
- Console.WriteLine(html);
+ html.Print();
//File.WriteAllText("~/AppData/TestsResults/Customer.htm".MapAbsolutePath(), html);
Assert.That(html.StartsWith("<!doctype html>"));
View
21 tests/ServiceStack.ServiceHost.Tests/Formats_Razor/IntroductionExampleRazorTests.cs
@@ -1,8 +1,13 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
+using ServiceStack.Common.Utils;
using ServiceStack.Razor;
using ServiceStack.ServiceHost.Tests.Formats;
+using ServiceStack.ServiceInterface.Testing;
+using ServiceStack.Text;
+using ServiceStack.VirtualPath;
+using ServiceStack.WebHost.Endpoints;
namespace ServiceStack.ServiceHost.Tests.Formats_Razor
{
@@ -36,10 +41,18 @@ public void TestFixtureSetUp()
new Product("DVD", 11.99m),
};
productArgs = new { products = products };
-
- var mvcRazorFormat = new RazorFormat { DefaultBaseType = typeof(CustomRazorBasePage<>) };
- mvcRazorFormat.Init();
}
+
+ [SetUp]
+ public void SetUp()
+ {
+ RazorFormat = new RazorFormat {
+ DefaultBaseType = typeof(CustomRazorBasePage<>),
+ VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost()),
+ TemplateProvider = { CompileInParallel = false },
+ };
+ RazorFormat.Init();
+ }
[Test]
public void Basic_Razor_Example()
@@ -190,7 +203,7 @@ public void HTML_encoding()
var html = RenderToHtml(template, new { stringContainingHtml = "<span>html</span>"});
- Console.WriteLine(html);
+ html.Print();
Assert.That(html, Is.EqualTo(expectedHtml));
}
View
38 tests/ServiceStack.ServiceHost.Tests/Formats_Razor/IntroductionLayoutRazorTests.cs
@@ -5,6 +5,8 @@
using ServiceStack.Html;
using ServiceStack.Razor;
using ServiceStack.ServiceHost.Tests.Formats;
+using ServiceStack.ServiceInterface.Testing;
+using ServiceStack.VirtualPath;
namespace ServiceStack.ServiceHost.Tests.Formats_Razor
{
@@ -40,25 +42,15 @@ public MvcHtmlString Field(string fieldName, string fieldValue)
[TestFixture]
public class IntroductionLayoutRazorTests : RazorTestBase
{
- private RazorFormat razorFormat;
-
[SetUp]
public void OnBeforeEachTest()
{
- razorFormat = new RazorFormat();
- razorFormat.Init();
- }
-
- private ViewPageRef AddViewPage(string pageName, string pagePath, string pageContents, string templatePath = null)
- {
- var dynamicPage = new ViewPageRef(razorFormat,
- pagePath, pageName, pageContents, RazorPageType.ViewPage) {
- Template = templatePath
- };
-
- razorFormat.AddPage(dynamicPage);
- return dynamicPage;
- }
+ base.RazorFormat = new RazorFormat {
+ VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost()),
+ TemplateProvider = { CompileInParallel = false },
+ };
+ base.RazorFormat.Init();
+ }
[Test]
public void Simple_Layout_Example()
@@ -84,7 +76,7 @@ public void Simple_Layout_Example()
</html>".NormalizeNewLines();
var pageTemplate =
-@"@{ Layout = ""C:\\path\\to\\websiteTemplate""; }
+@"@{ Layout = ""websiteTemplate.cshtml""; }
<h1>About this Site</h1>
@@ -127,8 +119,7 @@ public void Simple_Layout_Example()
</html>".NormalizeNewLines();
- var websiteTemplatePath = @"C:\path\to\websiteTemplate";
- razorFormat.AddTemplate(websiteTemplatePath, websiteTemplate);
+ RazorFormat.AddFileAndTemplate("websiteTemplate.cshtml", websiteTemplate);
var dynamicPage = AddViewPage(PageName, @"C:\path\to\page-tpl", pageTemplate);
var template = dynamicPage.RenderToHtml();
@@ -240,11 +231,10 @@ public void Layout_MasterPage_Scenarios_Adding_Sections()
</html>".NormalizeNewLines();
- var websiteTemplatePath = @"C:\path\to\websiteTemplate";
- razorFormat.AddTemplate(websiteTemplatePath, websiteTemplate);
+ RazorFormat.AddFileAndTemplate("websiteTemplate.cshtml", websiteTemplate);
var dynamicPage = AddViewPage(
- PageName, @"C:\path\to\page-tpl", pageTemplate, websiteTemplatePath);
+ PageName, @"C:\path\to\page-tpl.cshtml", pageTemplate, "websiteTemplate.cshtml");
var html = dynamicPage.RenderToHtml();
@@ -320,7 +310,7 @@ public void Using_External_HTML_Helpers()
new Product("DVD", 11.99m),
};
- razorFormat.DefaultBaseType = typeof(CustomViewBase<>);
+ RazorFormat.TemplateService.TemplateBaseType = typeof(CustomViewBase<>);
var html = RenderToHtml(pageTemplate, products);
@@ -347,7 +337,7 @@ public void Using_Custom_base_class()
</fieldset>".NormalizeNewLines();
- razorFormat.DefaultBaseType = typeof(CustomBaseClass<>);
+ RazorFormat.DefaultBaseType = typeof(CustomBaseClass<>);
var html = RenderToHtml(pageTemplate, new Product("Pen", 1.99m));
View
77 tests/ServiceStack.ServiceHost.Tests/Formats_Razor/RazorTestBase.cs
@@ -1,53 +1,90 @@
using System.Collections.Generic;
using ServiceStack.Razor;
+using ServiceStack.VirtualPath;
namespace ServiceStack.ServiceHost.Tests.Formats_Razor
{
- public class RazorTestBase
+ public static class MarkdownFormatExtensions
+ {
+ public static void AddFileAndView(this RazorFormat razorFormat, ViewPageRef viewPage)
+ {
+ var pathProvider = (InMemoryVirtualPathProvider)razorFormat.VirtualPathProvider;
+ pathProvider.AddFile(viewPage.FilePath, viewPage.Contents);
+ razorFormat.AddPage(viewPage);
+ }
+
+ public static void AddFileAndTemplate(this RazorFormat razorFormat, string filePath, string contents)
+ {
+ var pathProvider = (InMemoryVirtualPathProvider)razorFormat.VirtualPathProvider;
+ pathProvider.AddFile(filePath, contents);
+ razorFormat.AddTemplate(filePath, contents);
+ }
+ }
+
+ public class RazorTestBase
{
public const string TemplateName = "Template";
protected const string PageName = "Page";
+ protected RazorFormat RazorFormat;
- public RazorFormat Create(string websiteTemplate, string pageTemplate)
+ public RazorFormat AddPage(string websiteTemplate, string pageTemplate)
{
- var razorFormat = new RazorFormat();
-
- razorFormat.AddTemplate("/path/to/websitetpl", websiteTemplate);
- razorFormat.AddPage(
- new ViewPageRef(razorFormat, "/path/to/tpl", PageName, pageTemplate) {
- Template = "/path/to/websitetpl",
+ RazorFormat.AddTemplate("websiteTemplate", websiteTemplate);
+ RazorFormat.AddPage(
+ new ViewPageRef(RazorFormat, "/path/to/tpl", PageName, pageTemplate) {
+ Template = "websiteTemplate",
});
- return razorFormat;
+ return RazorFormat;
}
- public RazorFormat Create(string pageTemplate)
+ public RazorFormat AddPage(string pageTemplate)
{
- var razorFormat = new RazorFormat();
- razorFormat.AddPage(
- new ViewPageRef(razorFormat, "/path/to/tpl", PageName, pageTemplate));
+ RazorFormat.AddPage(
+ new ViewPageRef(RazorFormat, "/path/to/tpl", PageName, pageTemplate) {
+ Service = RazorFormat.TemplateService
+ });
+
+ RazorFormat.TemplateService.RegisterPage("/path/to/tpl", PageName);
+ RazorFormat.TemplateProvider.CompileQueuedPages();
- return razorFormat;
+ return RazorFormat;
}
+ protected ViewPageRef AddViewPage(string pageName, string pagePath, string pageContents, string templatePath = null)
+ {
+ var dynamicPage = new ViewPageRef(RazorFormat,
+ pagePath, pageName, pageContents, RazorPageType.ViewPage) {
+ Template = templatePath,
+ Service = RazorFormat.TemplateService
+ };
+
+ RazorFormat.AddPage(dynamicPage);
+
+ RazorFormat.TemplateService.RegisterPage(pagePath, pageName);
+ RazorFormat.TemplateProvider.CompileQueuedPages();
+
+ return dynamicPage;
+ }
+
public string RenderToHtml(string pageTemplate, Dictionary<string, object> scopeArgs)
{
- var razorFormat = Create(pageTemplate);
- var template = razorFormat.ExecuteTemplate(scopeArgs, PageName, null);
+ AddPage(pageTemplate);
+ var template = RazorFormat.ExecuteTemplate(scopeArgs, PageName, null);
return template.Result;
}
public string RenderToHtml(string pageTemplate, Dictionary<string, object> scopeArgs, string websiteTemplate)
{
- var razorFormat = Create(pageTemplate);
- var template = razorFormat.ExecuteTemplate(scopeArgs, PageName, websiteTemplate);
+ AddPage(pageTemplate);
+ var template = RazorFormat.ExecuteTemplate(scopeArgs, PageName, websiteTemplate);
return template.Result;
}
public string RenderToHtml<T>(string pageTemplate, T model)
{
- var razorFormat = Create(pageTemplate);
- var template = razorFormat.ExecuteTemplate(model, PageName, null);
+ AddPage(pageTemplate);
+ var template = RazorFormat.ExecuteTemplate(model, PageName, null);
return template.Result;
}
}
View
85 tests/ServiceStack.ServiceHost.Tests/Formats_Razor/TemplateTests.cs
@@ -9,6 +9,9 @@
using ServiceStack.Markdown;
using ServiceStack.Razor;
using ServiceStack.ServiceHost.Tests.Formats;
+using ServiceStack.ServiceInterface.Testing;
+using ServiceStack.Text;
+using ServiceStack.VirtualPath;
namespace ServiceStack.ServiceHost.Tests.Formats_Razor
{
@@ -97,7 +100,7 @@ public MvcHtmlString InlineBlock(string content, string id)
}
[TestFixture]
- public class RazorTemplateTests
+ public class RazorTemplateTests : RazorTestBase
{
string staticTemplatePath;
string staticTemplateContent;
@@ -106,7 +109,6 @@ public class RazorTemplateTests
string dynamicListPagePath;
string dynamicListPageContent;
- private RazorFormat razorFormat;
Person templateArgs;
Person person = new Person {
@@ -122,42 +124,34 @@ public class RazorTemplateTests
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
- staticTemplatePath = "~/Views/Template/_Layout.cshtml".MapProjectPath();
- staticTemplateContent = File.ReadAllText(staticTemplatePath);
+ staticTemplatePath = "Views/Shared/_Layout.cshtml";
+ staticTemplateContent = File.ReadAllText("~/{0}".Fmt(staticTemplatePath).MapProjectPath());
- dynamicPagePath = "~/Views/Template/DynamicTpl.cshtml".MapProjectPath();
- dynamicPageContent = File.ReadAllText(dynamicPagePath);
+ dynamicPagePath = "Views/Template/DynamicTpl.cshtml";
+ dynamicPageContent = File.ReadAllText("~/{0}".Fmt(dynamicPagePath).MapProjectPath());
- dynamicListPagePath = "~/Views/Template/DynamicListTpl.cshtml".MapProjectPath();
- dynamicListPageContent = File.ReadAllText(dynamicListPagePath);
+ dynamicListPagePath = "Views/Template/DynamicListTpl.cshtml".MapProjectPath();
+ dynamicListPageContent = File.ReadAllText("~/{0}".Fmt(dynamicListPagePath).MapProjectPath());
templateArgs = person;
}
[SetUp]
public void OnBeforeEachTest()
{
- razorFormat = new RazorFormat();
- razorFormat.Init();
- }
-
- private ViewPageRef AddViewPage(string pageName, string pagePath, string pageContents, string templatePath = null)
- {
- var dynamicPage = new ViewPageRef(razorFormat,
- pagePath, pageName, pageContents, RazorPageType.ViewPage) {
- Template = templatePath
- };
-
- razorFormat.AddPage(dynamicPage);
- return dynamicPage;
+ base.RazorFormat = new RazorFormat {
+ VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost()),
+ TemplateProvider = { CompileInParallel = false },
+ };
+ RazorFormat.Init();
}
[Test]
public void Can_Render_RazorTemplate()
{
const string mockContents = "[Replaced with Template]";
- razorFormat.AddTemplate(staticTemplatePath, staticTemplateContent);
+ RazorFormat.AddFileAndTemplate(staticTemplatePath, staticTemplateContent);
var page = AddViewPage("MockPage", "/path/to/page", mockContents, staticTemplatePath);
var expectedHtml = staticTemplateContent.ReplaceFirst(RazorFormat.TemplatePlaceHolder, mockContents);
@@ -172,7 +166,8 @@ public void Can_Render_RazorTemplate()
[Test]
public void Can_Render_RazorPage()
{
- var dynamicPage = AddViewPage("DynamicTpl", dynamicPagePath, dynamicPageContent, staticTemplatePath);
+ RazorFormat.AddFileAndTemplate(staticTemplatePath, staticTemplateContent);
+ var dynamicPage = AddViewPage("DynamicTpl", dynamicPagePath, dynamicPageContent, staticTemplatePath);
var expectedHtml = dynamicPageContent
.Replace("@Model.FirstName", person.FirstName)
@@ -190,7 +185,8 @@ public void Can_Render_RazorPage()
[Test]
public void Can_Render_RazorPage_with_foreach()
{
- var dynamicPage = AddViewPage("DynamicListTpl", dynamicListPagePath, dynamicListPageContent, staticTemplatePath);
+ RazorFormat.AddFileAndTemplate(staticTemplatePath, staticTemplateContent);
+ var dynamicPage = AddViewPage("DynamicListTpl", dynamicListPagePath, dynamicListPageContent, staticTemplatePath);
var expectedHtml = dynamicListPageContent
.Replace("@Model.FirstName", person.FirstName)
@@ -380,7 +376,7 @@ public void Can_Render_Razor_with_StaticMethods()
</table>
".NormalizeNewLines();
- razorFormat.DefaultBaseType = typeof(CustomViewBase<>);
+ RazorFormat.TemplateService.TemplateBaseType = typeof(CustomViewBase<>);
AddViewPage("HeaderLinks", "/path/to/page", headerTemplate);
@@ -420,7 +416,7 @@ public void Can_inherit_from_Generic_RazorViewPage_from_model_directive()
[Test]
public void Can_inherit_from_CustomViewPage_using_inherits_directive()
{
- var template = @"@inherits ServiceStack.ServiceHost.Tests.Formats_Razor.CustomMarkdownViewBase<ServiceStack.ServiceHost.Tests.Formats_Razor.Person>
+ var template = @"@inherits ServiceStack.ServiceHost.Tests.Formats_Razor.CustomViewBase<ServiceStack.ServiceHost.Tests.Formats_Razor.Person>
<h1>Generic View Page</h1>
<h2>Form fields</h2>
@@ -441,9 +437,7 @@ public void Can_inherit_from_CustomViewPage_using_inherits_directive()
</table>
".NormalizeNewLines();
- razorFormat.DefaultBaseType = typeof(CustomViewBase<>);
-
- var dynamicPage = AddViewPage("DynamicModelTpl", "/path/to/tpl", template);
+ var dynamicPage = AddViewPage("DynamicModelTpl", "/path/to/tpl", template);
var templateOutput = dynamicPage.RenderToHtml(templateArgs).NormalizeNewLines();
@@ -471,7 +465,7 @@ public void Can_Render_RazorPage_with_external_helper()
".NormalizeNewLines();
- razorFormat.DefaultBaseType = typeof(CustomViewBase<>);
+ RazorFormat.TemplateService.TemplateBaseType = typeof(CustomViewBase<>);
var dynamicPage = AddViewPage("DynamicModelTpl", "/path/to/tpl", template);
@@ -532,7 +526,7 @@ public void Can_Render_RazorPage_with_variable_statements()
</li>
</ul>".NormalizeNewLines();
- razorFormat.DefaultBaseType = typeof(CustomViewBase<>);
+ RazorFormat.TemplateService.TemplateBaseType = typeof(CustomViewBase<>);
var dynamicPage = AddViewPage("DynamicModelTpl", "/path/to/tpl", template);
@@ -667,7 +661,7 @@ public void Can_capture_Section_statements_and_store_them_in_Sections()
<p>Hello BELLOT, Demis</p>
".NormalizeNewLines();
- razorFormat.DefaultBaseType = typeof(CustomViewBase<>);
+ RazorFormat.TemplateService.TemplateBaseType = typeof(CustomViewBase<>);
var dynamicPage = AddViewPage("DynamicModelTpl", "/path/to/tpl", template);
@@ -717,7 +711,7 @@ public void Can_Render_RazorTemplate_with_section_and_variable_placeholders()
}
</ul>
}";
- var websiteTemplatePath = "/path/to/tpl";
+ var websiteTemplatePath = "websiteTemplate.cshtml";
var websiteTemplate = @"<!doctype html>
<html lang=""en-us"">
@@ -792,12 +786,12 @@ public void Can_Render_RazorTemplate_with_section_and_variable_placeholders()
</body>
</html>".NormalizeNewLines();
- razorFormat.DefaultBaseType = typeof(CustomViewBase<>);
+ RazorFormat.TemplateService.TemplateBaseType = typeof(CustomViewBase<>);
- razorFormat.AddTemplate(websiteTemplatePath, websiteTemplate);
+ RazorFormat.AddFileAndTemplate(websiteTemplatePath, websiteTemplate);
AddViewPage("DynamicModelTpl", "/path/to/page-tpl", template, websiteTemplatePath);
- var razorTemplate = razorFormat.ExecuteTemplate(
+ var razorTemplate = RazorFormat.ExecuteTemplate(
person, "DynamicModelTpl", websiteTemplatePath);
var templateOutput = razorTemplate.Result.NormalizeNewLines();
@@ -881,19 +875,22 @@ public void Can_Render_Static_RazorContentPage_that_populates_variable_and_displ
</body>
</html>".NormalizeNewLines();
- razorFormat.DefaultBaseType = typeof(CustomViewBase<>);
+ RazorFormat.TemplateService.TemplateBaseType = typeof(CustomViewBase<>);
- var websiteTemplatePath = "/path/to/tpl";
- razorFormat.AddTemplate(websiteTemplatePath, websiteTemplate);
+ var websiteTemplatePath = "websiteTemplate.cshtml";
+ RazorFormat.AddFileAndTemplate(websiteTemplatePath, websiteTemplate);
- var staticPage = new ViewPageRef(razorFormat,
- "/path/to/pagetpl", "StaticTpl", template, RazorPageType.ContentPage) {
- Template = websiteTemplatePath
+ var staticPage = new ViewPageRef(RazorFormat,
+ "pagetpl", "StaticTpl", template, RazorPageType.ContentPage) {
+ Service = RazorFormat.TemplateService,
+ Template = websiteTemplatePath,
};
- razorFormat.AddPage(staticPage);
+ RazorFormat.AddPage(staticPage);
+ RazorFormat.TemplateService.RegisterPage("pagetpl", "StaticTpl");
+ RazorFormat.TemplateProvider.CompileQueuedPages();
- var templateOutput = razorFormat.RenderStaticPage("/path/to/pagetpl").NormalizeNewLines();
+ var templateOutput = RazorFormat.RenderStaticPage("pagetpl").NormalizeNewLines();
Console.WriteLine(templateOutput);
Assert.That(templateOutput, Is.EqualTo(expectedHtml));
View
9 tests/ServiceStack.ServiceHost.Tests/ServiceStack.ServiceHost.Tests.csproj
@@ -115,6 +115,7 @@
<Compile Include="AppData\NorthwindCustomers.cs" />
<Compile Include="AppData\FormatHelpers.cs" />
<Compile Include="AppData\NorthwindHelpers.cs" />
+ <Compile Include="Formats\MarkdownFormatExtensions.cs" />
<Compile Include="Formats_Razor\CustomRazorBasePage.cs" />
<Compile Include="Formats_Razor\IntroductionExampleRazorTests.cs" />
<Compile Include="Formats_Razor\IntroductionLayoutRazorTests.cs" />
@@ -178,10 +179,10 @@
<None Include="Views\Template\Customer.md" />
<None Include="Views\Template\CustomerDetailsResponse.md" />
<None Include="AppData\Template\_Layout.cshtml" />
- <Content Include="AppData\Template\default.shtml" />
- <Content Include="Views\Template\alt-template.htm" />
- <None Include="Views\Template\_Layout.cshtml" />
- <Content Include="Views\Template\default.shtml" />
+ <Content Include="AppData\Template\_Layout.shtml" />
+ <Content Include="Views\Shared\alt-template.shtml" />
+ <None Include="Views\Shared\_Layout.cshtml" />
+ <Content Include="Views\Shared\_Layout.shtml" />
<Content Include="lib\Funq.dll" />
<Content Include="lib\hiro\Hiro.Containers.dll" />
<Content Include="lib\hiro\Hiro.Containers.XML" />
View
2 tests/ServiceStack.ServiceHost.Tests/ServiceStack.ServiceHost.Tests.csproj.user
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
- <ProjectView>ShowAllFiles</ProjectView>
+ <ProjectView>ProjectFiles</ProjectView>
<PublishUrlHistory />
<InstallUrlHistory />
<SupportUrlHistory />
View
0 ...eHost.Tests/Views/Template/_Layout.cshtml → ...iceHost.Tests/Views/Shared/_Layout.cshtml
File renamed without changes.
View
0 ...ceHost.Tests/Views/Template/default.shtml → ...viceHost.Tests/Views/Shared/_Layout.shtml
File renamed without changes.
View
0 ...ost.Tests/Views/Template/alt-template.htm → ...ost.Tests/Views/Shared/alt-template.shtml
File renamed without changes.
View
2 tests/ServiceStack.ServiceHost.Tests/Views/Template/Customer.md
@@ -1,5 +1,5 @@
@model ServiceStack.ServiceHost.Tests.AppData.Customer
-@template alt-template.htm
+@template alt-template
@helper Fmt: ServiceStack.ServiceHost.Tests.AppData.FormatHelpers
@helper Nwnd: ServiceStack.ServiceHost.Tests.AppData.NorthwindHelpers

0 comments on commit c49fe74

Please sign in to comment.