Add some tests for hosted project building and publishing (#17398)
* Add some tests for hosted project building and publishing
This commit is contained in:
parent
3c6dc1c516
commit
0c381d2402
|
|
@ -40,8 +40,17 @@
|
|||
<PropertyGroup>
|
||||
<_BlazorConfigPath>$(OutDir)$(AssemblyName).blazor.config</_BlazorConfigPath>
|
||||
</PropertyGroup>
|
||||
<WriteLinesToFile File="$(_BlazorConfigPath)" Lines="." Overwrite="true" />
|
||||
<WriteLinesToFile File="$(_BlazorConfigPath)" Lines="$(AssemblyName)/" Overwrite="false" />
|
||||
|
||||
<ItemGroup>
|
||||
<_BlazorPublishConfigContent Include="." />
|
||||
<_BlazorPublishConfigContent Include="$(AssemblyName)" />
|
||||
</ItemGroup>
|
||||
|
||||
<WriteLinesToFile
|
||||
File="$(_BlazorConfigPath)"
|
||||
Lines="@(_BlazorPublishConfigContent)"
|
||||
Overwrite="true"
|
||||
WriteOnlyWhenDifferent="true" />
|
||||
</Target>
|
||||
|
||||
<!-- The following target runs only for standalone publishing -->
|
||||
|
|
|
|||
|
|
@ -28,6 +28,25 @@ namespace Microsoft.AspNetCore.Blazor.Build
|
|||
Assert.FileExists(result, buildOutputDirectory, "dist", "_framework", "_bin", "Microsoft.Extensions.Logging.Abstractions.dll"); // Verify dependencies are part of the output.
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Build_Hosted_Works()
|
||||
{
|
||||
// Arrange
|
||||
using var project = ProjectDirectory.Create("blazorhosted", additionalProjects: new[] { "standalone", "razorclasslibrary", });
|
||||
project.TargetFramework = "netcoreapp3.1";
|
||||
var result = await MSBuildProcessManager.DotnetMSBuild(project);
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
var buildOutputDirectory = project.BuildOutputDirectory;
|
||||
var blazorConfig = Path.Combine(buildOutputDirectory, "standalone.blazor.config");
|
||||
Assert.FileExists(result, blazorConfig);
|
||||
|
||||
var path = Path.GetFullPath(Path.Combine(project.SolutionPath, "standalone", "bin", project.Configuration, "netstandard2.1", "standalone.dll"));
|
||||
Assert.FileContains(result, blazorConfig, path);
|
||||
Assert.FileDoesNotExist(result, buildOutputDirectory, "dist", "_framework", "_bin", "standalone.dll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Build_WithLinkOnBuildDisabled_Works()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Blazor.Build
|
|||
public async Task Publish_WithDefaultSettings_Works()
|
||||
{
|
||||
// Arrange
|
||||
using var project = ProjectDirectory.Create("standalone", additionalProjects: new string[] { "razorclasslibrary" });
|
||||
using var project = ProjectDirectory.Create("standalone", additionalProjects: new [] { "razorclasslibrary" });
|
||||
var result = await MSBuildProcessManager.DotnetMSBuild(project, "Publish");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
|
@ -39,11 +39,49 @@ namespace Microsoft.AspNetCore.Blazor.Build
|
|||
Assert.FileExists(result, publishDirectory, "web.config");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_WithNoBuild_Works()
|
||||
{
|
||||
// Arrange
|
||||
using var project = ProjectDirectory.Create("standalone", additionalProjects: new[] { "razorclasslibrary" });
|
||||
var result = await MSBuildProcessManager.DotnetMSBuild(project, "Build");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
result = await MSBuildProcessManager.DotnetMSBuild(project, "Publish", "/p:NoBuild=true");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
var publishDirectory = project.PublishOutputDirectory;
|
||||
var blazorPublishDirectory = Path.Combine(publishDirectory, Path.GetFileNameWithoutExtension(project.ProjectFilePath));
|
||||
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "blazor.boot.json");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "blazor.webassembly.js");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "wasm", "mono.wasm");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "wasm", "mono.js");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "_bin", "standalone.dll");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "_bin", "Microsoft.Extensions.Logging.Abstractions.dll"); // Verify dependencies are part of the output.
|
||||
|
||||
// Verify static assets are in the publish directory
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "index.html");
|
||||
|
||||
// Verify static web assets from referenced projects are copied.
|
||||
// Uncomment once https://github.com/aspnet/AspNetCore/issues/17426 is resolved.
|
||||
// Assert.FileExists(result, blazorPublishDirectory, "dist", "_content", "RazorClassLibrary", "wwwroot", "exampleJsInterop.js");
|
||||
// Assert.FileExists(result, blazorPublishDirectory, "dist", "_content", "RazorClassLibrary", "styles.css");
|
||||
|
||||
// Verify static assets are in the publish directory
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "index.html");
|
||||
|
||||
// Verify web.config
|
||||
Assert.FileExists(result, publishDirectory, "web.config");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_WithLinkOnBuildDisabled_Works()
|
||||
{
|
||||
// Arrange
|
||||
using var project = ProjectDirectory.Create("standalone", additionalProjects: new string[] { "razorclasslibrary" });
|
||||
using var project = ProjectDirectory.Create("standalone", additionalProjects: new [] { "razorclasslibrary" });
|
||||
project.AddProjectFileContent(
|
||||
@"<PropertyGroup>
|
||||
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
|
||||
|
|
@ -73,5 +111,83 @@ namespace Microsoft.AspNetCore.Blazor.Build
|
|||
// Verify web.config
|
||||
Assert.FileExists(result, publishDirectory, "web.config");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_HostedApp_Works()
|
||||
{
|
||||
// Arrange
|
||||
using var project = ProjectDirectory.Create("blazorhosted", additionalProjects: new[] { "standalone", "razorclasslibrary", });
|
||||
project.TargetFramework = "netcoreapp3.1";
|
||||
var result = await MSBuildProcessManager.DotnetMSBuild(project, "Publish");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
var publishDirectory = project.PublishOutputDirectory;
|
||||
// Make sure the main project exists
|
||||
Assert.FileExists(result, publishDirectory, "blazorhosted.dll");
|
||||
|
||||
var blazorPublishDirectory = Path.Combine(publishDirectory, "standalone");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "blazor.boot.json");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "blazor.webassembly.js");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "wasm", "mono.wasm");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "wasm", "mono.js");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "_bin", "standalone.dll");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "_bin", "Microsoft.Extensions.Logging.Abstractions.dll"); // Verify dependencies are part of the output.
|
||||
|
||||
// Verify static assets are in the publish directory
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "index.html");
|
||||
|
||||
// Verify static web assets from referenced projects are copied.
|
||||
Assert.FileExists(result, publishDirectory, "wwwroot", "_content", "RazorClassLibrary", "wwwroot", "exampleJsInterop.js");
|
||||
Assert.FileExists(result, publishDirectory, "wwwroot", "_content", "RazorClassLibrary", "styles.css");
|
||||
|
||||
// Verify static assets are in the publish directory
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "index.html");
|
||||
|
||||
// Verify web.config
|
||||
Assert.FileExists(result, publishDirectory, "web.config");
|
||||
|
||||
var blazorConfig = Path.Combine(publishDirectory, "standalone.blazor.config");
|
||||
Assert.FileContains(result, blazorConfig, ".");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publish_HostedApp_WithNoBuild_Works()
|
||||
{
|
||||
// Arrange
|
||||
using var project = ProjectDirectory.Create("blazorhosted", additionalProjects: new[] { "standalone", "razorclasslibrary", });
|
||||
project.TargetFramework = "netcoreapp3.1";
|
||||
var result = await MSBuildProcessManager.DotnetMSBuild(project, "Build");
|
||||
|
||||
Assert.BuildPassed(result);
|
||||
|
||||
result = await MSBuildProcessManager.DotnetMSBuild(project, "Publish", "/p:NoBuild=true");
|
||||
|
||||
var publishDirectory = project.PublishOutputDirectory;
|
||||
// Make sure the main project exists
|
||||
Assert.FileExists(result, publishDirectory, "blazorhosted.dll");
|
||||
|
||||
var blazorPublishDirectory = Path.Combine(publishDirectory, "standalone");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "blazor.boot.json");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "blazor.webassembly.js");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "wasm", "mono.wasm");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "wasm", "mono.js");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "_bin", "standalone.dll");
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "_framework", "_bin", "Microsoft.Extensions.Logging.Abstractions.dll"); // Verify dependencies are part of the output.
|
||||
|
||||
// Verify static assets are in the publish directory
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "index.html");
|
||||
|
||||
// Verify static web assets from referenced projects are copied.
|
||||
// Uncomment once https://github.com/aspnet/AspNetCore/issues/17426 is resolved.
|
||||
// Assert.FileExists(result, publishDirectory, "wwwroot", "_content", "RazorClassLibrary", "wwwroot", "exampleJsInterop.js");
|
||||
// Assert.FileExists(result, publishDirectory, "wwwroot", "_content", "RazorClassLibrary", "styles.css");
|
||||
|
||||
// Verify static assets are in the publish directory
|
||||
Assert.FileExists(result, blazorPublishDirectory, "dist", "index.html");
|
||||
|
||||
// Verify web.config
|
||||
Assert.FileExists(result, publishDirectory, "web.config");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@
|
|||
<Target Name="RestoreTestAssets" AfterTargets="Restore;Build" Condition="'$(DotNetBuildFromSource)' != 'true'">
|
||||
<ItemGroup>
|
||||
<_TestAsset Include="..\testassets\standalone\standalone.csproj" />
|
||||
<_TestAsset Include="..\testassets\blazorhosted\blazorhosted.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<MSBuild
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace blazorhosted.Server
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(typeof(IWebHost));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\standalone\standalone.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Loading…
Reference in New Issue