This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update default Razor search paths to include ~/[PagesRoot]/Shared
Fixes #6604
- Loading branch information
Showing
14 changed files
with
207 additions
and
10 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
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
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
142 changes: 142 additions & 0 deletions
142
...soft.AspNetCore.Mvc.RazorPages.Test/Internal/RazorPagesRazorViewEngineOptionsSetupTest.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,142 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc.Razor; | ||
using Microsoft.AspNetCore.Mvc.Razor.Internal; | ||
using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal | ||
{ | ||
public class RazorPagesRazorViewEngineOptionsSetupTest | ||
{ | ||
[Fact] | ||
public void Configure_AddsPageViewLocationFormats_WhenPagesRootIsAppRoot() | ||
{ | ||
// Arrange | ||
var expected = new[] | ||
{ | ||
"/{1}/{0}.cshtml", | ||
"/Shared/{0}.cshtml", | ||
"/Views/Shared/{0}.cshtml", | ||
}; | ||
|
||
var razorPagesOptions = new RazorPagesOptions | ||
{ | ||
RootDirectory = "/" | ||
}; | ||
var viewEngineOptions = GetViewEngineOptions(); | ||
var setup = new RazorPagesRazorViewEngineOptionsSetup( | ||
new TestOptionsManager<RazorPagesOptions>(razorPagesOptions)); | ||
|
||
// Act | ||
setup.Configure(viewEngineOptions); | ||
|
||
// Assert | ||
Assert.Equal(expected, viewEngineOptions.PageViewLocationFormats); | ||
} | ||
|
||
[Fact] | ||
public void Configure_AddsPageViewLocationFormats_WithDefaultPagesRoot() | ||
{ | ||
// Arrange | ||
var expected = new[] | ||
{ | ||
"/Pages/{1}/{0}.cshtml", | ||
"/Pages/Shared/{0}.cshtml", | ||
"/Views/Shared/{0}.cshtml", | ||
}; | ||
|
||
var razorPagesOptions = new RazorPagesOptions(); | ||
var viewEngineOptions = GetViewEngineOptions(); | ||
var setup = new RazorPagesRazorViewEngineOptionsSetup( | ||
new TestOptionsManager<RazorPagesOptions>(razorPagesOptions)); | ||
|
||
// Act | ||
setup.Configure(viewEngineOptions); | ||
|
||
// Assert | ||
Assert.Equal(expected, viewEngineOptions.PageViewLocationFormats); | ||
} | ||
|
||
[Fact] | ||
public void Configure_AddsSharedPagesDirectoryToViewLocationFormats() | ||
{ | ||
// Arrange | ||
var expected = new[] | ||
{ | ||
"/Views/{1}/{0}.cshtml", | ||
"/Views/Shared/{0}.cshtml", | ||
"/PagesRoot/Shared/{0}.cshtml", | ||
}; | ||
|
||
var razorPagesOptions = new RazorPagesOptions | ||
{ | ||
RootDirectory = "/PagesRoot", | ||
}; | ||
var viewEngineOptions = GetViewEngineOptions(); | ||
var setup = new RazorPagesRazorViewEngineOptionsSetup( | ||
new TestOptionsManager<RazorPagesOptions>(razorPagesOptions)); | ||
|
||
// Act | ||
setup.Configure(viewEngineOptions); | ||
|
||
// Assert | ||
Assert.Equal(expected, viewEngineOptions.ViewLocationFormats); | ||
} | ||
|
||
[Fact] | ||
public void Configure_AddsSharedPagesDirectoryToAreaViewLocationFormats() | ||
{ | ||
// Arrange | ||
var expected = new[] | ||
{ | ||
"/Areas/{2}/Views/{1}/{0}.cshtml", | ||
"/Areas/{2}/Views/Shared/{0}.cshtml", | ||
"/Views/Shared/{0}.cshtml", | ||
"/PagesRoot/Shared/{0}.cshtml", | ||
}; | ||
|
||
var razorPagesOptions = new RazorPagesOptions | ||
{ | ||
RootDirectory = "/PagesRoot", | ||
}; | ||
var viewEngineOptions = GetViewEngineOptions(); | ||
var setup = new RazorPagesRazorViewEngineOptionsSetup( | ||
new TestOptionsManager<RazorPagesOptions>(razorPagesOptions)); | ||
|
||
// Act | ||
setup.Configure(viewEngineOptions); | ||
|
||
// Assert | ||
Assert.Equal(expected, viewEngineOptions.AreaViewLocationFormats); | ||
} | ||
|
||
[Fact] | ||
public void Configure_RegistersPageViewLocationExpander() | ||
{ | ||
// Arrange | ||
var viewEngineOptions = GetViewEngineOptions(); | ||
var setup = new RazorPagesRazorViewEngineOptionsSetup(new TestOptionsManager<RazorPagesOptions>()); | ||
|
||
// Act | ||
setup.Configure(viewEngineOptions); | ||
|
||
// Assert | ||
Assert.Collection( | ||
viewEngineOptions.ViewLocationExpanders, | ||
expander => Assert.IsType<PageViewLocationExpander>(expander)); | ||
} | ||
|
||
private static RazorViewEngineOptions GetViewEngineOptions() | ||
{ | ||
var defaultSetup = new RazorViewEngineOptionsSetup(Mock.Of<IHostingEnvironment>()); | ||
var options = new RazorViewEngineOptions(); | ||
defaultSetup.Configure(options); | ||
|
||
return options; | ||
} | ||
} | ||
} |
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 @@ | ||
@Html.Partial("_FileInShared) |
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,2 @@ | ||
@page | ||
@Html.Partial("_FileInShared") |
1 change: 1 addition & 0 deletions
1
test/WebSites/RazorPagesWebSite/Pages/Shared/_FileInShared.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 @@ | ||
Hello from Pages/Shared |
1 change: 1 addition & 0 deletions
1
test/WebSites/RazorPagesWebSite/Views/Shared/_FileInShared.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 @@ | ||
@{ throw new Exception("This file should not be processed"); } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@{ throw new Exception("This file should not be processed"); } |
1 change: 1 addition & 0 deletions
1
test/WebSites/RazorWebSite/Pages/Shared/_SharedFromPages.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 @@ | ||
Hello from Pages/Shared |
1 change: 1 addition & 0 deletions
1
test/WebSites/RazorWebSite/Views/ViewEngine/SearchInPages.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 @@ | ||
@Html.Partial("_SharedFromPages") |