diff --git a/src/AuthSamples/build/dependencies.props b/src/AuthSamples/build/dependencies.props
index ac3ece8537..87bd618059 100644
--- a/src/AuthSamples/build/dependencies.props
+++ b/src/AuthSamples/build/dependencies.props
@@ -57,7 +57,7 @@
3.19.8
5.3.0
3.0.0-preview1-26907-05
- 3.0.0-preview-18579-0056
+ 3.0.0-preview.19053.2
15.6.1
3.0.1
3.0.0-alpha1-10772
diff --git a/src/Mvc/Mvc.sln b/src/Mvc/Mvc.sln
index d0cb0d402c..1dfdb97911 100644
--- a/src/Mvc/Mvc.sln
+++ b/src/Mvc/Mvc.sln
@@ -2,7 +2,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28414.68
-MinimumVisualStudioVersion = 15.0.26730.03
+MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{DAAE4C74-D06F-4874-A166-33305D2643CE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{32285FA4-6B46-4D6B-A840-2B13E4C8B58E}"
@@ -148,8 +148,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorBuildWebSite", "test\WebSites\RazorBuildWebSite\RazorBuildWebSite.csproj", "{BF8A3392-C3D2-4813-855A-E906564600E1}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorBuildWebSite.PrecompiledViews", "test\WebSites\RazorBuildWebSite.PrecompiledViews\RazorBuildWebSite.PrecompiledViews.csproj", "{856D7E25-E033-477D-9ABD-0B50CF428C80}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorBuildWebSite.Views", "test\WebSites\RazorBuildWebSite.Views\RazorBuildWebSite.Views.csproj", "{8916DDCA-EC2A-4193-B9F3-78CAA1A96D5A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Analyzers", "src\Microsoft.AspNetCore.Mvc.Analyzers\Microsoft.AspNetCore.Mvc.Analyzers.csproj", "{87A3E227-C45E-4141-A59F-402908E651FD}"
@@ -868,18 +866,6 @@ Global
{BF8A3392-C3D2-4813-855A-E906564600E1}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{BF8A3392-C3D2-4813-855A-E906564600E1}.Release|x86.ActiveCfg = Release|Any CPU
{BF8A3392-C3D2-4813-855A-E906564600E1}.Release|x86.Build.0 = Release|Any CPU
- {856D7E25-E033-477D-9ABD-0B50CF428C80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {856D7E25-E033-477D-9ABD-0B50CF428C80}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {856D7E25-E033-477D-9ABD-0B50CF428C80}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
- {856D7E25-E033-477D-9ABD-0B50CF428C80}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
- {856D7E25-E033-477D-9ABD-0B50CF428C80}.Debug|x86.ActiveCfg = Debug|Any CPU
- {856D7E25-E033-477D-9ABD-0B50CF428C80}.Debug|x86.Build.0 = Debug|Any CPU
- {856D7E25-E033-477D-9ABD-0B50CF428C80}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {856D7E25-E033-477D-9ABD-0B50CF428C80}.Release|Any CPU.Build.0 = Release|Any CPU
- {856D7E25-E033-477D-9ABD-0B50CF428C80}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
- {856D7E25-E033-477D-9ABD-0B50CF428C80}.Release|Mixed Platforms.Build.0 = Release|Any CPU
- {856D7E25-E033-477D-9ABD-0B50CF428C80}.Release|x86.ActiveCfg = Release|Any CPU
- {856D7E25-E033-477D-9ABD-0B50CF428C80}.Release|x86.Build.0 = Release|Any CPU
{8916DDCA-EC2A-4193-B9F3-78CAA1A96D5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8916DDCA-EC2A-4193-B9F3-78CAA1A96D5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8916DDCA-EC2A-4193-B9F3-78CAA1A96D5A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -1634,7 +1620,6 @@ Global
{F16CEE0D-A28E-43BD-802F-99BAFE4BA7CE} = {FDC66952-A3EA-4074-899E-C29816BF7C1F}
{7500B228-1769-4CFB-A571-3DFAC6678A06} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
{BF8A3392-C3D2-4813-855A-E906564600E1} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
- {856D7E25-E033-477D-9ABD-0B50CF428C80} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{8916DDCA-EC2A-4193-B9F3-78CAA1A96D5A} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{87A3E227-C45E-4141-A59F-402908E651FD} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
{E3E09D2F-1FCF-4396-9B09-5A62CA8CC831} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/CompiledViewDescriptor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/CompiledViewDescriptor.cs
index 213218c5cd..6d0213ea30 100644
--- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/CompiledViewDescriptor.cs
+++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/CompiledViewDescriptor.cs
@@ -21,6 +21,23 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
}
+ ///
+ /// Creates a new .
+ ///
+ /// The .
+ public CompiledViewDescriptor(RazorCompiledItem item)
+ {
+ if (item == null)
+ {
+ throw new ArgumentNullException(nameof(item));
+ }
+
+ Item = item;
+ ExpirationTokens = Array.Empty();
+ RelativePath = ViewPath.NormalizePath(item.Identifier);
+ }
+
+#pragma warning disable CS0618// Type or member is obsolete
///
/// Creates a new . At least one of or
/// must be non-null.
@@ -28,6 +45,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
/// The .
/// The .
public CompiledViewDescriptor(RazorCompiledItem item, RazorViewAttribute attribute)
+#pragma warning restore CS0618 // Type or member is obsolete
{
if (item == null && attribute == null)
{
@@ -44,7 +62,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
//
// In theory we could look at the 'Item.Kind' to determine what kind of thing we're dealing
// with, but for compat reasons we're basing it on ViewAttribute since that's what 2.0 had.
+#pragma warning disable CS0618 // Type or member is obsolete
ViewAttribute = attribute;
+#pragma warning restore CS0618 // Type or member is obsolete
// We don't have access to the file provider here so we can't check if the files
// even exist or what their checksums are. For now leave this empty, it will be updated
@@ -58,13 +78,17 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
///
public string RelativePath { get; set; }
+#pragma warning disable CS0618
+ // Type or member is obsolete
///
/// Gets or sets the decorating the view.
///
///
/// May be null.
///
+ [Obsolete("Use Item instead. RazorViewAttribute has been superseded by RazorCompiledItem and will not be used by the runtime.")]
public RazorViewAttribute ViewAttribute { get; set; }
+#pragma warning restore CS0618 // Type or member is obsolete
///
/// instances that indicate when this result has expired.
@@ -79,6 +103,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
///
/// Gets the type of the compiled item.
///
- public Type Type => Item?.Type ?? ViewAttribute?.ViewType;
+ public Type Type => Item?.Type;
}
}
\ No newline at end of file
diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorViewAttribute.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorViewAttribute.cs
index 1ac6aba09a..233edc6aa1 100644
--- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorViewAttribute.cs
+++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorViewAttribute.cs
@@ -5,6 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
{
+ [Obsolete("This attribute has been superseded by RazorCompiledItem and will not be used by the runtime.")]
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public class RazorViewAttribute : Attribute
{
diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/CompiledPageRouteModelProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/CompiledPageRouteModelProvider.cs
index 54b67eb1db..855fcb6d1a 100644
--- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/CompiledPageRouteModelProvider.cs
+++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/CompiledPageRouteModelProvider.cs
@@ -82,10 +82,6 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
{
return viewDescriptor.Item.Kind == RazorPageDocumentKind;
}
- else if (viewDescriptor.ViewAttribute != null)
- {
- return viewDescriptor.ViewAttribute is RazorPageAttribute;
- }
return false;
}
@@ -133,11 +129,6 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
internal static string GetRouteTemplate(CompiledViewDescriptor viewDescriptor)
{
- if (viewDescriptor.ViewAttribute != null)
- {
- return ((RazorPageAttribute)viewDescriptor.ViewAttribute).RouteTemplate;
- }
-
if (viewDescriptor.Item != null)
{
return viewDescriptor.Item.Metadata
diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/RazorPageAttribute.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/RazorPageAttribute.cs
index 900827a018..2fe3030064 100644
--- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/RazorPageAttribute.cs
+++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/RazorPageAttribute.cs
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc.Razor.Compilation;
namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
{
+ [Obsolete("This attribute has been superseded by RazorCompiledItem and will not be used by the runtime.")]
public class RazorPageAttribute : RazorViewAttribute
{
public RazorPageAttribute(string path, Type viewType, string routeTemplate)
diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorBuildTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorBuildTest.cs
index 08097d5224..e90c761c83 100644
--- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorBuildTest.cs
+++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorBuildTest.cs
@@ -17,30 +17,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
public HttpClient Client { get; }
- [Fact]
- public async Task PrecompiledPage_LocalPageWithDifferentContent_NotUsed()
- {
- // Act
- var response = await Client.GetAsync("http://localhost/Precompilation/Page");
- var responseBody = await response.Content.ReadAsStringAsync();
-
- // Assert
- Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- Assert.Equal("Hello from buildtime-compiled precompilation page!", responseBody.Trim());
- }
-
- [Fact]
- public async Task PrecompiledView_LocalViewWithDifferentContent_NotUsed()
- {
- // Act
- var response = await Client.GetAsync("http://localhost/Precompilation/View");
- var responseBody = await response.Content.ReadAsStringAsync();
-
- // Assert
- Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- Assert.Equal("Hello from buildtime-compiled precompilation view!", responseBody.Trim());
- }
-
[Fact(Skip = "https://github.com/aspnet/Mvc/issues/8753")]
public async Task Rzc_LocalPageWithDifferentContent_IsUsed()
{
@@ -66,7 +42,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
}
[Fact]
- public async Task RzcViewsArePreferredToPrecompiledViews()
+ public async Task RzcViewsArePreferredToRuntimeViews()
{
// Verifies that when two views have the same paths, the one compiled using rzc is preferred to the one from Precompilation.
// Act
diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Razor.Test/ApplicationParts/RazorCompiledItemFeatureProviderTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Razor.Test/ApplicationParts/RazorCompiledItemFeatureProviderTest.cs
index ffcc6ad8cf..de3b31d0b3 100644
--- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Razor.Test/ApplicationParts/RazorCompiledItemFeatureProviderTest.cs
+++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Razor.Test/ApplicationParts/RazorCompiledItemFeatureProviderTest.cs
@@ -41,16 +41,18 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
var item1 = Mock.Of(i => i.Identifier == "Item1" && i.Type == typeof(TestView));
var item2 = Mock.Of(i => i.Identifier == "Item2" && i.Type == typeof(TestPage));
- var attribute1 = new RazorViewAttribute("Item1", typeof(TestView));
- var attribute2 = new RazorViewAttribute("Item2", typeof(TestPage));
-
- var assembly = new TestAssembly(new[] { attribute1, attribute2 });
+ var assembly = new TestAssembly(new[]
+ {
+ new RazorCompiledItemAttribute(typeof(TestView), "mvc.1.0.razor-page", "Item1"),
+ new RazorCompiledItemAttribute(typeof(TestView), "mvc.1.0.razor-view", "Item1"),
+ });
var part1 = new AssemblyPart(assembly);
var part2 = new Mock();
part2
.As()
- .Setup(p => p.CompiledItems).Returns(new[] { item1, item2, });
+ .Setup(p => p.CompiledItems)
+ .Returns(new[] { item1, item2, });
var featureProvider = new RazorCompiledItemFeatureProvider();
var feature = new ViewsFeature();
diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Razor.Test/Compilation/DefaultRazorPageFactoryProviderTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Razor.Test/Compilation/DefaultRazorPageFactoryProviderTest.cs
index 4e35a4f838..c1b0b0c0d8 100644
--- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Razor.Test/Compilation/DefaultRazorPageFactoryProviderTest.cs
+++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Razor.Test/Compilation/DefaultRazorPageFactoryProviderTest.cs
@@ -3,6 +3,7 @@
using System;
using System.Threading.Tasks;
+using Microsoft.AspNetCore.Razor.Hosting;
using Microsoft.Extensions.Primitives;
using Moq;
using Xunit;
@@ -54,7 +55,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
var descriptor = new CompiledViewDescriptor
{
RelativePath = relativePath,
- ViewAttribute = new RazorViewAttribute(relativePath, typeof(TestRazorPage)),
+ Item = TestRazorCompiledItem.CreateForView(typeof(TestRazorPage), relativePath),
ExpirationTokens = expirationTokens,
};
var compilerCache = new Mock();
@@ -80,7 +81,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
var descriptor = new CompiledViewDescriptor
{
RelativePath = relativePath,
- ViewAttribute = new RazorViewAttribute(relativePath, typeof(TestRazorPage)),
+ Item = TestRazorCompiledItem.CreateForView(typeof(TestRazorPage), relativePath),
ExpirationTokens = Array.Empty(),
};
var viewCompiler = new Mock();
diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Razor.Test/Compilation/RazorViewCompilerTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Razor.Test/Compilation/RazorViewCompilerTest.cs
index ac26f8e66e..790efd95dd 100644
--- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.Razor.Test/Compilation/RazorViewCompilerTest.cs
+++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.Razor.Test/Compilation/RazorViewCompilerTest.cs
@@ -23,7 +23,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation
var result2 = await viewCompiler.CompileAsync(path);
// Assert
- Assert.Null(result1.ViewAttribute);
Assert.Empty(result1.ExpirationTokens);
}
diff --git a/src/Mvc/test/Microsoft.AspNetCore.Mvc.RazorPages.Test/ApplicationModels/CompiledPageRouteModelProviderTest.cs b/src/Mvc/test/Microsoft.AspNetCore.Mvc.RazorPages.Test/ApplicationModels/CompiledPageRouteModelProviderTest.cs
index c462f8edb5..c0cf96f38c 100644
--- a/src/Mvc/test/Microsoft.AspNetCore.Mvc.RazorPages.Test/ApplicationModels/CompiledPageRouteModelProviderTest.cs
+++ b/src/Mvc/test/Microsoft.AspNetCore.Mvc.RazorPages.Test/ApplicationModels/CompiledPageRouteModelProviderTest.cs
@@ -22,67 +22,16 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
public void OnProvidersExecuting_AddsModelsForCompiledViews()
{
// Arrange
- var descriptors = new[]
+ var items = new[]
{
- CreateVersion_2_0_Descriptor("/Pages/About.cshtml"),
- CreateVersion_2_0_Descriptor("/Pages/Home.cshtml", "some-prefix"),
- };
-
- var provider = CreateProvider(descriptors: descriptors);
- var context = new PageRouteModelProviderContext();
-
- // Act
- provider.OnProvidersExecuting(context);
-
- // Assert
- Assert.Collection(
- context.RouteModels,
- result =>
- {
- Assert.Equal("/Pages/About.cshtml", result.RelativePath);
- Assert.Equal("/About", result.ViewEnginePath);
- Assert.Collection(
- result.Selectors,
- selector => Assert.Equal("About", selector.AttributeRouteModel.Template));
- Assert.Collection(
- result.RouteValues.OrderBy(k => k.Key),
- kvp =>
- {
- Assert.Equal("page", kvp.Key);
- Assert.Equal("/About", kvp.Value);
- });
- },
- result =>
- {
- Assert.Equal("/Pages/Home.cshtml", result.RelativePath);
- Assert.Equal("/Home", result.ViewEnginePath);
- Assert.Collection(
- result.Selectors,
- selector => Assert.Equal("Home/some-prefix", selector.AttributeRouteModel.Template));
- Assert.Collection(
- result.RouteValues.OrderBy(k => k.Key),
- kvp =>
- {
- Assert.Equal("page", kvp.Key);
- Assert.Equal("/Home", kvp.Value);
- });
- });
- }
-
- [Fact] // 2.1 adds some additional metadata to the view descriptors. We want to make sure both versions work.
- public void OnProvidersExecuting_AddsModelsForCompiledViews_Version_2_1()
- {
- // Arrange
- var descriptors = new[]
- {
- CreateVersion_2_1_Descriptor("/Pages/About.cshtml"),
- CreateVersion_2_1_Descriptor("/Pages/Home.cshtml", metadata: new[]
+ TestRazorCompiledItem.CreateForPage("/Pages/About.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Pages/Home.cshtml", metadata: new[]
{
new RazorCompiledItemMetadataAttribute("RouteTemplate", "some-prefix"),
}),
};
- var provider = CreateProvider(descriptors: descriptors);
+ var provider = CreateProvider(items);
var context = new PageRouteModelProviderContext();
// Act
@@ -127,12 +76,15 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
public void OnProvidersExecuting_AddsModelsForCompiledAreaPages()
{
// Arrange
- var descriptors = new[]
+ var items = new[]
{
- CreateVersion_2_0_Descriptor("/Areas/Products/Files/About.cshtml"),
- CreateVersion_2_0_Descriptor("/Areas/Products/Pages/About.cshtml"),
- CreateVersion_2_0_Descriptor("/Areas/Products/Pages/Manage/Index.cshtml"),
- CreateVersion_2_0_Descriptor("/Areas/Products/Pages/Manage/Edit.cshtml", "{id}"),
+ TestRazorCompiledItem.CreateForPage("/Areas/Products/Files/About.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Areas/Products/Pages/About.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Areas/Products/Pages/Manage/Index.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Areas/Products/Pages/Manage/Edit.cshtml", metadata: new object[]
+ {
+ new RazorCompiledItemMetadataAttribute("RouteTemplate", "{id}"),
+ }),
};
var options = new RazorPagesOptions
@@ -141,7 +93,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
RootDirectory = "/Files",
};
- var provider = CreateProvider(options: options, descriptors: descriptors);
+ var provider = CreateProvider(items, options);
var context = new PageRouteModelProviderContext();
// Act
@@ -216,12 +168,12 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
public void OnProvidersExecuting_DoesNotAddAreaAndNonAreaRoutesForAPage()
{
// Arrange
- var descriptors = new[]
+ var items = new[]
{
- CreateVersion_2_0_Descriptor("/Areas/Accounts/Pages/Manage/Home.cshtml"),
- CreateVersion_2_0_Descriptor("/Areas/Accounts/Manage/Home.cshtml"),
- CreateVersion_2_0_Descriptor("/Areas/About.cshtml"),
- CreateVersion_2_0_Descriptor("/Contact.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Areas/Accounts/Pages/Manage/Home.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Areas/Accounts/Manage/Home.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Areas/About.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Contact.cshtml"),
};
var options = new RazorPagesOptions
@@ -229,7 +181,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
RootDirectory = "/",
};
- var provider = CreateProvider(options: options, descriptors: descriptors);
+ var provider = CreateProvider(items, options);
var context = new PageRouteModelProviderContext();
// Act
@@ -279,14 +231,17 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
public void OnProvidersExecuting_AddsMultipleSelectorsForIndexPage_WithIndexAtRoot()
{
// Arrange
- var descriptors = new[]
+ var items = new[]
{
- CreateVersion_2_0_Descriptor("/Pages/Index.cshtml"),
- CreateVersion_2_0_Descriptor("/Pages/Admin/Index.cshtml", "some-template"),
+ TestRazorCompiledItem.CreateForPage("/Pages/Index.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Pages/Admin/Index.cshtml", metadata: new object[]
+ {
+ new RazorCompiledItemMetadataAttribute("RouteTemplate", "some-template"),
+ }),
};
var options = new RazorPagesOptions { RootDirectory = "/" };
- var provider = CreateProvider(options: options, descriptors: descriptors);
+ var provider = CreateProvider(items, options);
var context = new PageRouteModelProviderContext();
// Act
@@ -319,13 +274,16 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
public void OnProvidersExecuting_AddsMultipleSelectorsForIndexPage()
{
// Arrange
- var descriptors = new[]
+ var items = new[]
{
- CreateVersion_2_0_Descriptor("/Pages/Index.cshtml"),
- CreateVersion_2_0_Descriptor("/Pages/Admin/Index.cshtml", "some-template"),
+ TestRazorCompiledItem.CreateForPage("/Pages/Index.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Pages/Admin/Index.cshtml", metadata: new object[]
+ {
+ new RazorCompiledItemMetadataAttribute("RouteTemplate", "some-template"),
+ }),
};
- var provider = CreateProvider(descriptors: descriptors);
+ var provider = CreateProvider(items);
var context = new PageRouteModelProviderContext();
// Act
@@ -358,13 +316,19 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
public void OnProvidersExecuting_AllowsRouteTemplatesWithOverridePattern()
{
// Arrange
- var descriptors = new[]
+ var items = new[]
{
- CreateVersion_2_0_Descriptor("/Pages/Index.cshtml", "~/some-other-prefix"),
- CreateVersion_2_0_Descriptor("/Pages/Home.cshtml", "/some-prefix"),
+ TestRazorCompiledItem.CreateForPage("/Pages/Index.cshtml", metadata: new object[]
+ {
+ new RazorCompiledItemMetadataAttribute("RouteTemplate", "~/some-other-prefix"),
+ }),
+ TestRazorCompiledItem.CreateForPage("/Pages/Home.cshtml", metadata: new object[]
+ {
+ new RazorCompiledItemMetadataAttribute("RouteTemplate", "/some-prefix"),
+ }),
};
- var provider = CreateProvider(descriptors: descriptors);
+ var provider = CreateProvider(items);
var context = new PageRouteModelProviderContext();
// Act
@@ -399,16 +363,16 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
// to a Razor Page added by a library.
// Arrange
- var descriptors = new[]
+ var items = new[]
{
// Page coming from the app
- CreateVersion_2_1_Descriptor("/Pages/About.cshtml"),
- CreateVersion_2_1_Descriptor("/Pages/Home.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Pages/About.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Pages/Home.cshtml"),
// Page coming from the app
- CreateVersion_2_1_Descriptor("/Pages/About.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Pages/About.cshtml"),
};
- var provider = CreateProvider(descriptors: descriptors);
+ var provider = CreateProvider(items);
var context = new PageRouteModelProviderContext();
// Act
@@ -433,13 +397,13 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
public void OnProvidersExecuting_AllowsRazorFilesWithUnderscorePrefix()
{
// Arrange
- var descriptors = new[]
+ var items = new[]
{
- CreateVersion_2_1_Descriptor("/Pages/_About.cshtml"),
- CreateVersion_2_1_Descriptor("/Pages/Home.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Pages/_About.cshtml"),
+ TestRazorCompiledItem.CreateForPage("/Pages/Home.cshtml"),
};
- var provider = CreateProvider(descriptors: descriptors);
+ var provider = CreateProvider(items);
var context = new PageRouteModelProviderContext();
// Act
@@ -480,42 +444,15 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
});
}
- [Fact]
- public void GetRouteTemplate_ReturnsPathFromRazorPageAttribute()
- {
- // Arrange
- var expected = "test";
- var descriptor = CreateVersion_2_0_Descriptor("/Pages/Home.cshtml", expected);
-
- // Act
- var result = CompiledPageRouteModelProvider.GetRouteTemplate(descriptor);
-
- // Assert
- Assert.Equal(expected, result);
- }
-
- [Fact]
- public void GetRouteTemplate_ReturnsNull_IfPageAttributeDoesNotHaveTemplate()
- {
- // Arrange
- var descriptor = CreateVersion_2_0_Descriptor("/Pages/Home.cshtml", routeTemplate: null);
-
- // Act
- var result = CompiledPageRouteModelProvider.GetRouteTemplate(descriptor);
-
- // Assert
- Assert.Null(result);
- }
-
[Fact]
public void GetRouteTemplate_ReturnsPathFromMetadataAttribute()
{
// Arrange
var expected = "test";
- var descriptor = CreateVersion_2_1_Descriptor("/Pages/About.cshtml", metadata: new object[]
+ var descriptor = new CompiledViewDescriptor(TestRazorCompiledItem.CreateForPage("/Pages/About.cshtml", metadata: new object[]
{
new RazorCompiledItemMetadataAttribute("RouteTemplate", expected),
- });
+ }));
// Act
var result = CompiledPageRouteModelProvider.GetRouteTemplate(descriptor);
@@ -528,7 +465,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
public void GetRouteTemplate_ReturnsNull_IfAttributeDoesNotExist()
{
// Arrange
- var descriptor = CreateVersion_2_1_Descriptor("/Pages/About.cshtml");
+ var descriptor = new CompiledViewDescriptor(TestRazorCompiledItem.CreateForPage("/Pages/About.cshtml"));
// Act
var result = CompiledPageRouteModelProvider.GetRouteTemplate(descriptor);
@@ -537,9 +474,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
Assert.Null(result);
}
- private TestCompiledPageRouteModelProvider CreateProvider(
- RazorPagesOptions options = null,
- IList descriptors = null)
+ private CompiledPageRouteModelProvider CreateProvider(IList items, RazorPagesOptions options = null)
{
options = options ?? new RazorPagesOptions();
@@ -548,31 +483,14 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels
Options.Create(options),
NullLogger.Instance);
- provider.Descriptors.AddRange(descriptors ?? Array.Empty());
+ for (var i = 0; i < items.Count; i++)
+ {
+ provider.Descriptors.Add(new CompiledViewDescriptor(items[i]));
+ }
return provider;
}
- private static CompiledViewDescriptor CreateVersion_2_0_Descriptor(string path, string routeTemplate = "")
- {
- return new CompiledViewDescriptor
- {
- RelativePath = path,
- ViewAttribute = new RazorPageAttribute(path, typeof(object), routeTemplate),
- };
- }
-
- private static CompiledViewDescriptor CreateVersion_2_1_Descriptor(
- string path,
- object[] metadata = null)
- {
- return new CompiledViewDescriptor
- {
- RelativePath = path,
- Item = new TestRazorCompiledItem(typeof(object), "mvc.1.0.razor-page", path, metadata ?? Array.Empty