Fix small issue in Identity UI (#12607)
The logic for selecting the views assembly had a small bug. Added an E2E test to cover the scenario.
This commit is contained in:
parent
51497f72a6
commit
0d553f7147
|
|
@ -53,22 +53,22 @@ namespace Microsoft.AspNetCore.Identity
|
|||
|
||||
private static void AddRelatedParts(IdentityBuilder builder)
|
||||
{
|
||||
// We try to resolve the UI framework that was used by looking at the entry assembly.
|
||||
// When an app runs, the entry assembly will point to the built app. In some rare cases
|
||||
// (functional testing) the app assembly will be different, and we'll try to locate it through
|
||||
// the same mechanism that MVC uses today.
|
||||
// Finally, if for some reason we aren't able to find the assembly, we'll use our default value
|
||||
// (Bootstrap4)
|
||||
if (!TryResolveUIFramework(Assembly.GetEntryAssembly(), out var framework) ||
|
||||
!TryResolveUIFramework(GetApplicationAssembly(builder), out framework))
|
||||
{
|
||||
framework = default;
|
||||
}
|
||||
|
||||
var mvcBuilder = builder.Services
|
||||
.AddMvc()
|
||||
.ConfigureApplicationPartManager(partManager =>
|
||||
{
|
||||
// We try to resolve the UI framework that was used by looking at the entry assembly.
|
||||
// When an app runs, the entry assembly will point to the built app. In some rare cases
|
||||
// (functional testing) the app assembly will be different, and we'll try to locate it through
|
||||
// the same mechanism that MVC uses today.
|
||||
// Finally, if for some reason we aren't able to find the assembly, we'll use our default value
|
||||
// (Bootstrap4)
|
||||
if (!TryResolveUIFramework(Assembly.GetEntryAssembly(), out var framework) &&
|
||||
!TryResolveUIFramework(GetApplicationAssembly(builder), out framework))
|
||||
{
|
||||
framework = default;
|
||||
}
|
||||
|
||||
var thisAssembly = typeof(IdentityBuilderUIExtensions).Assembly;
|
||||
var relatedAssemblies = RelatedAssemblyAttribute.GetRelatedAssemblies(thisAssembly, throwOnError: true);
|
||||
var relatedParts = relatedAssemblies.ToDictionary(
|
||||
|
|
@ -149,7 +149,7 @@ namespace Microsoft.AspNetCore.Identity
|
|||
}
|
||||
|
||||
// If we find the metadata there must be a valid framework here.
|
||||
if (!Enum.TryParse<UIFramework>(metadata, ignoreCase: true, out var uIFramework))
|
||||
if (!Enum.TryParse<UIFramework>(metadata, ignoreCase: true, out uiFramework))
|
||||
{
|
||||
var enumValues = string.Join(", ", Enum.GetNames(typeof(UIFramework)).Select(v => $"'{v}'"));
|
||||
throw new InvalidOperationException(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
// 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 System.Linq;
|
||||
using Identity.DefaultUI.WebSite;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Bootstrap3Tests
|
||||
{
|
||||
public class UIFramewrokAttributeTest : IClassFixture<WebApplicationFactory<Startup>>
|
||||
{
|
||||
public UIFramewrokAttributeTest(WebApplicationFactory<Startup> factory)
|
||||
{
|
||||
Factory = factory;
|
||||
}
|
||||
|
||||
public WebApplicationFactory<Startup> Factory { get; }
|
||||
|
||||
[Fact]
|
||||
public void DefaultWebSite_DefaultsToBootstrap3()
|
||||
{
|
||||
var hasV3Part = false;
|
||||
var hasV4Part = false;
|
||||
var factory = Factory.WithWebHostBuilder(
|
||||
whb => whb.UseStartup<Startup>().ConfigureServices(
|
||||
services => services.AddMvc().ConfigureApplicationPartManager(
|
||||
apm => (hasV3Part, hasV4Part) = (HasPart(apm, "V3"), HasPart(apm, "V4")))));
|
||||
|
||||
// Act
|
||||
var client = factory.CreateClient();
|
||||
|
||||
// Assert
|
||||
Assert.True(hasV3Part);
|
||||
Assert.False(hasV4Part);
|
||||
}
|
||||
|
||||
private static bool HasPart(ApplicationPartManager apm, string name)
|
||||
{
|
||||
return apm.ApplicationParts
|
||||
.Any(p => p is CompiledRazorAssemblyPart cp && cp.Assembly.GetName().Name == "Microsoft.AspNetCore.Identity.UI.Views." + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -48,6 +48,13 @@
|
|||
<ResolveStaticWebAssetsInputsDependsOn>_SetBootstrapFrameworkVersion</ResolveStaticWebAssetsInputsDependsOn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="Microsoft.AspNetCore.Identity.UI.UIFrameworkAttribute">
|
||||
<_Parameter1>$(IdentityDefaultUIFramework)</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<Target Name="_SetBootstrapFrameworkVersion">
|
||||
<ItemGroup>
|
||||
<_StaticWebAssetsProjectReference Condition="'%(FileName)' == 'Microsoft.AspNetCore.Identity.UI'">
|
||||
|
|
|
|||
Loading…
Reference in New Issue