Skip to content

Commit

Permalink
Remove version check when setting the condition to install wasm-tools (
Browse files Browse the repository at this point in the history
…#2269)

* Remove version check when setting the condition to install wasm-tools

* Add additional test coverage for Blazor starter app
  • Loading branch information
cormacpayne authored Nov 28, 2023
1 parent 29e5823 commit 0b76566
Show file tree
Hide file tree
Showing 77 changed files with 723 additions and 1,564 deletions.
7 changes: 2 additions & 5 deletions src/Detector/DotNetCore/DotnetCoreDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,9 @@ public PlatformDetectorResult Detect(DetectorContext context)

var version = this.GetVersion(targetFramework);

// Any Blazor WebAssembly app on .NET >= 6 should have the workload installed.
// Any Blazor WebAssembly app should have the workload installed.
// https://github.com/microsoft/Oryx/issues/1026
// TODO (#1664369): Remove the version check once .NET Core 3.1 is EOL.
if (ProjectFileHelpers.IsBlazorWebAssemblyProject(projectFileDoc)
&& !string.IsNullOrEmpty(version)
&& (version.StartsWith("6") || version.StartsWith("7")))
if (ProjectFileHelpers.IsBlazorWebAssemblyProject(projectFileDoc))
{
installAOTWorkloads = true;
}
Expand Down
30 changes: 17 additions & 13 deletions tests/Oryx.BuildImage.Tests/DotNetCore/DotNetCoreSampleAppsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -800,18 +800,20 @@ public void Builds_SingleBlazorWasmProject_Without_Setting_Apptype_Option()
result.GetDebugInfo());
}

[Fact, Trait("category", "latest")]
public void Builds_AzureBlazorWasmFunctionProject_By_Setting_Apptype_Via_BuildCommand()
[Theory]
[Trait("category", "jamstack")]
[InlineData("BlazorStarterAppNet8")]
[InlineData("BlazorVanillaApiAppNet8")]
public void Builds_AzureBlazorWasmFunctionProject_By_Setting_Apptype_Via_BuildCommand(string appName)
{
// Arrange
var appName = "Blazor_Function_Sample";
var volume = CreateSampleAppVolume(appName);
var appDir = volume.ContainerDir;
var appOutputDir = $"{appDir}/output";
var script = new ShellScriptBuilder()
.AddBuildCommand(
$"{appDir} -o {appOutputDir} --apptype {Constants.StaticSiteApplications} " +
$"--platform dotnet --platform-version 3.1.8")
$"--platform dotnet --platform-version 8.0")
.AddFileExistsCheck($"{appOutputDir}/{FilePaths.BuildManifestFileName}")
.AddFileExistsCheck($"{appOutputDir}/{FilePaths.OsTypeFileName}")
.AddStringExistsInFileCheck(ManifestFilePropertyKeys.PlatformName, $"{appOutputDir}/{FilePaths.BuildManifestFileName}")
Expand All @@ -820,7 +822,7 @@ public void Builds_AzureBlazorWasmFunctionProject_By_Setting_Apptype_Via_BuildCo
// Act
var result = _dockerCli.Run(new DockerRunArguments
{
ImageId = Settings.BuildImageName,
ImageId = _imageHelper.GetAzureFunctionsJamStackBuildImage(ImageTestHelperConstants.AzureFunctionsJamStackBullseye),
EnvironmentVariables = new List<EnvironmentVariable>
{
CreateAppNameEnvVar(appName)
Expand All @@ -835,31 +837,33 @@ public void Builds_AzureBlazorWasmFunctionProject_By_Setting_Apptype_Via_BuildCo
() =>
{
Assert.True(result.IsSuccess);
Assert.Contains(string.Format(SdkVersionMessageFormat, "3.1.402"), result.StdOut);
Assert.Contains(string.Format(SdkVersionMessageFormat, DotNetCoreSdkVersions.DotNet80SdkVersion), result.StdOut);
},
result.GetDebugInfo());
}

[Fact, Trait("category", "jamstack")]
public void Builds_AzureFunctionProject_FromBlazorFunctionRepo_When_Apptype_Is_SetAs_Functions()
[Theory]
[Trait("category", "jamstack")]
[InlineData("BlazorStarterAppNet8")]
[InlineData("BlazorVanillaApiAppNet8")]
public void Builds_AzureFunctionProject_FromBlazorFunctionRepo_When_Apptype_Is_SetAs_Functions(string appName)
{
// Arrange
var appName = "Blazor_Function_Sample";
var volume = CreateSampleAppVolume(appName);
var appDir = volume.ContainerDir;
var appOutputDir = "/tmp/blazor-wasm-output";
var script = new ShellScriptBuilder()
.AddBuildCommand(
$"{appDir}/MessageFunction -o {appOutputDir} --apptype functions --platform dotnet " +
$"--platform-version {FinalStretchVersions.FinalStretchDotNetCoreApp31RunTimeVersion}")
$"{appDir} -o {appOutputDir} --apptype {Constants.FunctionApplications} --platform dotnet " +
$"--platform-version 8.0")
.AddFileExistsCheck($"{appOutputDir}/{FilePaths.BuildManifestFileName}")
.AddFileExistsCheck($"{appOutputDir}/{FilePaths.OsTypeFileName}")
.ToString();

// Act
var result = _dockerCli.Run(new DockerRunArguments
{
ImageId = _imageHelper.GetAzureFunctionsJamStackBuildImage(),
ImageId = _imageHelper.GetAzureFunctionsJamStackBuildImage(ImageTestHelperConstants.AzureFunctionsJamStackBullseye),
EnvironmentVariables = new List<EnvironmentVariable>
{
CreateAppNameEnvVar(appName)
Expand All @@ -875,7 +879,7 @@ public void Builds_AzureFunctionProject_FromBlazorFunctionRepo_When_Apptype_Is_S
{
Assert.True(result.IsSuccess);
Assert.Contains(
string.Format(SdkVersionMessageFormat, FinalStretchVersions.FinalStretchDotNetCore31SdkVersion),
string.Format(SdkVersionMessageFormat, DotNetCoreSdkVersions.DotNet80SdkVersion),
result.StdOut);
},
result.GetDebugInfo());
Expand Down
24 changes: 24 additions & 0 deletions tests/SampleApps/DotNetCore/BlazorStarterAppNet8/Api/Api.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.15.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
</Project>
19 changes: 19 additions & 0 deletions tests/SampleApps/DotNetCore/BlazorStarterAppNet8/Api/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Azure.Functions.Worker.Configuration;

namespace ApiIsolated
{
public class Program
{
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.Build();

host.Run();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Linq;
using System.Net;
using BlazorApp.Shared;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace ApiIsolated
{
public class HttpTrigger
{
private readonly ILogger _logger;

public HttpTrigger(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<HttpTrigger>();
}

[Function("WeatherForecast")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req)
{
var randomNumber = new Random();
var temp = 0;

var result = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = temp = randomNumber.Next(-20, 55),
Summary = GetSummary(temp)
}).ToArray();

var response = req.CreateResponse(HttpStatusCode.OK);
response.WriteAsJsonAsync(result);

return response;
}

private string GetSummary(int temp)
{
var summary = "Mild";

if (temp >= 32)
{
summary = "Hot";
}
else if (temp <= 16 && temp > 0)
{
summary = "Cold";
}
else if (temp <= 0)
{
summary = "Freezing!";
}

return summary;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
"isEnabled": true,
"excludedTypes": "Request"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*",
"CORSCredentials": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "Client\Client.csproj", "{F4B1375B-C892-424D-9CB2-9FE2B5B47EDF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{DA2371A3-4788-4B2A-A0F0-0FF8EBB4C948}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api", "Api\Api.csproj", "{CEF28A6B-A047-4153-A4E0-5A2A921B432E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F4B1375B-C892-424D-9CB2-9FE2B5B47EDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4B1375B-C892-424D-9CB2-9FE2B5B47EDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4B1375B-C892-424D-9CB2-9FE2B5B47EDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4B1375B-C892-424D-9CB2-9FE2B5B47EDF}.Release|Any CPU.Build.0 = Release|Any CPU
{DA2371A3-4788-4B2A-A0F0-0FF8EBB4C948}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA2371A3-4788-4B2A-A0F0-0FF8EBB4C948}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA2371A3-4788-4B2A-A0F0-0FF8EBB4C948}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA2371A3-4788-4B2A-A0F0-0FF8EBB4C948}.Release|Any CPU.Build.0 = Release|Any CPU
{CEF28A6B-A047-4153-A4E0-5A2A921B432E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CEF28A6B-A047-4153-A4E0-5A2A921B432E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEF28A6B-A047-4153-A4E0-5A2A921B432E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CEF28A6B-A047-4153-A4E0-5A2A921B432E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CAEC77B5-1FF5-4E89-86CD-620314C521C4}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>BlazorApp.Client</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@page "/counter"

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p>Current count: @currentCount</p>
<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page "/fetchdata"
@page "/fetchdata"
@using BlazorApp.Shared
@inject HttpClient Http

<h1>Weather forecast</h1>
Expand Down Expand Up @@ -35,21 +36,17 @@ else
}

@code {
private WeatherForecast[] forecasts;
private WeatherForecast[] forecasts = new WeatherForecast[]{};

protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}

public class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public string Summary { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
try
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("/api/WeatherForecast") ?? new WeatherForecast[]{};
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@page "/"

<PageTitle>Index</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />
11 changes: 11 additions & 0 deletions tests/SampleApps/DotNetCore/BlazorStarterAppNet8/Client/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using BlazorApp.Client;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.Configuration["API_Prefix"] ?? builder.HostEnvironment.BaseAddress) });

await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@inherits LayoutComponentBase

<div class="page">
<div class="sidebar">
<NavMenu />
</div>

<main>
<div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
</div>

<article class="content px-4">
@Body
</article>
</main>
</div>
Loading

0 comments on commit 0b76566

Please sign in to comment.