Skip to content
代码片段 群组 项目
未验证 提交 9f7dfd95 编辑于 作者: Tanay Parikh's avatar Tanay Parikh 提交者: GitHub
浏览文件

Split Blazor WASM Auth Tests to New Project (#42879)

* Split Blazor WASM Auth Tests to New Project

* Remove func moved to base class.

* Add to sln files

* Update parent proj

* File rename -> BlazorWasmTemplateAuthTest

* Fix .slnf files
上级 61b9a06e
No related branches found
No related tags found
无相关合并请求
显示 416 个添加311 个删除
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31606.5
MinimumVisualStudioVersion = 15.0.26124.0
......@@ -1743,6 +1743,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinimalOpenIdConnectSample"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebTransportInteractiveSampleApp", "src\Servers\Kestrel\samples\WebTransportInteractiveSampleApp\WebTransportInteractiveSampleApp.csproj", "{BA649043-EF2B-42DC-B422-A46127BE8296}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Templates.Blazor.WebAssembly.Auth.Tests", "src\ProjectTemplates\test\Templates.Blazor.WebAssembly.Auth.Tests\Templates.Blazor.WebAssembly.Auth.Tests.csproj", "{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -10472,6 +10474,22 @@ Global
{BA649043-EF2B-42DC-B422-A46127BE8296}.Release|x64.Build.0 = Release|Any CPU
{BA649043-EF2B-42DC-B422-A46127BE8296}.Release|x86.ActiveCfg = Release|Any CPU
{BA649043-EF2B-42DC-B422-A46127BE8296}.Release|x86.Build.0 = Release|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Debug|arm64.ActiveCfg = Debug|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Debug|arm64.Build.0 = Debug|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Debug|x64.ActiveCfg = Debug|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Debug|x64.Build.0 = Debug|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Debug|x86.ActiveCfg = Debug|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Debug|x86.Build.0 = Debug|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Release|Any CPU.Build.0 = Release|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Release|arm64.ActiveCfg = Release|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Release|arm64.Build.0 = Release|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Release|x64.ActiveCfg = Release|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Release|x64.Build.0 = Release|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Release|x86.ActiveCfg = Release|Any CPU
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -11333,6 +11351,7 @@ Global
{F4A9CC79-5FE3-4F2B-9CC3-7F42DEDB4853} = {7B976D8F-EA31-4C0B-97BD-DFD9B3CC86FB}
{07FDBE0D-B7A1-43DE-B120-F699C30E7CEF} = {E19E55A2-1562-47A7-8EA6-B51F2CA0CC4C}
{BA649043-EF2B-42DC-B422-A46127BE8296} = {7B976D8F-EA31-4C0B-97BD-DFD9B3CC86FB}
{3A6FD623-F7F3-404B-8A39-CAFB40CA6A08} = {08D53E58-4AAE-40C4-8497-63EC8664F304}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}
......
......@@ -68,6 +68,7 @@
"src\\ProjectTemplates\\test\\Templates.Blazor.Server.Tests\\Templates.Blazor.Server.Tests.csproj",
"src\\ProjectTemplates\\test\\Templates.Blazor.Tests\\Templates.Blazor.Tests.csproj",
"src\\ProjectTemplates\\test\\Templates.Blazor.WebAssembly.Tests\\Templates.Blazor.WebAssembly.Tests.csproj",
"src\\ProjectTemplates\\test\\Templates.Blazor.WebAssembly.Auth.Tests\\Templates.Blazor.WebAssembly.Auth.Tests.csproj",
"src\\ProjectTemplates\\test\\Templates.Mvc.Tests\\Templates.Mvc.Tests.csproj",
"src\\ProjectTemplates\\test\\Templates.Tests\\Templates.Tests.csproj",
"src\\Razor\\Razor.Runtime\\src\\Microsoft.AspNetCore.Razor.Runtime.csproj",
......
......@@ -9,6 +9,7 @@
"src\\ProjectTemplates\\test\\Templates.Blazor.Server.Tests\\Templates.Blazor.Server.Tests.csproj",
"src\\ProjectTemplates\\test\\Templates.Blazor.Tests\\Templates.Blazor.Tests.csproj",
"src\\ProjectTemplates\\test\\Templates.Blazor.WebAssembly.Tests\\Templates.Blazor.WebAssembly.Tests.csproj",
"src\\ProjectTemplates\\test\\Templates.Blazor.WebAssembly.Auth.Tests\\Templates.Blazor.WebAssembly.Auth.Tests.csproj",
"src\\ProjectTemplates\\test\\Templates.Mvc.Tests\\Templates.Mvc.Tests.csproj",
"src\\ProjectTemplates\\test\\Templates.Tests\\Templates.Tests.csproj",
"src\\Shared\\BrowserTesting\\src\\Microsoft.AspNetCore.BrowserTesting.csproj"
......
......@@ -103,4 +103,13 @@ public abstract class BlazorTemplateTest : LoggedTest
return subProject;
}
protected static string ReadFile(string basePath, string path)
{
var fullPath = Path.Combine(basePath, path);
var doesExist = File.Exists(fullPath);
Assert.True(doesExist, $"Expected file to exist, but it doesn't: {path}");
return File.ReadAllText(Path.Combine(basePath, path));
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing;
using Newtonsoft.Json.Linq;
using Templates.Test.Helpers;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Templates.Blazor.Test;
public class BlazorWasmTemplateAuthTest : BlazorTemplateTest
{
public BlazorWasmTemplateAuthTest(ProjectFactoryFixture projectFactory)
: base(projectFactory) { }
public override string ProjectType { get; } = "blazorwasm";
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
// LocalDB doesn't work on non Windows platforms
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public Task BlazorWasmHostedTemplate_IndividualAuth_Works_WithLocalDB()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(true, false, false);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
// LocalDB doesn't work on non Windows platforms
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public Task BlazorWasmHostedTemplate_IndividualAuth_NoHttps_Works_WithLocalDB()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(true, false, true);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
public Task BlazorWasmHostedTemplate_IndividualAuth_Works_WithOutLocalDB()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(false, false, false);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
public Task BlazorWasmHostedTemplate_IndividualAuth_NoHttps_Works_WithOutLocalDB()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(false, false, false);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
// LocalDB doesn't work on non Windows platforms
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public Task BlazorWasmHostedTemplate_IndividualAuth_Works_WithLocalDB_ProgramMain()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(true, true, false);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
// LocalDB doesn't work on non Windows platforms
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public Task BlazorWasmHostedTemplate_IndividualAuth_NoHttps_Works_WithLocalDB_ProgramMain()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(true, true, true);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
public Task BlazorWasmHostedTemplate_IndividualAuth_Works_WithOutLocalDB_ProgramMain()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(false, true, false);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
public Task BlazorWasmHostedTemplate_IndividualAuth_NoHttps_Works_WithOutLocalDB_ProgramMain()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(false, true, true);
private async Task<Project> CreateBuildPublishIndividualAuthProject(bool useLocalDb, bool useProgramMain = false, bool noHttps = false)
{
// Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278
Environment.SetEnvironmentVariable("EnableDefaultScopedCssItems", "true");
var args = new[] { ArgConstants.Hosted, useLocalDb ? "-uld" : "", useProgramMain ? ArgConstants.UseProgramMain : "", noHttps ? ArgConstants.NoHttps : "" };
var project = await CreateBuildPublishAsync("Individual", args: args);
var serverProject = GetSubProject(project, "Server", $"{project.ProjectName}.Server");
var serverProjectFileContents = ReadFile(serverProject.TemplateOutputDir, $"{serverProject.ProjectName}.csproj");
if (!useLocalDb)
{
Assert.Contains(".db", serverProjectFileContents);
}
var appSettings = ReadFile(serverProject.TemplateOutputDir, "appsettings.json");
var element = JsonSerializer.Deserialize<JsonElement>(appSettings);
var clientsProperty = element.GetProperty("IdentityServer").EnumerateObject().Single().Value.EnumerateObject().Single();
var replacedSection = element.GetRawText().Replace(clientsProperty.Name, serverProject.ProjectName.Replace(".Server", ".Client"));
var appSettingsPath = Path.Combine(serverProject.TemplateOutputDir, "appsettings.json");
File.WriteAllText(appSettingsPath, replacedSection);
var publishResult = await serverProject.RunDotNetPublishAsync();
Assert.True(0 == publishResult.ExitCode, ErrorMessages.GetFailedProcessMessage("publish", serverProject, publishResult));
// Run dotnet build after publish. The reason is that one uses Config = Debug and the other uses Config = Release
// The output from publish will go into bin/Release/netcoreappX.Y/publish and won't be affected by calling build
// later, while the opposite is not true.
var buildResult = await serverProject.RunDotNetBuildAsync();
Assert.True(0 == buildResult.ExitCode, ErrorMessages.GetFailedProcessMessage("build", serverProject, buildResult));
var migrationsResult = await serverProject.RunDotNetEfCreateMigrationAsync("blazorwasm");
Assert.True(0 == migrationsResult.ExitCode, ErrorMessages.GetFailedProcessMessage("run EF migrations", serverProject, migrationsResult));
serverProject.AssertEmptyMigration("blazorwasm");
return project;
}
private async Task BlazorWasmHostedTemplate_IndividualAuth_Works(bool useLocalDb, bool useProgramMain, bool noHttps)
{
var project = await CreateBuildPublishIndividualAuthProject(useLocalDb: useLocalDb, useProgramMain: useProgramMain, noHttps: noHttps);
var serverProject = GetSubProject(project, "Server", $"{project.ProjectName}.Server");
}
[Fact]
public async Task BlazorWasmStandaloneTemplate_IndividualAuth_CreateBuildPublish()
{
var project = await CreateBuildPublishAsync("Individual", args: new[] {
"--authority",
"https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration",
ArgConstants.ClientId,
"sample-client-id"
});
}
[Fact]
public async Task BlazorWasmStandaloneTemplate_NoHttps_IndividualAuth_CreateBuildPublish()
{
var project = await CreateBuildPublishAsync("Individual", args: new[] {
"--authority",
"https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration",
ArgConstants.ClientId,
"sample-client-id",
ArgConstants.NoHttps
});
}
public static TheoryData<TemplateInstance> TemplateDataIndividualB2C => new TheoryData<TemplateInstance>
{
new TemplateInstance("blazorwasmhostedaadb2c", "IndividualB2C",
ArgConstants.Hosted,
ArgConstants.AadB2cInstance, "example.b2clogin.com",
"-ssp", "b2c_1_siupin",
ArgConstants.ClientId, "clientId",
ArgConstants.Domain, "my-domain",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324"),
new TemplateInstance("blazorwasmhostedaadb2c_program_main", "IndividualB2C",
ArgConstants.Hosted,
ArgConstants.AadB2cInstance, "example.b2clogin.com",
"-ssp", "b2c_1_siupin",
ArgConstants.ClientId, "clientId",
ArgConstants.Domain, "my-domain",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324",
ArgConstants.UseProgramMain),
new TemplateInstance("blazorwasmstandaloneaadb2c", "IndividualB2C",
ArgConstants.AadB2cInstance, "example.b2clogin.com",
"-ssp", "b2c_1_siupin",
ArgConstants.ClientId, "clientId",
ArgConstants.Domain, "my-domain"),
new TemplateInstance("blazorwasmstandaloneaadb2c_program_main", "IndividualB2C",
ArgConstants.AadB2cInstance, "example.b2clogin.com",
"-ssp", "b2c_1_siupin",
ArgConstants.ClientId, "clientId",
ArgConstants.Domain, "my-domain",
ArgConstants.UseProgramMain),
};
public static TheoryData<TemplateInstance> TemplateDataSingleOrg => new TheoryData<TemplateInstance>
{
new TemplateInstance("blazorwasmhostedaad", "SingleOrg",
ArgConstants.Hosted,
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324"),
new TemplateInstance("blazorwasmhostedaadgraph", "SingleOrg",
ArgConstants.Hosted,
ArgConstants.CallsGraph,
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324"),
new TemplateInstance("blazorwasmhostedaadapi", "SingleOrg",
ArgConstants.Hosted,
ArgConstants.CalledApiUrl, "\"https://graph.microsoft.com\"",
ArgConstants.CalledApiScopes, "user.readwrite",
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324"),
new TemplateInstance("blazorwasmstandaloneaad", "SingleOrg",
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId"),
};
public static TheoryData<TemplateInstance> TemplateDataSingleOrgProgramMain => new TheoryData<TemplateInstance>
{
new TemplateInstance("blazorwasmhostedaad_program_main", "SingleOrg",
ArgConstants.Hosted,
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324",
ArgConstants.UseProgramMain),
new TemplateInstance("blazorwasmhostedaadgraph_program_main", "SingleOrg",
ArgConstants.Hosted,
ArgConstants.CallsGraph,
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324",
ArgConstants.UseProgramMain),
new TemplateInstance("blazorwasmhostedaadapi_program_main", "SingleOrg",
ArgConstants.Hosted,
ArgConstants.CalledApiUrl, "\"https://graph.microsoft.com\"",
ArgConstants.CalledApiScopes, "user.readwrite",
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324",
ArgConstants.UseProgramMain),
new TemplateInstance("blazorwasmstandaloneaad_program_main", "SingleOrg",
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.UseProgramMain),
};
public class TemplateInstance
{
public TemplateInstance(string name, string auth, params string[] arguments)
{
Name = name;
Auth = auth;
Arguments = arguments;
}
public string Name { get; }
public string Auth { get; }
public string[] Arguments { get; }
}
[ConditionalTheory]
[MemberData(nameof(TemplateDataIndividualB2C))]
public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_IndividualB2C_Works(TemplateInstance instance)
=> CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments, targetFramework: "netstandard2.1");
[ConditionalTheory]
[MemberData(nameof(TemplateDataIndividualB2C))]
public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_IndividualB2C_NoHttps_Works(TemplateInstance instance)
=> CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments.Union(new[] { ArgConstants.NoHttps }).ToArray(), targetFramework: "netstandard2.1");
[ConditionalTheory]
[MemberData(nameof(TemplateDataSingleOrg))]
public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_SingleOrg_Works(TemplateInstance instance)
=> CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments, targetFramework: "netstandard2.1");
[ConditionalTheory]
[MemberData(nameof(TemplateDataSingleOrg))]
public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_SingleOrg_NoHttps_Works(TemplateInstance instance)
=> CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments.Union(new[] { ArgConstants.NoHttps }).ToArray(), targetFramework: "netstandard2.1");
[ConditionalTheory]
[MemberData(nameof(TemplateDataSingleOrgProgramMain))]
public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_SingleOrg_ProgramMain_Works(TemplateInstance instance)
=> CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments, targetFramework: "netstandard2.1");
[ConditionalTheory]
[MemberData(nameof(TemplateDataSingleOrgProgramMain))]
public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_SingleOrg_NoHttps_ProgramMain_Works(TemplateInstance instance)
=> CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments.Union(new[] { ArgConstants.NoHttps }).ToArray(), targetFramework: "netstandard2.1");
private static void UpdatePublishedSettings(Project serverProject)
{
// Hijack here the config file to use the development key during publish.
var appSettings = JObject.Parse(File.ReadAllText(Path.Combine(serverProject.TemplateOutputDir, "appsettings.json")));
var appSettingsDevelopment = JObject.Parse(File.ReadAllText(Path.Combine(serverProject.TemplateOutputDir, "appsettings.Development.json")));
((JObject)appSettings["IdentityServer"]).Merge(appSettingsDevelopment["IdentityServer"]);
((JObject)appSettings["IdentityServer"]).Merge(new
{
IdentityServer = new
{
Key = new
{
FilePath = "./tempkey.json"
}
}
});
var testAppSettings = appSettings.ToString();
File.WriteAllText(Path.Combine(serverProject.TemplatePublishDir, "appsettings.json"), testAppSettings);
}
}
<Project Sdk="Microsoft.NET.Sdk">
<!-- Shared testing infrastructure for running E2E tests using selenium -->
<Import Condition="'$(SkipTestBuild)' != 'true'" Project="$(SharedSourceRoot)E2ETesting\E2ETesting.props" />
<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<TestGroupName>ProjectTemplates.Blazor.WebAssembly.Auth.Tests</TestGroupName>
<DefineConstants>$(DefineConstants);XPLAT</DefineConstants>
<RunTemplateTests Condition="'$(RunTemplateTests)' == ''">true</RunTemplateTests>
<SkipTests Condition="'$(RunTemplateTests)' != 'true'">true</SkipTests>
<BaseOutputPath />
<OutputPath />
<!-- Properties that affect test runs -->
<!-- TestTemplateCreationFolder is the folder where the templates will be created. Will point out to $(OutputDir)$(TestTemplateCreationFolder) -->
<TestTemplateCreationFolder>TestTemplates\</TestTemplateCreationFolder>
<RestoreFolderName>WebAssembly</RestoreFolderName>
<TestDependsOnAspNetPackages>true</TestDependsOnAspNetPackages>
<SkipHelixQueues>
$(HelixQueueArmDebian11);
</SkipHelixQueues>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(SharedSourceRoot)CommandLineUtils\**\*.cs" />
<Compile Include="$(SharedSourceRoot)CertificateGeneration\**\*.cs" LinkBase="shared\CertificateGeneration" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(SharedSourceRoot)Process\*.cs" LinkBase="shared\Process" />
<Compile Include="..\..\Shared\**" LinkBase="Helpers" />
</ItemGroup>
<ItemGroup>
<!-- We need the actual templates in the output directory for tests to verify file encodings. -->
<Content Include="..\..\Web.ProjectTemplates\**" LinkBase="Assets\Web.ProjectTemplates" />
</ItemGroup>
<ItemGroup>
<HelixContent Include="$(OutputPath)$(TargetFramework)Assets\**" />
</ItemGroup>
<ItemGroup>
<Reference Include="AngleSharp" />
<Reference Include="System.Net.Http" />
<ProjectReference Include="$(RepoRoot)src\Framework\App.Runtime\src\Microsoft.AspNetCore.App.Runtime.csproj"
Private="false"
ReferenceOutputAssembly="false"
SkipGetTargetFrameworkProperties="true" />
<ProjectReference Include="$(RepoRoot)src\Hosting\Server.IntegrationTesting\src\Microsoft.AspNetCore.Server.IntegrationTesting.csproj" />
<ProjectReference Include="$(RepoRoot)src\Shared\BrowserTesting\src\Microsoft.AspNetCore.BrowserTesting.csproj" />
<ProjectReference Include="../../Web.ProjectTemplates/Microsoft.DotNet.Web.ProjectTemplates.csproj"
Private="false"
ReferenceOutputAssembly="false"
SkipGetTargetFrameworkProperties="true" />
</ItemGroup>
<PropertyGroup>
<PreserveExistingLogsInOutput Condition="'$(PreserveExistingLogsInOutput)' == '' AND '$(ContinuousIntegrationBuild)' == 'true'">true</PreserveExistingLogsInOutput>
<PreserveExistingLogsInOutput Condition="'$(PreserveExistingLogsInOutput)' == ''">false</PreserveExistingLogsInOutput>
</PropertyGroup>
<!-- Shared testing infrastructure for running E2E tests -->
<Import Condition="'$(SkipTestBuild)' != 'true'" Project="..\..\TestInfrastructure\PrepareForTest.targets" />
</Project>
......@@ -88,7 +88,7 @@ public class BlazorWasmTemplateTest : BlazorTemplateTest
ValidatePublishedServiceWorker(serverProject);
}
private void ValidatePublishedServiceWorker(Project project)
private static void ValidatePublishedServiceWorker(Project project)
{
var publishDir = Path.Combine(project.TemplatePublishDir, "wwwroot");
......@@ -110,303 +110,4 @@ public class BlazorWasmTemplateTest : BlazorTemplateTest
var serviceWorkerAssetsManifestVersion = JsonSerializer.Deserialize<string>(serviceWorkerAssetsManifestVersionJson);
Assert.True(serviceWorkerContents.Contains($"/* Manifest version: {serviceWorkerAssetsManifestVersion} */", StringComparison.Ordinal));
}
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
// LocalDB doesn't work on non Windows platforms
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public Task BlazorWasmHostedTemplate_IndividualAuth_Works_WithLocalDB()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(true, false, false);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
// LocalDB doesn't work on non Windows platforms
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public Task BlazorWasmHostedTemplate_IndividualAuth_NoHttps_Works_WithLocalDB()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(true, false, true);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
public Task BlazorWasmHostedTemplate_IndividualAuth_Works_WithOutLocalDB()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(false, false, false);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
public Task BlazorWasmHostedTemplate_IndividualAuth_NoHttps_Works_WithOutLocalDB()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(false, false, false);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
// LocalDB doesn't work on non Windows platforms
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public Task BlazorWasmHostedTemplate_IndividualAuth_Works_WithLocalDB_ProgramMain()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(true, true, false);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
// LocalDB doesn't work on non Windows platforms
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public Task BlazorWasmHostedTemplate_IndividualAuth_NoHttps_Works_WithLocalDB_ProgramMain()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(true, true, true);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
public Task BlazorWasmHostedTemplate_IndividualAuth_Works_WithOutLocalDB_ProgramMain()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(false, true, false);
[ConditionalFact]
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/34554", Queues = "Windows.10.Arm64v8.Open")]
public Task BlazorWasmHostedTemplate_IndividualAuth_NoHttps_Works_WithOutLocalDB_ProgramMain()
=> BlazorWasmHostedTemplate_IndividualAuth_Works(false, true, true);
private async Task<Project> CreateBuildPublishIndividualAuthProject(bool useLocalDb, bool useProgramMain = false, bool noHttps = false)
{
// Additional arguments are needed. See: https://github.com/dotnet/aspnetcore/issues/24278
Environment.SetEnvironmentVariable("EnableDefaultScopedCssItems", "true");
var args = new[] { ArgConstants.Hosted, useLocalDb ? "-uld" : "", useProgramMain ? ArgConstants.UseProgramMain : "", noHttps ? ArgConstants.NoHttps : "" };
var project = await CreateBuildPublishAsync("Individual", args: args);
var serverProject = GetSubProject(project, "Server", $"{project.ProjectName}.Server");
var serverProjectFileContents = ReadFile(serverProject.TemplateOutputDir, $"{serverProject.ProjectName}.csproj");
if (!useLocalDb)
{
Assert.Contains(".db", serverProjectFileContents);
}
var appSettings = ReadFile(serverProject.TemplateOutputDir, "appsettings.json");
var element = JsonSerializer.Deserialize<JsonElement>(appSettings);
var clientsProperty = element.GetProperty("IdentityServer").EnumerateObject().Single().Value.EnumerateObject().Single();
var replacedSection = element.GetRawText().Replace(clientsProperty.Name, serverProject.ProjectName.Replace(".Server", ".Client"));
var appSettingsPath = Path.Combine(serverProject.TemplateOutputDir, "appsettings.json");
File.WriteAllText(appSettingsPath, replacedSection);
var publishResult = await serverProject.RunDotNetPublishAsync();
Assert.True(0 == publishResult.ExitCode, ErrorMessages.GetFailedProcessMessage("publish", serverProject, publishResult));
// Run dotnet build after publish. The reason is that one uses Config = Debug and the other uses Config = Release
// The output from publish will go into bin/Release/netcoreappX.Y/publish and won't be affected by calling build
// later, while the opposite is not true.
var buildResult = await serverProject.RunDotNetBuildAsync();
Assert.True(0 == buildResult.ExitCode, ErrorMessages.GetFailedProcessMessage("build", serverProject, buildResult));
var migrationsResult = await serverProject.RunDotNetEfCreateMigrationAsync("blazorwasm");
Assert.True(0 == migrationsResult.ExitCode, ErrorMessages.GetFailedProcessMessage("run EF migrations", serverProject, migrationsResult));
serverProject.AssertEmptyMigration("blazorwasm");
return project;
}
private async Task BlazorWasmHostedTemplate_IndividualAuth_Works(bool useLocalDb, bool useProgramMain, bool noHttps)
{
var project = await CreateBuildPublishIndividualAuthProject(useLocalDb: useLocalDb, useProgramMain: useProgramMain, noHttps: noHttps);
var serverProject = GetSubProject(project, "Server", $"{project.ProjectName}.Server");
}
[Fact]
public async Task BlazorWasmStandaloneTemplate_IndividualAuth_CreateBuildPublish()
{
var project = await CreateBuildPublishAsync("Individual", args: new[] {
"--authority",
"https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration",
ArgConstants.ClientId,
"sample-client-id"
});
}
[Fact]
public async Task BlazorWasmStandaloneTemplate_NoHttps_IndividualAuth_CreateBuildPublish()
{
var project = await CreateBuildPublishAsync("Individual", args: new[] {
"--authority",
"https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration",
ArgConstants.ClientId,
"sample-client-id",
ArgConstants.NoHttps
});
}
public static TheoryData<TemplateInstance> TemplateDataIndividualB2C => new TheoryData<TemplateInstance>
{
new TemplateInstance("blazorwasmhostedaadb2c", "IndividualB2C",
ArgConstants.Hosted,
ArgConstants.AadB2cInstance, "example.b2clogin.com",
"-ssp", "b2c_1_siupin",
ArgConstants.ClientId, "clientId",
ArgConstants.Domain, "my-domain",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324"),
new TemplateInstance("blazorwasmhostedaadb2c_program_main", "IndividualB2C",
ArgConstants.Hosted,
ArgConstants.AadB2cInstance, "example.b2clogin.com",
"-ssp", "b2c_1_siupin",
ArgConstants.ClientId, "clientId",
ArgConstants.Domain, "my-domain",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324",
ArgConstants.UseProgramMain),
new TemplateInstance("blazorwasmstandaloneaadb2c", "IndividualB2C",
ArgConstants.AadB2cInstance, "example.b2clogin.com",
"-ssp", "b2c_1_siupin",
ArgConstants.ClientId, "clientId",
ArgConstants.Domain, "my-domain"),
new TemplateInstance("blazorwasmstandaloneaadb2c_program_main", "IndividualB2C",
ArgConstants.AadB2cInstance, "example.b2clogin.com",
"-ssp", "b2c_1_siupin",
ArgConstants.ClientId, "clientId",
ArgConstants.Domain, "my-domain",
ArgConstants.UseProgramMain),
};
public static TheoryData<TemplateInstance> TemplateDataSingleOrg => new TheoryData<TemplateInstance>
{
new TemplateInstance("blazorwasmhostedaad", "SingleOrg",
ArgConstants.Hosted,
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324"),
new TemplateInstance("blazorwasmhostedaadgraph", "SingleOrg",
ArgConstants.Hosted,
ArgConstants.CallsGraph,
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324"),
new TemplateInstance("blazorwasmhostedaadapi", "SingleOrg",
ArgConstants.Hosted,
ArgConstants.CalledApiUrl, "\"https://graph.microsoft.com\"",
ArgConstants.CalledApiScopes, "user.readwrite",
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324"),
new TemplateInstance("blazorwasmstandaloneaad", "SingleOrg",
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId"),
};
public static TheoryData<TemplateInstance> TemplateDataSingleOrgProgramMain => new TheoryData<TemplateInstance>
{
new TemplateInstance("blazorwasmhostedaad_program_main", "SingleOrg",
ArgConstants.Hosted,
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324",
ArgConstants.UseProgramMain),
new TemplateInstance("blazorwasmhostedaadgraph_program_main", "SingleOrg",
ArgConstants.Hosted,
ArgConstants.CallsGraph,
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324",
ArgConstants.UseProgramMain),
new TemplateInstance("blazorwasmhostedaadapi_program_main", "SingleOrg",
ArgConstants.Hosted,
ArgConstants.CalledApiUrl, "\"https://graph.microsoft.com\"",
ArgConstants.CalledApiScopes, "user.readwrite",
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.DefaultScope, "full",
ArgConstants.AppIdUri, "ApiUri",
ArgConstants.AppIdClientId, "1234123413241324",
ArgConstants.UseProgramMain),
new TemplateInstance("blazorwasmstandaloneaad_program_main", "SingleOrg",
ArgConstants.Domain, "my-domain",
ArgConstants.TenantId, "tenantId",
ArgConstants.ClientId, "clientId",
ArgConstants.UseProgramMain),
};
public class TemplateInstance
{
public TemplateInstance(string name, string auth, params string[] arguments)
{
Name = name;
Auth = auth;
Arguments = arguments;
}
public string Name { get; }
public string Auth { get; }
public string[] Arguments { get; }
}
[ConditionalTheory]
[MemberData(nameof(TemplateDataIndividualB2C))]
public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_IndividualB2C_Works(TemplateInstance instance)
=> CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments, targetFramework: "netstandard2.1");
[ConditionalTheory]
[MemberData(nameof(TemplateDataIndividualB2C))]
public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_IndividualB2C_NoHttps_Works(TemplateInstance instance)
=> CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments.Union(new[] { ArgConstants.NoHttps }).ToArray(), targetFramework: "netstandard2.1");
[ConditionalTheory]
[MemberData(nameof(TemplateDataSingleOrg))]
public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_SingleOrg_Works(TemplateInstance instance)
=> CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments, targetFramework: "netstandard2.1");
[ConditionalTheory]
[MemberData(nameof(TemplateDataSingleOrg))]
public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_SingleOrg_NoHttps_Works(TemplateInstance instance)
=> CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments.Union(new[] { ArgConstants.NoHttps }).ToArray(), targetFramework: "netstandard2.1");
[ConditionalTheory]
[MemberData(nameof(TemplateDataSingleOrgProgramMain))]
public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_SingleOrg_ProgramMain_Works(TemplateInstance instance)
=> CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments, targetFramework: "netstandard2.1");
[ConditionalTheory]
[MemberData(nameof(TemplateDataSingleOrgProgramMain))]
public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_SingleOrg_NoHttps_ProgramMain_Works(TemplateInstance instance)
=> CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments.Union(new[] { ArgConstants.NoHttps }).ToArray(), targetFramework: "netstandard2.1");
private string ReadFile(string basePath, string path)
{
var fullPath = Path.Combine(basePath, path);
var doesExist = File.Exists(fullPath);
Assert.True(doesExist, $"Expected file to exist, but it doesn't: {path}");
return File.ReadAllText(Path.Combine(basePath, path));
}
private void UpdatePublishedSettings(Project serverProject)
{
// Hijack here the config file to use the development key during publish.
var appSettings = JObject.Parse(File.ReadAllText(Path.Combine(serverProject.TemplateOutputDir, "appsettings.json")));
var appSettingsDevelopment = JObject.Parse(File.ReadAllText(Path.Combine(serverProject.TemplateOutputDir, "appsettings.Development.json")));
((JObject)appSettings["IdentityServer"]).Merge(appSettingsDevelopment["IdentityServer"]);
((JObject)appSettings["IdentityServer"]).Merge(new
{
IdentityServer = new
{
Key = new
{
FilePath = "./tempkey.json"
}
}
});
var testAppSettings = appSettings.ToString();
File.WriteAllText(Path.Combine(serverProject.TemplatePublishDir, "appsettings.json"), testAppSettings);
}
}
......@@ -102,13 +102,4 @@ public class EmptyBlazorWasmTemplateTest : BlazorTemplateTest
var serviceWorkerAssetsManifestVersion = JsonSerializer.Deserialize<string>(serviceWorkerAssetsManifestVersionJson);
Assert.True(serviceWorkerContents.Contains($"/* Manifest version: {serviceWorkerAssetsManifestVersion} */", StringComparison.Ordinal));
}
private string ReadFile(string basePath, string path)
{
var fullPath = Path.Combine(basePath, path);
var doesExist = File.Exists(fullPath);
Assert.True(doesExist, $"Expected file to exist, but it doesn't: {path}");
return File.ReadAllText(Path.Combine(basePath, path));
}
}
......@@ -6,7 +6,6 @@
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<TestGroupName>ProjectTemplates.Blazor.WebAssembly.Tests</TestGroupName>
<DefineConstants>$(DefineConstants);XPLAT</DefineConstants>
<HelixTimeout>01:00:00</HelixTimeout>
<RunTemplateTests Condition="'$(RunTemplateTests)' == ''">true</RunTemplateTests>
<SkipTests Condition="'$(RunTemplateTests)' != 'true'">true</SkipTests>
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册