Skip to content

Commit db1c1c5

Browse files
committed
e2e test
1 parent 6eb9ee8 commit db1c1c5

24 files changed

+6595
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(ThreadingApp.Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
5+
</Found>
6+
<NotFound>
7+
<LayoutView Layout="@typeof(MainLayout)">
8+
<h2>Not found</h2>
9+
Sorry, there's nothing at this address.
10+
</LayoutView>
11+
</NotFound>
12+
</Router>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@page "/counter"
2+
@using System.Runtime.InteropServices
3+
4+
<h1>Counter</h1>
5+
6+
<p>Current count: @currentCount</p>
7+
8+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
9+
10+
@code {
11+
int currentCount = 0;
12+
13+
void IncrementCount()
14+
{
15+
currentCount++;
16+
}
17+
18+
protected override Task OnInitializedAsync()
19+
{
20+
if(!RuntimeInformation.IsOSPlatform(OSPlatform.Create("Browser"))){
21+
return Task.CompletedTask;
22+
}
23+
new Timer(async (state) =>
24+
{
25+
// send me to the thread pool
26+
await Task.Delay(10).ConfigureAwait(false);
27+
28+
await InvokeAsync(() =>
29+
{
30+
// we are back on main thread
31+
IncrementCount();
32+
StateHasChanged(); // render!
33+
});
34+
}, null, 0, 100);
35+
return Task.CompletedTask;
36+
}
37+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
@page "/fetchdata"
2+
@page "/fetchdata/{StartDate:datetime}"
3+
@inject HttpClient Http
4+
5+
<h1>Weather forecast</h1>
6+
7+
<p>This component demonstrates fetching data from the server.</p>
8+
9+
@if (forecasts == null)
10+
{
11+
<p><em>Loading...</em></p>
12+
}
13+
else
14+
{
15+
<table class='table'>
16+
<thead>
17+
<tr>
18+
<th>Date</th>
19+
<th>Temp. (C)</th>
20+
<th>Temp. (F)</th>
21+
<th>Summary</th>
22+
</tr>
23+
</thead>
24+
<tbody>
25+
@foreach (var forecast in forecasts)
26+
{
27+
<tr>
28+
<td>@forecast.DateFormatted</td>
29+
<td>@forecast.TemperatureC</td>
30+
<td>@forecast.TemperatureF</td>
31+
<td>@forecast.Summary</td>
32+
</tr>
33+
}
34+
</tbody>
35+
</table>
36+
<p>
37+
<a href="fetchdata/@startDate.AddDays(-5).ToString("yyyy-MM-dd")" class="btn btn-secondary float-left">
38+
Previous
39+
</a>
40+
<a href="fetchdata/@startDate.AddDays(5).ToString("yyyy-MM-dd")" class="btn btn-secondary float-right">
41+
Next
42+
</a>
43+
</p>
44+
}
45+
46+
@code {
47+
[Parameter] public DateTime? StartDate { get; set; }
48+
49+
WeatherForecast[] forecasts;
50+
DateTime startDate;
51+
52+
protected override async Task OnParametersSetAsync()
53+
{
54+
startDate = StartDate.GetValueOrDefault(DateTime.Now);
55+
56+
// send me to the thread pool, next line HTTP should work anyway
57+
await Task.Delay(10).ConfigureAwait(false);
58+
59+
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>(
60+
$"sample-data/weather.json?date={startDate.ToString("yyyy-MM-dd")}");
61+
62+
// Because ThreadingApp doesn't really have a server endpoint to get dynamic data from,
63+
// fake the DateFormatted values here. This would not apply in a real app.
64+
for (var i = 0; i < forecasts.Length; i++)
65+
{
66+
forecasts[i].DateFormatted = startDate.AddDays(i).ToShortDateString();
67+
}
68+
}
69+
70+
class WeatherForecast
71+
{
72+
public string DateFormatted { get; set; }
73+
public int TemperatureC { get; set; }
74+
public int TemperatureF { get; set; }
75+
public string Summary { get; set; }
76+
}
77+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@page "/"
2+
3+
<h1>Hello, world!</h1>
4+
5+
Welcome to your new app.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Net.Http;
5+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
6+
7+
namespace ThreadingApp;
8+
9+
public class Program
10+
{
11+
public static async Task Main(string[] args)
12+
{
13+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
14+
builder.RootComponents.Add<App>("app");
15+
builder.Services.AddSingleton(new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
16+
17+
await builder.Build().RunAsync();
18+
}
19+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:56502/",
7+
"sslPort": 44332
8+
}
9+
},
10+
"profiles": {
11+
"ThreadingApp": {
12+
"commandName": "Project",
13+
"launchBrowser": true,
14+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
},
18+
"applicationUrl": "https://localhost:5001;http://localhost:5000"
19+
},
20+
"IIS Express": {
21+
"commandName": "IISExpress",
22+
"launchBrowser": true,
23+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
24+
"environmentVariables": {
25+
"ASPNETCORE_ENVIRONMENT": "Development"
26+
}
27+
}
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="sidebar">
4+
<NavMenu />
5+
</div>
6+
7+
<div class="main">
8+
<div class="top-row px-4">
9+
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
10+
</div>
11+
12+
<div class="content px-4">
13+
@Body
14+
</div>
15+
</div>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<div class="top-row pl-4 navbar navbar-dark">
2+
<a class="navbar-brand" href="">Blazor app</a>
3+
<button class="navbar-toggler" @onclick=ToggleNavMenu>
4+
<span class="navbar-toggler-icon"></span>
5+
</button>
6+
</div>
7+
8+
<div class=@(collapseNavMenu ? "collapse" : null) @onclick=ToggleNavMenu>
9+
<ul class="nav flex-column">
10+
<li class="nav-item px-3">
11+
<NavLink class="nav-link" href="" Match=NavLinkMatch.All>
12+
<span class="bi bi-house-door-fill" aria-hidden="true"></span> Home
13+
</NavLink>
14+
</li>
15+
<li class="nav-item px-3">
16+
<NavLink class="nav-link" href="counter">
17+
<span class="bi bi-plus-square-fill" aria-hidden="true"></span> Counter
18+
</NavLink>
19+
</li>
20+
<li class="nav-item px-3">
21+
<NavLink class="nav-link" href="fetchdata">
22+
<span class="bi bi-list-nested" aria-hidden="true"></span> Fetch data
23+
</NavLink>
24+
</li>
25+
</ul>
26+
</div>
27+
28+
@code {
29+
bool collapseNavMenu = true;
30+
31+
void ToggleNavMenu()
32+
{
33+
collapseNavMenu = !collapseNavMenu;
34+
}
35+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
5+
<WasmEnableThreads>true</WasmEnableThreads>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly" />
10+
<Reference Include="System.Net.Http.Json" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@using System.Net.Http
2+
@using System.Net.Http.Json
3+
@using Microsoft.AspNetCore.Components.Routing
4+
@using Microsoft.AspNetCore.Components.Web
5+
@using ThreadingApp
6+
@using ThreadingApp.Shared

0 commit comments

Comments
 (0)