-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #346 from SimonCropp/verify
add verify example
- Loading branch information
Showing
20 changed files
with
295 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,4 +38,6 @@ node_modules | |
*launchSettings.json | ||
*.orig | ||
nuget | ||
RazorLight.Sandbox/ | ||
RazorLight.Sandbox/ | ||
|
||
*.received.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
tests/RazorLight.Tests/Assets/Files/LayoutWithRequiredSection.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<layout> | ||
@RenderBody() | ||
</layout> | ||
|
||
<section> | ||
@RenderSection("header", true) | ||
</section> | ||
|
||
<section> | ||
@RenderSection("message", false) | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@using RazorLight | ||
@model RazorLight.Tests.IntegrationTests.TestViewModel | ||
|
||
This is a nested partial which attempts to render Partial.cshtml | ||
|
||
@{ | ||
await IncludeAsync("Partial", Model); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@using RazorLight | ||
@model RazorLight.Tests.IntegrationTests.TestViewModel | ||
|
||
This included partial template is used to render data of the passed view model: @Model.Name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@using RazorLight | ||
@model RazorLight.Tests.IntegrationTests.TestViewModel | ||
@{ | ||
Layout = "LayoutWithSection.cshtml"; | ||
} | ||
|
||
@section section { | ||
The content of the section | ||
} | ||
|
||
We are rendering this with @Model.Name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@using RazorLight | ||
@model RazorLight.Tests.IntegrationTests.TestViewModel | ||
@{ | ||
Layout = "LayoutWithRequiredSection.cshtml"; | ||
} | ||
|
||
@section header { | ||
Header of a @Model.Name page | ||
} | ||
|
||
@section message { | ||
await IncludeAsync("Partial", Model) | ||
} | ||
|
||
|
||
We are rendering this with @Model.Name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@using RazorLight | ||
@model RazorLight.Tests.IntegrationTests.TestViewModel | ||
@{ | ||
Layout = "LayoutWithRequiredSection.cshtml"; | ||
} | ||
|
||
@section message { | ||
Message | ||
} | ||
|
||
We are rendering this with @Model.Name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@using RazorLight | ||
@model RazorLight.Tests.IntegrationTests.TestViewModel | ||
|
||
We are rendering this with @Model.Name | ||
|
||
@{ | ||
await IncludeAsync("Partial", Model); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@using RazorLight | ||
@model RazorLight.Tests.IntegrationTests.TestViewModel | ||
@{ | ||
Layout = "LayoutWithRequiredSection.cshtml"; | ||
} | ||
|
||
@section header { | ||
Header of a @Model.Name page | ||
} | ||
|
||
@section message { | ||
await IncludeAsync("NestedPartial", Model); | ||
} | ||
|
||
|
||
We are rendering this with @Model.Name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@using RazorLight | ||
@model RazorLight.Tests.IntegrationTests.TestViewModel | ||
|
||
@{ | ||
await IncludeAsync("NestedPartial", Model); | ||
} |
5 changes: 5 additions & 0 deletions
5
...ration/RendererCommonCasesTests.Should_Fail_When_Required_Section_Is_Missing.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
Message: 'Section header is not defined', | ||
Data: {}, | ||
Source: 'RazorLight' | ||
} |
5 changes: 5 additions & 0 deletions
5
...rLight.Tests/Integration/RendererCommonCasesTests.Should_Render_IncludeAsync.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
We are rendering this with RazorLight | ||
|
||
|
||
This included partial template is used to render data of the passed view model: RazorLight |
6 changes: 6 additions & 0 deletions
6
...Tests/Integration/RendererCommonCasesTests.Should_Render_Nested_IncludeAsync.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
|
||
This is a nested partial which attempts to render Partial.cshtml | ||
|
||
|
||
This included partial template is used to render data of the passed view model: RazorLight |
19 changes: 19 additions & 0 deletions
19
...ommonCasesTests.Should_Render_RequiredSections_That_Have_Nested_IncludeAsync.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<layout> | ||
|
||
|
||
|
||
|
||
We are rendering this with RazorLight | ||
</layout> | ||
|
||
<section> | ||
|
||
Header of a RazorLight page | ||
|
||
</section> | ||
|
||
<section> | ||
|
||
await IncludeAsync("NestedPartial", Model); | ||
|
||
</section> |
11 changes: 11 additions & 0 deletions
11
...sts/Integration/RendererCommonCasesTests.Should_Render_Section_And_ViewModel.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<layout> | ||
|
||
|
||
We are rendering this with RazorLight | ||
</layout> | ||
|
||
<section> | ||
|
||
The content of the section | ||
|
||
</section> |
19 changes: 19 additions & 0 deletions
19
...ntegration/RendererCommonCasesTests.Should_Render_Sections_With_IncludeAsync.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<layout> | ||
|
||
|
||
|
||
|
||
We are rendering this with RazorLight | ||
</layout> | ||
|
||
<section> | ||
|
||
Header of a RazorLight page | ||
|
||
</section> | ||
|
||
<section> | ||
|
||
await IncludeAsync("Partial", Model) | ||
|
||
</section> |
131 changes: 131 additions & 0 deletions
131
tests/RazorLight.Tests/Integration/RendererCommonCasesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
| ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using RazorLight.Compilation; | ||
using VerifyXunit; | ||
using Xunit; | ||
|
||
namespace RazorLight.Tests.IntegrationTests | ||
{ | ||
public class TestViewModel | ||
{ | ||
public string Name { get; set; } | ||
|
||
public int NumberOfItems { get; set; } | ||
} | ||
|
||
[UsesVerify] | ||
public class RendererCommonCasesTests | ||
{ | ||
|
||
[Fact()] | ||
public async Task Should_Render_Section_And_ViewModel() | ||
{ | ||
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
|
||
var engine = new RazorLightEngineBuilder() | ||
.UseFileSystemProject(Path.Combine(path, "Assets", "Files")) | ||
.Build(); | ||
|
||
var model = new TestViewModel | ||
{ | ||
Name = "RazorLight", | ||
NumberOfItems = 100 | ||
}; | ||
var renderedResult = await engine.CompileRenderAsync("template4.cshtml", model); | ||
await Verifier.Verify(renderedResult); | ||
} | ||
|
||
[Fact()] | ||
public async Task Should_Render_Sections_With_IncludeAsync() | ||
{ | ||
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
|
||
var engine = new RazorLightEngineBuilder() | ||
.UseFileSystemProject(Path.Combine(path, "Assets", "Files")) | ||
.Build(); | ||
|
||
var model = new TestViewModel | ||
{ | ||
Name = "RazorLight", | ||
NumberOfItems = 200 | ||
}; | ||
var renderedResult = await engine.CompileRenderAsync("template5.cshtml", model); | ||
await Verifier.Verify(renderedResult); | ||
} | ||
|
||
[Fact()] | ||
public async Task Should_Fail_When_Required_Section_Is_Missing() | ||
{ | ||
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
|
||
var engine = new RazorLightEngineBuilder() | ||
.UseFileSystemProject(Path.Combine(path, "Assets", "Files")) | ||
.Build(); | ||
|
||
var model = new TestViewModel | ||
{ | ||
Name = "RazorLight", | ||
NumberOfItems = 300 | ||
}; | ||
var exception = await Assert.ThrowsAsync<InvalidOperationException>(async () => await engine.CompileRenderAsync("template6.cshtml", model)); | ||
await Verifier.Verify(exception); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_Render_IncludeAsync() | ||
{ | ||
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
|
||
var engine = new RazorLightEngineBuilder() | ||
.UseFileSystemProject(Path.Combine(path, "Assets", "Files")) | ||
.Build(); | ||
|
||
var model = new TestViewModel | ||
{ | ||
Name = "RazorLight", | ||
NumberOfItems = 400 | ||
}; | ||
var renderedResult = await engine.CompileRenderAsync("template7.cshtml", model); | ||
await Verifier.Verify(renderedResult); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_Render_Nested_IncludeAsync() | ||
{ | ||
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
|
||
var engine = new RazorLightEngineBuilder() | ||
.UseFileSystemProject(Path.Combine(path, "Assets", "Files")) | ||
.Build(); | ||
|
||
var model = new TestViewModel | ||
{ | ||
Name = "RazorLight", | ||
NumberOfItems = 400 | ||
}; | ||
var renderedResult = await engine.CompileRenderAsync("template9.cshtml", model); | ||
await Verifier.Verify(renderedResult); | ||
} | ||
|
||
[Fact()] | ||
public async Task Should_Render_RequiredSections_That_Have_Nested_IncludeAsync() | ||
{ | ||
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
|
||
var engine = new RazorLightEngineBuilder() | ||
.UseFileSystemProject(Path.Combine(path, "Assets", "Files")) | ||
.Build(); | ||
|
||
var model = new TestViewModel | ||
{ | ||
Name = "RazorLight", | ||
NumberOfItems = 400 | ||
}; | ||
var renderedResult = await engine.CompileRenderAsync("template8.cshtml", model); | ||
await Verifier.Verify(renderedResult); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters