Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit c49fe74091908d0439b434afa884f8554650d25f 1 parent 9ea5df4
Demis Bellot mythz authored

Showing 32 changed files with 457 additions and 158 deletions. Show diff stats Hide diff stats

  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
BIN  lib/ServiceStack.OrmLite.SqlServer.dll
Binary file not shown
BIN  lib/ServiceStack.OrmLite.Sqlite.dll
Binary file not shown
BIN  lib/ServiceStack.OrmLite.dll
Binary file not shown
BIN  lib/ServiceStack.OrmLite.pdb
Binary file not shown
32 src/ServiceStack.Razor/RazorFormat.cs
@@ -75,7 +75,7 @@ public static bool IsRegistered
75 75
76 76 public Dictionary<string, Type> RazorExtensionBaseTypes { get; set; }
77 77
78   - readonly TemplateProvider templateProvider = new TemplateProvider(DefaultTemplateName);
  78 + public TemplateProvider TemplateProvider { get; set; }
79 79
80 80 public Type DefaultBaseType
81 81 {
@@ -115,6 +115,11 @@ public RazorFormat()
115 115 {"cshtml", typeof(ViewPage<>) },
116 116 {"rzr", typeof(ViewPage<>) },
117 117 };
  118 + this.TemplateProvider = new TemplateProvider(DefaultTemplateName) {
  119 + CompileInParallel = true,
  120 + CompileWithNoOfThreads = Environment.ProcessorCount * 2,
  121 + };
  122 + this.VirtualPathProvider = EndpointHost.VirtualPathProvider;
118 123 }
119 124
120 125 public void Register(IAppHost appHost)
@@ -134,7 +139,7 @@ public void Configure(IAppHost appHost)
134 139 foreach (var ns in EndpointHostConfig.RazorNamespaces)
135 140 TemplateNamespaces.Add(ns);
136 141
137   - this.ReplaceTokens = new Dictionary<string, string>(appHost.Config.MarkdownReplaceTokens);
  142 + this.ReplaceTokens = appHost.Config.MarkdownReplaceTokens ?? new Dictionary<string, string>();
138 143 if (!appHost.Config.WebHostUrl.IsNullOrEmpty())
139 144 this.ReplaceTokens["~/"] = appHost.Config.WebHostUrl.WithTrailingSlash();
140 145
@@ -362,6 +367,21 @@ public ViewPageRef GetViewPage(string pageName)
362 367 return razorPage;
363 368 }
364 369
  370 + private ViewPageRef GetTemplatePage(string pageName)
  371 + {
  372 + ViewPageRef razorPage;
  373 +
  374 + var key = "Views/Shared/{0}.cshtml".Fmt(pageName);
  375 + MasterPageTemplates.TryGetValue(key, out razorPage);
  376 + if (razorPage != null)
  377 + {
  378 + razorPage.EnsureCompiled();
  379 + return razorPage;
  380 + }
  381 + return null;
  382 + }
  383 +
  384 +
365 385 private void RegisterRazorPages(string razorSearchPath)
366 386 {
367 387 foreach (var page in FindRazorPagesFn(razorSearchPath))
@@ -371,7 +391,7 @@ private void RegisterRazorPages(string razorSearchPath)
371 391
372 392 try
373 393 {
374   - templateProvider.CompileQueuedPages();
  394 + TemplateProvider.CompileQueuedPages();
375 395 }
376 396 catch (Exception ex)
377 397 {
@@ -404,7 +424,7 @@ public IEnumerable<ViewPageRef> FindRazorPages(string dirPath)
404 424 templateService.RegisterPage(csHtmlFile.VirtualPath, pageName);
405 425
406 426 var templatePath = pageType == RazorPageType.ContentPage
407   - ? templateProvider.GetTemplatePath(csHtmlFile.Directory)
  427 + ? TemplateProvider.GetTemplatePath(csHtmlFile.Directory)
408 428 : null;
409 429
410 430 yield return new ViewPageRef(this, csHtmlFile.VirtualPath, pageName, pageContents, pageType) {
@@ -423,7 +443,7 @@ public void AddPage(ViewPageRef page)
423 443 {
424 444 try
425 445 {
426   - templateProvider.QueuePageToCompile(page);
  446 + TemplateProvider.QueuePageToCompile(page);
427 447 AddViewPage(page);
428 448 }
429 449 catch (Exception ex)
@@ -518,7 +538,7 @@ public ViewPageRef AddTemplate(string templatePath, string templateContents)
518 538 try
519 539 {
520 540 //template.Compile();
521   - templateProvider.QueuePageToCompile(template);
  541 + TemplateProvider.QueuePageToCompile(template);
522 542 return template;
523 543 }
524 544 catch (Exception ex)
7 src/ServiceStack.Razor/Templating/TemplateService.ServiceStack.cs
@@ -85,6 +85,13 @@ public IRazorTemplate GetTemplate(string name)
85 85 if (!templateCache.TryGetValue(name, out instance))
86 86 {
87 87 var view = viewEngine.GetView(name);
  88 + if (view == null)
  89 + {
  90 + if (name == RazorFormat.DefaultTemplate)
  91 + return null;
  92 +
  93 + throw new Exception("Could not find template " + name);
  94 + }
88 95 view.Compile(); //compiling adds to templateCache
89 96
90 97 templateCache.TryGetValue(name, out instance);
9 src/ServiceStack/Html/TemplateProvider.cs
@@ -11,8 +11,8 @@ namespace ServiceStack.Html
11 11 {
12 12 public class TemplateProvider
13 13 {
14   - public static bool CompileInParallel = false;
15   - public static int CompileWithNoOfThreads = Environment.ProcessorCount * 2;
  14 + public bool CompileInParallel { get; set; }
  15 + public int CompileWithNoOfThreads { get; set; }
16 16
17 17 private static readonly ILog Log = LogManager.GetLogger(typeof(TemplateProvider));
18 18
@@ -21,6 +21,7 @@ public class TemplateProvider
21 21 public TemplateProvider(string defaultTemplateName)
22 22 {
23 23 this.defaultTemplateName = defaultTemplateName;
  24 + this.CompileInParallel = false;
24 25 }
25 26
26 27 readonly Dictionary<string, IVirtualFile> templatePathsFound = new Dictionary<string, IVirtualFile>(StringComparer.InvariantCultureIgnoreCase);
@@ -78,9 +79,9 @@ public void QueuePageToCompile(IViewPage pageToCompile)
78 79 public void CompileQueuedPages()
79 80 {
80 81 Log.InfoFormat("Starting to compile {0}/{1} pages, {2}",
81   - compilePages.Count, priorityCompilePages.Count,
  82 + compilePages.Count, priorityCompilePages.Count,
82 83 CompileInParallel ? "In Parallel" : "Sequentially");
83   -
  84 +
84 85 if (CompileInParallel)
85 86 {
86 87 var threadsToRun = Math.Min(CompileWithNoOfThreads, compilePages.Count);
1  src/ServiceStack/ServiceStack.csproj
@@ -182,6 +182,7 @@
182 182 <Compile Include="VirtualPath\FileSystemVirtualDirectory.cs" />
183 183 <Compile Include="VirtualPath\FileSystemVirtualFile.cs" />
184 184 <Compile Include="VirtualPath\FileSystemVirtualPathProvider.cs" />
  185 + <Compile Include="VirtualPath\InMemoryVirtualPathProvider.cs" />
185 186 <Compile Include="WebHost.Endpoints\AppHostExtensions.cs" />
186 187 <Compile Include="Markdown\CachedExpressionCompiler.cs" />
187 188 <Compile Include="Markdown\DynamicTypeGenerator .cs" />
15 src/ServiceStack/VirtualPath/AbstractVirtualPathProviderBase.cs
@@ -43,17 +43,14 @@ public virtual IVirtualFile GetFile(string virtualPath)
43 43 public virtual string GetFileHash(string virtualPath)
44 44 {
45 45 var f = GetFile(virtualPath);
46   - return GetFileHash(f); ;
47   - }
48   -
49   - public virtual string GetFileHash(IVirtualFile virtualFile)
50   - {
51   - if (virtualFile == null)
52   - return String.Empty;
53   -
54   - return virtualFile.GetFileHash();
  46 + return GetFileHash(f);
55 47 }
56 48
  49 + public virtual string GetFileHash(IVirtualFile virtualFile)
  50 + {
  51 + return virtualFile == null ? string.Empty : virtualFile.GetFileHash();
  52 + }
  53 +
57 54 public virtual IVirtualDirectory GetDirectory(string virtualPath)
58 55 {
59 56 return RootDirectory.GetDirectory(virtualPath);
162 src/ServiceStack/VirtualPath/InMemoryVirtualPathProvider.cs
... ... @@ -0,0 +1,162 @@
  1 +using System;
  2 +using System.Collections.Generic;
  3 +using System.IO;
  4 +using System.Linq;
  5 +using ServiceStack.Text;
  6 +using ServiceStack.WebHost.Endpoints;
  7 +
  8 +namespace ServiceStack.VirtualPath
  9 +{
  10 + /// <summary>
  11 + /// In Memory repository for files. Useful for testing.
  12 + /// </summary>
  13 + public class InMemoryVirtualPathProvider : AbstractVirtualPathProviderBase
  14 + {
  15 + public InMemoryVirtualPathProvider(IAppHost appHost)
  16 + : base(appHost)
  17 + {
  18 + this.rootDirectory = new InMemoryVirtualDirectory(this);
  19 + }
  20 +
  21 + public InMemoryVirtualDirectory rootDirectory;
  22 +
  23 + public override IVirtualDirectory RootDirectory
  24 + {
  25 + get { return rootDirectory; }
  26 + }
  27 +
  28 + public override string VirtualPathSeparator
  29 + {
  30 + get { return "/"; }
  31 + }
  32 +
  33 + public override string RealPathSeparator
  34 + {
  35 + get { return "/"; }
  36 + }
  37 +
  38 + protected override void Initialize()
  39 + {
  40 + }
  41 +
  42 + public void AddFile(string filePath, string contents)
  43 + {
  44 + rootDirectory.AddFile(filePath, contents);
  45 + }
  46 +
  47 + public override IVirtualFile GetFile(string virtualPath)
  48 + {
  49 + return rootDirectory.GetFile(virtualPath)
  50 + ?? base.GetFile(virtualPath);
  51 + }
  52 + }
  53 +
  54 + public class InMemoryVirtualDirectory : AbstractVirtualDirectoryBase
  55 + {
  56 + public InMemoryVirtualDirectory(IVirtualPathProvider owningProvider)
  57 + : base(owningProvider)
  58 + {
  59 + this.files = new List<InMemoryVirtualFile>();
  60 + this.dirs = new List<InMemoryVirtualDirectory>();
  61 + this.DirLastModified = DateTime.MinValue;
  62 + }
  63 +
  64 + public InMemoryVirtualDirectory(IVirtualPathProvider owningProvider, IVirtualDirectory parentDirectory)
  65 + : base(owningProvider, parentDirectory) {}
  66 +
  67 + public DateTime DirLastModified { get; set; }
  68 + public override DateTime LastModified
  69 + {
  70 + get { return DirLastModified; }
  71 + }
  72 +
  73 + public List<InMemoryVirtualFile> files;
  74 +
  75 + public override IEnumerable<IVirtualFile> Files
  76 + {
  77 + get { return files.Cast<IVirtualFile>(); }
  78 + }
  79 +
  80 + public List<InMemoryVirtualDirectory> dirs;
  81 +
  82 + public override IEnumerable<IVirtualDirectory> Directories
  83 + {
  84 + get { return dirs.Cast<IVirtualDirectory>(); }
  85 + }
  86 +
  87 + public string DirName { get; set; }
  88 + public override string Name
  89 + {
  90 + get { return DirName; }
  91 + }
  92 +
  93 + public override IVirtualFile GetFile(string virtualPath)
  94 + {
  95 + return files.FirstOrDefault(x => x.FilePath == virtualPath);
  96 + }
  97 +
  98 + public override IEnumerator<IVirtualNode> GetEnumerator()
  99 + {
  100 + throw new NotImplementedException();
  101 + }
  102 +
  103 + protected override IVirtualFile GetFileFromBackingDirectoryOrDefault(string fileName)
  104 + {
  105 + return files.FirstOrDefault(x => x.FilePath == fileName);
  106 + }
  107 +
  108 + protected override IEnumerable<IVirtualFile> GetMatchingFilesInDir(string globPattern)
  109 + {
  110 + throw new NotImplementedException();
  111 + }
  112 +
  113 + protected override IVirtualDirectory GetDirectoryFromBackingDirectoryOrDefault(string directoryName)
  114 + {
  115 + return null;
  116 + }
  117 +
  118 + static readonly char[] DirSeps = new[] { '\\', '/' };
  119 + public void AddFile(string filePath, string contents)
  120 + {
  121 + this.files.Add(new InMemoryVirtualFile(VirtualPathProvider, this) {
  122 + FilePath = filePath,
  123 + FileName = filePath.Split(DirSeps).Last(),
  124 + TextContents = contents,
  125 + });
  126 + }
  127 + }
  128 +
  129 + public class InMemoryVirtualFile : AbstractVirtualFileBase
  130 + {
  131 + public InMemoryVirtualFile(IVirtualPathProvider owningProvider, IVirtualDirectory directory)
  132 + : base(owningProvider, directory)
  133 + {
  134 + this.FileLastModified = DateTime.MinValue;
  135 + }
  136 +
  137 + public string FilePath { get; set; }
  138 +
  139 + public string FileName { get; set; }
  140 + public override string Name
  141 + {
  142 + get { return FileName; }
  143 + }
  144 +
  145 + public DateTime FileLastModified { get; set; }
  146 + public override DateTime LastModified
  147 + {
  148 + get { return FileLastModified; }
  149 + }
  150 +
  151 + public string TextContents { get; set; }
  152 +
  153 + public byte[] ByteContents { get; set; }
  154 +
  155 + public override Stream OpenRead()
  156 + {
  157 + return new MemoryStream(ByteContents ?? (TextContents ?? "").ToUtf8Bytes());
  158 + }
  159 + }
  160 +
  161 +
  162 +}
6 src/ServiceStack/WebHost.Endpoints/Formats/MarkdownFormat.cs
@@ -80,9 +80,10 @@ public MarkdownFormat()
80 80 this.MarkdownGlobalHelpers = new Dictionary<string, Type>();
81 81 this.FindMarkdownPagesFn = FindMarkdownPages;
82 82 this.MarkdownReplaceTokens = new Dictionary<string, string>();
  83 + this.VirtualPathProvider = EndpointHost.VirtualPathProvider;
83 84 }
84 85
85   - static readonly char[] DirSeps = new[] { '\\', '/' };
  86 + internal static readonly char[] DirSeps = new[] { '\\', '/' };
86 87 static HashSet<string> catchAllPathsNotFound = new HashSet<string>();
87 88
88 89 public void Register(IAppHost appHost)
@@ -525,6 +526,9 @@ private string RenderInTemplateIfAny(MarkdownPage markdownPage, Dictionary<strin
525 526
526 527 if (markdownTemplate == null)
527 528 {
  529 + if (templatePath == null)
  530 + return pageHtml;
  531 +
528 532 throw new Exception("No template found for page: " + markdownPage.FilePath);
529 533 }
530 534 }
5 src/ServiceStack/WebHost.Endpoints/Support/Markdown/MarkdownHandler.cs
@@ -18,8 +18,9 @@ public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes,
18 18 var contentPage = MarkdownPage;
19 19 if (contentPage == null)
20 20 {
21   - var pageFilePath = this.FilePath.WithoutExtension();
22   - contentPage = MarkdownFormat.GetContentPage(pageFilePath);
  21 + contentPage = MarkdownFormat.GetContentPage(
  22 + this.FilePath.WithoutExtension(),
  23 + PathInfo.TrimStart(MarkdownFormat.DirSeps).WithoutExtension());
23 24 }
24 25 if (contentPage == null)
25 26 {
29 src/ServiceStack/WebHost.Endpoints/Support/Markdown/TextBlock.cs
@@ -939,15 +939,26 @@ private void Prepare(MarkdownPage markdownPage)
939 939 "Unable to resolve type '{0}'. Check type exists in Config.MarkdownBaseType or Page.Markdown.MarkdownGlobalHelpers",
940 940 typePropertyName));
941 941
942   - var mi = type.GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance);
943   - if (mi == null)
944   - {
945   - mi = HtmlHelper.GetMethod(methodName);
946   - if (mi == null)
947   - throw new ArgumentException("Unable to resolve method '" + methodExpr + "' on type " + type.Name);
948   - }
949   -
950   - base.ReturnType = mi.ReturnType;
  942 + try
  943 + {
  944 + var mi = methodName == "Partial"
  945 + ? type.GetMethods(BindingFlags.Public | BindingFlags.Instance)
  946 + .FirstOrDefault(m => m.GetParameters().Length == 2 && m.Name == methodName)
  947 + : type.GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance);
  948 +
  949 + if (mi == null)
  950 + {
  951 + mi = HtmlHelper.GetMethod(methodName);
  952 + if (mi == null)
  953 + throw new ArgumentException("Unable to resolve method '" + methodExpr + "' on type " + type.Name);
  954 + }
  955 +
  956 + base.ReturnType = mi.ReturnType;
  957 + }
  958 + catch (Exception ex)
  959 + {
  960 + throw;
  961 + }
951 962
952 963 var isMemberExpr = Condition.IndexOf('(') != -1;
953 964 if (!isMemberExpr || this.WriteRawHtml)
4 tests/RazorRockstars.Console.Files/RazorRockstars.Console.Files.csproj
@@ -66,7 +66,9 @@
66 66 <Compile Include="RazorRockstars_FilesTests.cs" />
67 67 </ItemGroup>
68 68 <ItemGroup>
69   - <None Include="App.config" />
  69 + <None Include="App.config">
  70 + <SubType>Designer</SubType>
  71 + </None>
70 72 <None Include="TypedModelNoController.cshtml">
71 73 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
72 74 </None>
12 tests/ServiceStack.Common.Tests/StringExtensionTests.cs
@@ -106,11 +106,13 @@ public void SafeVarName_strips_illegal_chars()
106 106
107 107 [Test]
108 108 public void Glob_finds_right_strings()
109   - {
110   - var input = new[] {"Foo, Boo, Hoo, Baz"};
111   - var expected = input.Where(s => s.EndsWith("oo")).ToArray();
112   -
113   - Assert.AreEqual(expected, input.Select(s => s.Glob("*oo")));
  109 + {
  110 + var input = new[] { "Foo", "Boo", "Hoo", "Baz" }.ToList();
  111 + var expected = input.Where(s => s.EndsWith("oo")).ToList();
  112 +
  113 + var actual = input.Where(s => s.Glob("*oo")).ToList();
  114 +
  115 + Assert.That(actual, Is.EquivalentTo(expected));
114 116 }
115 117 }
116 118 }
0  ....ServiceHost.Tests/AppData/Template/default.shtml → ....ServiceHost.Tests/AppData/Template/_Layout.shtml
File renamed without changes
19 tests/ServiceStack.ServiceHost.Tests/Formats/IntroductionLayoutTests.cs
@@ -4,6 +4,9 @@
4 4 using NUnit.Framework;
5 5 using ServiceStack.Html;
6 6 using ServiceStack.Markdown;
  7 +using ServiceStack.ServiceInterface.Testing;
  8 +using ServiceStack.VirtualPath;
  9 +using ServiceStack.WebHost.Endpoints;
7 10 using ServiceStack.WebHost.Endpoints.Formats;
8 11 using ServiceStack.WebHost.Endpoints.Support.Markdown;
9 12
@@ -41,6 +44,14 @@ public MvcHtmlString Field(string fieldName, string fieldValue)
41 44 [TestFixture]
42 45 public class IntroductionLayoutTests : MarkdownTestBase
43 46 {
  47 + private InMemoryVirtualPathProvider pathProvider;
  48 +
  49 + [TestFixtureSetUp]
  50 + public void TestFixtureSetUp()
  51 + {
  52 + EndpointHost.VirtualPathProvider = pathProvider = new InMemoryVirtualPathProvider(new BasicAppHost());
  53 + }
  54 +
44 55 [Test]
45 56 public void Simple_Layout_Example()
46 57 {
@@ -65,7 +76,7 @@ public void Simple_Layout_Example()
65 76 </html>".NormalizeNewLines();
66 77
67 78 var pageTemplate =
68   -@"@Layout ~/websiteTemplate
  79 +@"@Layout websiteTemplate
69 80
70 81 # About this Site
71 82
@@ -112,7 +123,7 @@ public void Simple_Layout_Example()
112 123 markdownFormat.AddPage(
113 124 new MarkdownPage(markdownFormat, @"C:\path\to\page-tpl", PageName, pageTemplate));
114 125
115   - markdownFormat.AddTemplate(@"C:\path\to\websiteTemplate", websiteTemplate);
  126 + markdownFormat.AddFileAndTemplate(@"websiteTemplate", websiteTemplate);
116 127
117 128 var html = markdownFormat.RenderDynamicPageHtml(PageName);
118 129
@@ -154,7 +165,7 @@ public void Layout_MasterPage_Scenarios_Adding_Sections()
154 165 </html>".NormalizeNewLines();
155 166
156 167 var pageTemplate =
157   -@"@Layout ~/websiteTemplate
  168 +@"@Layout websiteTemplate
158 169
159 170 # About this Site
160 171
@@ -225,7 +236,7 @@ public void Layout_MasterPage_Scenarios_Adding_Sections()
225 236 markdownFormat.AddPage(
226 237 new MarkdownPage(markdownFormat, @"C:\path\to\page-tpl", PageName, pageTemplate));
227 238
228   - markdownFormat.AddTemplate(@"C:\path\to\websiteTemplate", websiteTemplate);
  239 + markdownFormat.AddFileAndTemplate(@"websiteTemplate", websiteTemplate);
229 240
230 241 var html = markdownFormat.RenderDynamicPageHtml(PageName);
231 242
23 tests/ServiceStack.ServiceHost.Tests/Formats/MarkdownFormatExtensions.cs
... ... @@ -0,0 +1,23 @@
  1 +using ServiceStack.VirtualPath;
  2 +using ServiceStack.WebHost.Endpoints.Formats;
  3 +using ServiceStack.WebHost.Endpoints.Support.Markdown;
  4 +
  5 +namespace ServiceStack.ServiceHost.Tests.Formats
  6 +{
  7 + public static class MarkdownFormatExtensions
  8 + {
  9 + public static void AddFileAndPage(this MarkdownFormat markdown, MarkdownPage markdownPage)
  10 + {
  11 + var pathProvider = (InMemoryVirtualPathProvider)markdown.VirtualPathProvider;
  12 + pathProvider.AddFile(markdownPage.FilePath, markdownPage.Contents);
  13 + markdown.AddPage(markdownPage);
  14 + }
  15 +
  16 + public static void AddFileAndTemplate(this MarkdownFormat markdown, string filePath, string contents)
  17 + {
  18 + var pathProvider = (InMemoryVirtualPathProvider)markdown.VirtualPathProvider;
  19 + pathProvider.AddFile(filePath, contents);
  20 + markdown.AddTemplate(filePath, contents);
  21 + }
  22 + }
  23 +}
12 tests/ServiceStack.ServiceHost.Tests/Formats/MarkdownFormatTests.cs
@@ -4,7 +4,9 @@
4 4 using NUnit.Framework;
5 5 using ServiceStack.Common;
6 6 using ServiceStack.Common.Utils;
  7 +using ServiceStack.ServiceInterface.Testing;
7 8 using ServiceStack.Text;
  9 +using ServiceStack.VirtualPath;
8 10 using ServiceStack.WebHost.Endpoints.Formats;
9 11
10 12 namespace ServiceStack.ServiceHost.Tests.Formats
@@ -55,7 +57,9 @@ public void TestFixtureSetUp()
55 57 [SetUp]
56 58 public void OnBeforeEachTest()
57 59 {
58   - markdownFormat = new MarkdownFormat();
  60 + markdownFormat = new MarkdownFormat {
  61 + VirtualPathProvider = new FileSystemVirtualPathProvider(new BasicAppHost(), "~/".MapProjectPath()),
  62 + };
59 63 }
60 64
61 65 [Test]
@@ -79,7 +83,7 @@ public void Can_load_all_markdown_files()
79 83 public void Can_Render_StaticPage()
80 84 {
81 85 markdownFormat.RegisterMarkdownPages("~/".MapProjectPath());
82   - var html = markdownFormat.RenderStaticPageHtml("~/AppData/NoTemplate/Static".MapProjectPath());
  86 + var html = markdownFormat.RenderStaticPageHtml("AppData/NoTemplate/Static");
83 87
84 88 Assert.That(html, Is.Not.Null);
85 89 Assert.That(html, Is.StringStarting("<h1>Static Markdown template</h1>"));
@@ -89,9 +93,9 @@ public void Can_Render_StaticPage()
89 93 public void Can_Render_StaticPage_WithTemplate()
90 94 {
91 95 markdownFormat.RegisterMarkdownPages("~/".MapProjectPath());
92   - var html = markdownFormat.RenderStaticPageHtml("~/AppData/Template/StaticTpl".MapProjectPath());
  96 + var html = markdownFormat.RenderStaticPageHtml("AppData/Template/StaticTpl");
93 97
94   - Console.WriteLine(html);
  98 + html.Print();
95 99
96 100 Assert.That(html, Is.Not.Null);
97 101 Assert.That(html, Is.StringStarting("<!doctype html>"));
10 tests/ServiceStack.ServiceHost.Tests/Formats/MarkdownTestBase.cs
... ... @@ -1,4 +1,6 @@
1 1 using System.Collections.Generic;
  2 +using ServiceStack.ServiceInterface.Testing;
  3 +using ServiceStack.VirtualPath;
2 4 using ServiceStack.WebHost.Endpoints.Formats;
3 5 using ServiceStack.WebHost.Endpoints.Support.Markdown;
4 6
@@ -11,12 +13,14 @@ public class MarkdownTestBase
11 13
12 14 public MarkdownFormat Create(string websiteTemplate, string pageTemplate)
13 15 {
14   - var markdownFormat = new MarkdownFormat();
  16 + var markdownFormat = new MarkdownFormat {
  17 + VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost())
  18 + };
15 19
16   - markdownFormat.AddTemplate("/path/to/websitetpl", websiteTemplate);
  20 + markdownFormat.AddFileAndTemplate("websiteTemplate", websiteTemplate);
17 21 markdownFormat.AddPage(
18 22 new MarkdownPage(markdownFormat, "/path/to/tpl", PageName, pageTemplate) {
19   - Template = "/path/to/websitetpl",
  23 + Template = "websiteTemplate",
20 24 });
21 25
22 26 return markdownFormat;
27 tests/ServiceStack.ServiceHost.Tests/Formats/TemplateTests.cs
@@ -7,6 +7,9 @@
7 7 using ServiceStack.Common.Utils;
8 8 using ServiceStack.Html;
9 9 using ServiceStack.Markdown;
  10 +using ServiceStack.ServiceInterface.Testing;
  11 +using ServiceStack.Text;
  12 +using ServiceStack.VirtualPath;
10 13 using ServiceStack.WebHost.Endpoints.Formats;
11 14 using ServiceStack.WebHost.Endpoints.Support.Markdown;
12 15
@@ -41,7 +44,9 @@ public void TestFixtureSetUp()
41 44 [SetUp]
42 45 public void OnBeforeEachTest()
43 46 {
44   - markdownFormat = new MarkdownFormat();
  47 + markdownFormat = new MarkdownFormat {
  48 + VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost())
  49 + };
45 50 templateArgs = new Dictionary<string, object> { { MarkdownPage.ModelName, person } };
46 51 }
47 52
@@ -360,7 +365,7 @@ public void Can_Render_Markdown_with_StaticMethods()
360 365 {"Ext", typeof(CustomMarkdownHelper)}
361 366 };
362 367
363   - markdownFormat.RegisterMarkdownPage(new MarkdownPage(markdownFormat,
  368 + markdownFormat.RegisterMarkdownPage(new MarkdownPage(markdownFormat,
364 369 "/path/to/page", "HeaderLinks", headerTemplate));
365 370
366 371 var dynamicPage = new MarkdownPage(markdownFormat, "/path/to/tpl", "DynamicIfTpl", template);
@@ -369,7 +374,7 @@ public void Can_Render_Markdown_with_StaticMethods()
369 374 var templateOutput = dynamicPage.RenderToHtml(templateArgs);
370 375 templateOutput = templateOutput.Replace("\r\n", "\n");
371 376
372   - Console.WriteLine(templateOutput);
  377 + templateOutput.Print();
373 378 Assert.That(templateOutput, Is.EqualTo(expectedHtml));
374 379 }
375 380
@@ -523,6 +528,7 @@ public void Can_Render_page_to_Markdown_only()
523 528 ### Breadcrumbs
524 529 @Combine("" / "", Model.FirstName, Model.LastName)
525 530
  531 +
526 532 ### Menus
527 533 @foreach (var link in Model.Links) {
528 534 - @link.Name - @link.Href
@@ -577,10 +583,12 @@ public void Can_Render_Markdown_with_variable_statements()
577 583
578 584 Hello @Upper(lastName), @Model.FirstName
579 585
  586 +
580 587 ### Breadcrumbs
581 588 @Combine("" / "", Model.FirstName, lastName)
582 589
583 590 @var links = Model.Links
  591 +
584 592 ### Menus
585 593 @foreach (var link in links) {
586 594 - @link.Name - @link.Href
@@ -594,6 +602,7 @@ public void Can_Render_Markdown_with_variable_statements()
594 602
595 603 Hello BELLOT, Demis
596 604
  605 +
597 606 ### Breadcrumbs
598 607 Demis / Bellot
599 608
@@ -883,11 +892,11 @@ public void Can_Render_Template_with_section_and_variable_placeholders()
883 892 </body>
884 893 </html>".Replace("\r\n", "\n");
885 894
886   - markdownFormat.AddTemplate("/path/to/tpl", websiteTemplate);
  895 + markdownFormat.AddFileAndTemplate("websiteTemplate", websiteTemplate);
887 896
888 897 markdownFormat.AddPage(
889 898 new MarkdownPage(markdownFormat, "/path/to/page-tpl", "DynamicModelTpl", template) {
890   - Template = "/path/to/tpl"
  899 + Template = "websiteTemplate"
891 900 });
892 901
893 902 var templateOutput = markdownFormat.RenderDynamicPageHtml("DynamicModelTpl", person);
@@ -970,14 +979,14 @@ public void Can_Render_Static_ContentPage_that_populates_variable_and_displayed_
970 979
971 980 markdownFormat.MarkdownBaseType = typeof(CustomMarkdownViewBase);
972 981
973   - markdownFormat.AddTemplate("/path/to/tpl", websiteTemplate);
  982 + markdownFormat.AddFileAndTemplate("websiteTemplate", websiteTemplate);
974 983
975 984 markdownFormat.RegisterMarkdownPage(
976   - new MarkdownPage(markdownFormat, "/path/to/pagetpl", "StaticTpl", template, MarkdownPageType.ContentPage) {
977   - Template = "/path/to/tpl"
  985 + new MarkdownPage(markdownFormat, "pagetpl", "StaticTpl", template, MarkdownPageType.ContentPage) {
  986 + Template = "websiteTemplate"
978 987 });
979 988
980   - var templateOutput = markdownFormat.RenderStaticPage("/path/to/pagetpl", true);
  989 + var templateOutput = markdownFormat.RenderStaticPage("pagetpl", true);
981 990
982 991 Console.WriteLine(templateOutput);
983 992 Assert.That(templateOutput, Is.EqualTo(expectedHtml));
8 tests/ServiceStack.ServiceHost.Tests/Formats/ViewTests.cs
@@ -36,7 +36,9 @@ public void TestFixtureSetUp()
36 36 public void OnBeforeEachTest()
37 37 {
38 38 appHost = new AppHost();
39   - markdownFormat = new MarkdownFormat();
  39 + markdownFormat = new MarkdownFormat {
  40 + VirtualPathProvider = appHost.VirtualPathProvider
  41 + };
40 42 markdownFormat.Register(appHost);
41 43 }
42 44
@@ -52,7 +54,7 @@ public AppHost()
52 54 this.ResponseFilters = new List<Action<IHttpRequest, IHttpResponse, object>>();
53 55 this.ViewEngines = new List<IViewEngine>();
54 56 this.CatchAllHandlers = new List<HttpHandlerResolverDelegate>();
55   - this.VirtualPathProvider = new FileSystemVirtualPathProvider(this);
  57 + this.VirtualPathProvider = new FileSystemVirtualPathProvider(this, "~".MapProjectPath());
56 58 }
57 59
58 60 public void Register<T>(T instance)
@@ -181,7 +183,7 @@ public void Does_serve_dynamic_view_HTML_page_with_ALT_template()
181 183 {
182 184 var html = GetHtml(response.Customer);
183 185
184   - Console.WriteLine(html);
  186 + html.Print();
185 187 //File.WriteAllText("~/AppData/TestsResults/Customer.htm".MapAbsolutePath(), html);
186 188
187 189 Assert.That(html.StartsWith("<!doctype html>"));
21 tests/ServiceStack.ServiceHost.Tests/Formats_Razor/IntroductionExampleRazorTests.cs
... ... @@ -1,8 +1,13 @@
1 1 using System;
2 2 using System.Collections.Generic;
3 3 using NUnit.Framework;
  4 +using ServiceStack.Common.Utils;
4 5 using ServiceStack.Razor;
5 6 using ServiceStack.ServiceHost.Tests.Formats;
  7 +using ServiceStack.ServiceInterface.Testing;
  8 +using ServiceStack.Text;
  9 +using ServiceStack.VirtualPath;
  10 +using ServiceStack.WebHost.Endpoints;
6 11
7 12 namespace ServiceStack.ServiceHost.Tests.Formats_Razor
8 13 {
@@ -36,10 +41,18 @@ public void TestFixtureSetUp()
36 41 new Product("DVD", 11.99m),
37 42 };
38 43 productArgs = new { products = products };
39   -
40   - var mvcRazorFormat = new RazorFormat { DefaultBaseType = typeof(CustomRazorBasePage<>) };
41   - mvcRazorFormat.Init();
42 44 }
  45 +
  46 + [SetUp]
  47 + public void SetUp()
  48 + {
  49 + RazorFormat = new RazorFormat {
  50 + DefaultBaseType = typeof(CustomRazorBasePage<>),
  51 + VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost()),
  52 + TemplateProvider = { CompileInParallel = false },
  53 + };
  54 + RazorFormat.Init();
  55 + }
43 56
44 57 [Test]
45 58 public void Basic_Razor_Example()
@@ -190,7 +203,7 @@ public void HTML_encoding()
190 203
191 204 var html = RenderToHtml(template, new { stringContainingHtml = "<span>html</span>"});
192 205
193   - Console.WriteLine(html);
  206 + html.Print();
194 207 Assert.That(html, Is.EqualTo(expectedHtml));
195 208 }
196 209
38 tests/ServiceStack.ServiceHost.Tests/Formats_Razor/IntroductionLayoutRazorTests.cs
@@ -5,6 +5,8 @@
5 5 using ServiceStack.Html;
6 6 using ServiceStack.Razor;
7 7 using ServiceStack.ServiceHost.Tests.Formats;
  8 +using ServiceStack.ServiceInterface.Testing;
  9 +using ServiceStack.VirtualPath;
8 10
9 11 namespace ServiceStack.ServiceHost.Tests.Formats_Razor
10 12 {
@@ -40,25 +42,15 @@ public MvcHtmlString Field(string fieldName, string fieldValue)
40 42 [TestFixture]
41 43 public class IntroductionLayoutRazorTests : RazorTestBase
42 44 {
43   - private RazorFormat razorFormat;
44   -
45 45 [SetUp]
46 46 public void OnBeforeEachTest()
47 47 {
48   - razorFormat = new RazorFormat();
49   - razorFormat.Init();
50   - }
51   -
52   - private ViewPageRef AddViewPage(string pageName, string pagePath, string pageContents, string templatePath = null)
53   - {
54   - var dynamicPage = new ViewPageRef(razorFormat,
55   - pagePath, pageName, pageContents, RazorPageType.ViewPage) {
56   - Template = templatePath
57   - };
58   -
59   - razorFormat.AddPage(dynamicPage);
60   - return dynamicPage;
61   - }
  48 + base.RazorFormat = new RazorFormat {
  49 + VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost()),
  50 + TemplateProvider = { CompileInParallel = false },
  51 + };
  52 + base.RazorFormat.Init();
  53 + }
62 54
63 55 [Test]
64 56 public void Simple_Layout_Example()
@@ -84,7 +76,7 @@ public void Simple_Layout_Example()
84 76 </html>".NormalizeNewLines();
85 77
86 78 var pageTemplate =
87   -@"@{ Layout = ""C:\\path\\to\\websiteTemplate""; }
  79 +@"@{ Layout = ""websiteTemplate.cshtml""; }
88 80
89 81 <h1>About this Site</h1>
90 82
@@ -127,8 +119,7 @@ public void Simple_Layout_Example()
127 119 </html>".NormalizeNewLines();
128 120
129 121
130   - var websiteTemplatePath = @"C:\path\to\websiteTemplate";
131   - razorFormat.AddTemplate(websiteTemplatePath, websiteTemplate);
  122 + RazorFormat.AddFileAndTemplate("websiteTemplate.cshtml", websiteTemplate);
132 123 var dynamicPage = AddViewPage(PageName, @"C:\path\to\page-tpl", pageTemplate);
133 124
134 125 var template = dynamicPage.RenderToHtml();
@@ -240,11 +231,10 @@ public void Layout_MasterPage_Scenarios_Adding_Sections()
240 231 </html>".NormalizeNewLines();
241 232
242 233
243   - var websiteTemplatePath = @"C:\path\to\websiteTemplate";
244   - razorFormat.AddTemplate(websiteTemplatePath, websiteTemplate);
  234 + RazorFormat.AddFileAndTemplate("websiteTemplate.cshtml", websiteTemplate);
245 235
246 236 var dynamicPage = AddViewPage(
247   - PageName, @"C:\path\to\page-tpl", pageTemplate, websiteTemplatePath);
  237 + PageName, @"C:\path\to\page-tpl.cshtml", pageTemplate, "websiteTemplate.cshtml");
248 238
249 239
250 240 var html = dynamicPage.RenderToHtml();
@@ -320,7 +310,7 @@ public void Using_External_HTML_Helpers()
320 310 new Product("DVD", 11.99m),
321 311 };
322 312
323   - razorFormat.DefaultBaseType = typeof(CustomViewBase<>);
  313 + RazorFormat.TemplateService.TemplateBaseType = typeof(CustomViewBase<>);
324 314
325 315 var html = RenderToHtml(pageTemplate, products);
326 316
@@ -347,7 +337,7 @@ public void Using_Custom_base_class()
347 337
348 338 </fieldset>".NormalizeNewLines();
349 339
350   - razorFormat.DefaultBaseType = typeof(CustomBaseClass<>);
  340 + RazorFormat.DefaultBaseType = typeof(CustomBaseClass<>);
351 341
352 342 var html = RenderToHtml(pageTemplate, new Product("Pen", 1.99m));
353 343
77 tests/ServiceStack.ServiceHost.Tests/Formats_Razor/RazorTestBase.cs
... ... @@ -1,53 +1,90 @@
1 1 using System.Collections.Generic;
2 2 using ServiceStack.Razor;
  3 +using ServiceStack.VirtualPath;
3 4
4 5 namespace ServiceStack.ServiceHost.Tests.Formats_Razor
5 6 {
6   - public class RazorTestBase
  7 + public static class MarkdownFormatExtensions
  8 + {
  9 + public static void AddFileAndView(this RazorFormat razorFormat, ViewPageRef viewPage)
  10 + {
  11 + var pathProvider = (InMemoryVirtualPathProvider)razorFormat.VirtualPathProvider;
  12 + pathProvider.AddFile(viewPage.FilePath, viewPage.Contents);
  13 + razorFormat.AddPage(viewPage);
  14 + }
  15 +
  16 + public static void AddFileAndTemplate(this RazorFormat razorFormat, string filePath, string contents)
  17 + {
  18 + var pathProvider = (InMemoryVirtualPathProvider)razorFormat.VirtualPathProvider;
  19 + pathProvider.AddFile(filePath, contents);
  20 + razorFormat.AddTemplate(filePath, contents);
  21 + }
  22 + }
  23 +
  24 + public class RazorTestBase
7 25 {
8 26 public const string TemplateName = "Template";
9 27 protected const string PageName = "Page";
  28 + protected RazorFormat RazorFormat;
10 29
11   - public RazorFormat Create(string websiteTemplate, string pageTemplate)
  30 + public RazorFormat AddPage(string websiteTemplate, string pageTemplate)
12 31 {
13   - var razorFormat = new RazorFormat();
14   -
15   - razorFormat.AddTemplate("/path/to/websitetpl", websiteTemplate);
16   - razorFormat.AddPage(
17   - new ViewPageRef(razorFormat, "/path/to/tpl", PageName, pageTemplate) {
18   - Template = "/path/to/websitetpl",
  32 + RazorFormat.AddTemplate("websiteTemplate", websiteTemplate);
  33 + RazorFormat.AddPage(
  34 + new ViewPageRef(RazorFormat, "/path/to/tpl", PageName, pageTemplate) {
  35 + Template = "websiteTemplate",
19 36 });
20 37
21   - return razorFormat;
  38 + return RazorFormat;
22 39 }
23 40
24   - public RazorFormat Create(string pageTemplate)
  41 + public RazorFormat AddPage(string pageTemplate)
25 42 {
26   - var razorFormat = new RazorFormat();
27   - razorFormat.AddPage(
28   - new ViewPageRef(razorFormat, "/path/to/tpl", PageName, pageTemplate));
  43 + RazorFormat.AddPage(
  44 + new ViewPageRef(RazorFormat, "/path/to/tpl", PageName, pageTemplate) {
  45 + Service = RazorFormat.TemplateService
  46 + });
  47 +
  48 + RazorFormat.TemplateService.RegisterPage("/path/to/tpl", PageName);
  49 + RazorFormat.TemplateProvider.CompileQueuedPages();
29 50
30   - return razorFormat;
  51 + return RazorFormat;
31 52 }
32 53
  54 + protected ViewPageRef AddViewPage(string pageName, string pagePath, string pageContents, string templatePath = null)
  55 + {
  56 + var dynamicPage = new ViewPageRef(RazorFormat,
  57 + pagePath, pageName, pageContents, RazorPageType.ViewPage) {
  58 + Template = templatePath,
  59 + Service = RazorFormat.TemplateService
  60 + };
  61 +
  62 + RazorFormat.AddPage(dynamicPage);
  63 +
  64 + RazorFormat.TemplateService.RegisterPage(pagePath, pageName);
  65 + RazorFormat.TemplateProvider.CompileQueuedPages();
  66 +
  67 + return dynamicPage;
  68 + }
  69 +
33 70 public string RenderToHtml(string pageTemplate, Dictionary<string, object> scopeArgs)
34 71 {
35   - var razorFormat = Create(pageTemplate);
36   - var template = razorFormat.ExecuteTemplate(scopeArgs, PageName, null);
  72 + AddPage(pageTemplate);
  73 + var template = RazorFormat.ExecuteTemplate(scopeArgs, PageName, null);
37 74 return template.Result;
38 75 }
39 76
40 77 public string RenderToHtml(string pageTemplate, Dictionary<string, object> scopeArgs, string websiteTemplate)
41 78 {
42   - var razorFormat = Create(pageTemplate);
43   - var template = razorFormat.ExecuteTemplate(scopeArgs, PageName, websiteTemplate);
  79 + AddPage(pageTemplate);
  80 + var template = RazorFormat.ExecuteTemplate(scopeArgs, PageName, websiteTemplate);
44 81 return template.Result;
45 82 }
46 83
47 84 public string RenderToHtml<T>(string pageTemplate, T model)
48 85 {
49   - var razorFormat = Create(pageTemplate);
50   - var template = razorFormat.ExecuteTemplate(model, PageName, null);
  86 + AddPage(pageTemplate);
  87 + var template = RazorFormat.ExecuteTemplate(model, PageName, null);
51 88 return template.Result;
52 89 }
53 90 }
85 tests/ServiceStack.ServiceHost.Tests/Formats_Razor/TemplateTests.cs
@@ -9,6 +9,9 @@
9 9 using ServiceStack.Markdown;
10 10 using ServiceStack.Razor;
11 11 using ServiceStack.ServiceHost.Tests.Formats;
  12 +using ServiceStack.ServiceInterface.Testing;
  13 +using ServiceStack.Text;
  14 +using ServiceStack.VirtualPath;
12 15
13 16 namespace ServiceStack.ServiceHost.Tests.Formats_Razor
14 17 {
@@ -97,7 +100,7 @@ public MvcHtmlString InlineBlock(string content, string id)
97 100 }
98 101
99 102 [TestFixture]
100   - public class RazorTemplateTests
  103 + public class RazorTemplateTests : RazorTestBase
101 104 {
102 105 string staticTemplatePath;
103 106 string staticTemplateContent;
@@ -106,7 +109,6 @@ public class RazorTemplateTests
106 109 string dynamicListPagePath;
107 110