Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public override Task<CompiledPageActionDescriptor> LoadAsync(PageActionDescripto
throw new ArgumentNullException(nameof(actionDescriptor));
}

if (actionDescriptor is CompiledPageActionDescriptor compiledPageActionDescriptor)
{
// It's possible for some code paths of PageLoaderMatcherPolicy to invoke LoadAsync with an instance
// of CompiledPageActionDescriptor. In that case, we'll return the instance as-is.
compiledPageActionDescriptor.CompiledPageActionDescriptorTask ??= Task.FromResult(compiledPageActionDescriptor);
return compiledPageActionDescriptor.CompiledPageActionDescriptorTask;
}

var task = actionDescriptor.CompiledPageActionDescriptorTask;

if (task != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ public async Task LoadAsync_IsUniquePerPageDescriptor()
},
};


var transformer = new Mock<RoutePatternTransformer>();
transformer
.Setup(t => t.SubstituteRequiredValues(It.IsAny<RoutePattern>(), It.IsAny<object>()))
Expand Down Expand Up @@ -335,6 +334,29 @@ public async Task LoadAsync_IsUniquePerPageDescriptor()
Assert.NotSame(result1, result2);
}

[Fact]
public async Task LoadAsync_CompiledPageActionDescriptor_ReturnsSelf()
{
// Arrange
var mvcOptions = Options.Create(new MvcOptions());
var endpointFactory = new ActionEndpointFactory(Mock.Of<RoutePatternTransformer>(), Enumerable.Empty<IRequestDelegateFactory>());
var loader = new DefaultPageLoader(
new[] { Mock.Of<IPageApplicationModelProvider>() },
Mock.Of<IViewCompilerProvider>(),
endpointFactory,
RazorPagesOptions,
mvcOptions);
var pageDescriptor = new CompiledPageActionDescriptor();

// Act
var result1 = await loader.LoadAsync(pageDescriptor, new EndpointMetadataCollection());
var result2 = await loader.LoadAsync(pageDescriptor, new EndpointMetadataCollection());

// Assert
Assert.Same(pageDescriptor, result1);
Assert.Same(pageDescriptor, result2);
}

private static IViewCompilerProvider GetCompilerProvider()
{
var compiledItem = TestRazorCompiledItem.CreateForView(typeof(object), "/Views/Index.cshtml");
Expand Down
15 changes: 14 additions & 1 deletion src/Mvc/test/Mvc.FunctionalTests/RazorBuildTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand Down Expand Up @@ -50,6 +50,19 @@ public async Task Rzc_LocalPageWithDifferentContent_IsUsed()
Assert.Equal("Hello from runtime-compiled rzc page!", responseBody.Trim());
}

[Fact]
public async Task RuntimeCompilation_WithFallbackPage_Works()
{
// Regression test for https://github.com/dotnet/aspnetcore/issues/35060
// Act
var response = await Client.GetAsync("Fallback");

// Assert
await response.AssertStatusCodeAsync(HttpStatusCode.OK);
var responseBody = await response.Content.ReadAsStringAsync();
Assert.Equal("Hello from fallback page!", responseBody.Trim());
}

[Fact]
public async Task Rzc_LocalViewWithDifferentContent_IsUsed()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@page

Hello from fallback page!
3 changes: 2 additions & 1 deletion src/Mvc/test/WebSites/RazorBuildWebSite/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.IO;
Expand Down Expand Up @@ -27,6 +27,7 @@ public void Configure(IApplicationBuilder app)
{
endpoints.MapDefaultControllerRoute();
endpoints.MapRazorPages();
endpoints.MapFallbackToPage("/Fallback");
});
}

Expand Down