Skip to content

Commit 06e2cef

Browse files
committed
Rename back
1 parent ad12216 commit 06e2cef

30 files changed

+1270
-1
lines changed

src/Components/test/E2ETest/Microsoft.AspNetCore.Components.E2ETests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<ProjectReference Include="..\..\WebAssembly\testassets\StandaloneApp\StandaloneApp.csproj" />
4545
<ProjectReference Include="..\..\WebAssembly\DevServer\src\Microsoft.AspNetCore.Components.WebAssembly.DevServer.csproj" />
4646
<ProjectReference Include="..\testassets\BasicTestApp\BasicTestApp.csproj" />
47-
<ProjectReference Include="..\testassets\Components.TestServer\Components.TestServer.csproj" />
47+
<ProjectReference Include="..\testassets\TestServer\Components.TestServer.csproj" />
4848
<ProjectReference Include="..\..\WebAssembly\testassets\Wasm.Authentication.Server\Wasm.Authentication.Server.csproj" />
4949
</ItemGroup>
5050

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using Microsoft.AspNetCore.Authentication.Cookies;
3+
using Microsoft.AspNetCore.Builder;
4+
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.AspNetCore.Routing;
6+
using Microsoft.Extensions.Configuration;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.Hosting;
9+
10+
namespace TestServer
11+
{
12+
public class AuthenticationStartupBase
13+
{
14+
private readonly Action<IEndpointRouteBuilder> _configureMode;
15+
16+
public AuthenticationStartupBase(IConfiguration configuration, Action<IEndpointRouteBuilder> configureMode)
17+
{
18+
Configuration = configuration;
19+
_configureMode = configureMode;
20+
}
21+
22+
public IConfiguration Configuration { get; }
23+
24+
// This method gets called by the runtime. Use this method to add services to the container.
25+
public void ConfigureServices(IServiceCollection services)
26+
{
27+
services.AddMvc();
28+
29+
services.AddServerSideBlazor();
30+
31+
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
32+
services.AddAuthorization(options =>
33+
{
34+
options.AddPolicy("NameMustStartWithB", policy =>
35+
policy.RequireAssertion(ctx => ctx.User.Identity.Name?.StartsWith("B") ?? false));
36+
});
37+
}
38+
39+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
40+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
41+
{
42+
if (env.IsDevelopment())
43+
{
44+
app.UseDeveloperExceptionPage();
45+
}
46+
47+
app.UseAuthentication();
48+
49+
// Mount the server-side Blazor app on /subdir
50+
app.Map("/subdir", app =>
51+
{
52+
app.UseBlazorFrameworkFiles();
53+
app.UseStaticFiles();
54+
55+
app.UseRouting();
56+
app.UseEndpoints(endpoints =>
57+
{
58+
endpoints.MapControllers();
59+
endpoints.MapRazorPages();
60+
endpoints.MapBlazorHub();
61+
_configureMode(endpoints);
62+
});
63+
});
64+
}
65+
}
66+
67+
public class AuthenticationStartup : AuthenticationStartupBase
68+
{
69+
public AuthenticationStartup(IConfiguration configuration)
70+
: base(configuration, (endpoints) => endpoints.MapFallbackToFile("index.html"))
71+
{
72+
}
73+
}
74+
75+
public class ServerAuthenticationStartup : AuthenticationStartupBase
76+
{
77+
public ServerAuthenticationStartup(IConfiguration configuration)
78+
: base(configuration, (endpoints) => endpoints.MapFallbackToPage("/_ServerHost"))
79+
{
80+
}
81+
}
82+
83+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.Configuration;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Hosting;
6+
7+
namespace TestServer
8+
{
9+
// WARNING: DO NOT MODIFY THIS STARTUP CLASS FOR TEST PURPOSES
10+
// Most of the client-side tests are executed using the developer host directly, so changing values here won't
11+
// affect any client-side test.
12+
public class ClientStartup
13+
{
14+
public ClientStartup(IConfiguration configuration)
15+
{
16+
Configuration = configuration;
17+
}
18+
19+
public IConfiguration Configuration { get; }
20+
21+
// This method gets called by the runtime. Use this method to add services to the container.
22+
public void ConfigureServices(IServiceCollection services)
23+
{
24+
services.AddMvc();
25+
services.AddServerSideBlazor();
26+
}
27+
28+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
29+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
30+
{
31+
if (env.IsDevelopment())
32+
{
33+
app.UseDeveloperExceptionPage();
34+
}
35+
36+
// Mount the server-side Blazor app on /subdir
37+
app.Map("/subdir", app =>
38+
{
39+
// Add it before to ensure it takes priority over files in wwwroot
40+
app.UseBlazorFrameworkFiles();
41+
app.UseStaticFiles();
42+
43+
app.UseRouting();
44+
app.UseEndpoints(endpoints =>
45+
{
46+
endpoints.MapRazorPages();
47+
endpoints.MapControllers();
48+
endpoints.MapFallbackToFile("index.html");
49+
});
50+
});
51+
}
52+
}
53+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
5+
<CompileUsingReferenceAssemblies>false</CompileUsingReferenceAssemblies>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Reference Include="Microsoft.AspNetCore" />
10+
<Reference Include="Microsoft.AspNetCore.Authentication.Cookies" />
11+
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" />
12+
<Reference Include="Microsoft.AspNetCore.Components.Server" />
13+
<Reference Include="Microsoft.AspNetCore.Cors" />
14+
<Reference Include="Microsoft.AspNetCore.Mvc" />
15+
<Reference Include="Microsoft.AspNetCore.Components.Server" />
16+
<Reference Include="Microsoft.AspNetCore.Cors" />
17+
<Reference Include="Microsoft.AspNetCore.Mvc" />
18+
<Reference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" />
19+
<Reference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" />
20+
<Reference Include="Microsoft.AspNetCore.Testing" />
21+
<Reference Include="Microsoft.Extensions.Hosting" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<ProjectReference Include="..\..\..\WebAssembly\DevServer\src\Microsoft.AspNetCore.Components.WebAssembly.DevServer.csproj" />
26+
<ProjectReference Include="..\BasicTestApp\BasicTestApp.csproj" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
31+
<_Parameter1>Microsoft.AspNetCore.Testing.BasicTestApp.ContentRoot</_Parameter1>
32+
<_Parameter2 Condition="$(IsHelixJob) != 'true'">$([MSBuild]::NormalizeDirectory('$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\BasicTestApp'))'))</_Parameter2>
33+
<_Parameter2 Condition="$(IsHelixJob) == 'true'">..\BasicTestApp'))'))</_Parameter2>
34+
</AssemblyAttribute>
35+
</ItemGroup>
36+
37+
<Target Name="CopyClientAssetsForTest" BeforeTargets="Build"
38+
Inputs="..\BasicTestApp\wwwroot\js\jsinteroptests.js;
39+
..\BasicTestApp\wwwroot\NotAComponent.html;
40+
..\BasicTestApp\wwwroot\style.css"
41+
Outputs="wwwroot\js\jsinteroptests.js;
42+
wwwroot\NotAComponent.html;
43+
wwwroot\style.css">
44+
45+
<MakeDir Directories="wwwroot" />
46+
47+
<Copy SourceFiles="..\BasicTestApp\wwwroot\js\jsinteroptests.js;..\BasicTestApp\wwwroot\NotAComponent.html;..\BasicTestApp\wwwroot\style.css"
48+
DestinationFiles="wwwroot\js\jsinteroptests.js;wwwroot\NotAComponent.html;wwwroot\style.css" />
49+
</Target>
50+
</Project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.AspNetCore.Cors;
2+
using Microsoft.AspNetCore.Mvc;
3+
4+
namespace TestServer.Controllers
5+
{
6+
[Route("api/[controller]/[action]")]
7+
[EnableCors("AllowAll")] // Only because the test client apps runs on a different origin
8+
public class CookieController : Controller
9+
{
10+
const string cookieKey = "test-counter-cookie";
11+
12+
public string Reset()
13+
{
14+
Response.Cookies.Delete(cookieKey);
15+
return "Reset completed";
16+
}
17+
18+
public string Increment()
19+
{
20+
var counter = 0;
21+
if (Request.Cookies.TryGetValue(cookieKey, out var incomingValue))
22+
{
23+
counter = int.Parse(incomingValue);
24+
}
25+
26+
counter++;
27+
Response.Cookies.Append(cookieKey, counter.ToString());
28+
29+
return $"Counter value is {counter}";
30+
}
31+
}
32+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Text.Encodings.Web;
2+
using Microsoft.AspNetCore.Localization;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.AspNetCore.WebUtilities;
5+
using Microsoft.Net.Http.Headers;
6+
7+
namespace Components.TestServer.Controllers
8+
{
9+
[Route("[controller]/[action]")]
10+
public class CultureController : Controller
11+
{
12+
public IActionResult SetCulture(string culture, string redirectUri)
13+
{
14+
if (culture != null)
15+
{
16+
HttpContext.Response.Cookies.Append(
17+
CookieRequestCultureProvider.DefaultCookieName,
18+
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)));
19+
}
20+
21+
var htmlEncoder = HtmlEncoder.Default;
22+
var html = $"<h1>Culture has been changed to {htmlEncoder.Encode(culture)}</h1>" +
23+
$"<a class='return-from-culture-setter' href='{htmlEncoder.Encode(redirectUri)}'>Return to previous page</a>";
24+
return Content(html, "text/html");
25+
}
26+
}
27+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.IO;
3+
using System.Threading.Tasks;
4+
using Microsoft.AspNetCore.Cors;
5+
using Microsoft.AspNetCore.Mvc;
6+
7+
namespace TestServer.Controllers
8+
{
9+
[EnableCors("AllowAll")]
10+
[Route("api/[controller]")]
11+
public class DataController : Controller
12+
{
13+
// GET api/data
14+
[HttpGet]
15+
public FileContentResult Get()
16+
{
17+
var bytes = new byte[byte.MaxValue + 1];
18+
for (int i = 0; i <= byte.MaxValue; i++)
19+
{
20+
bytes[i] = (byte)i;
21+
}
22+
23+
return File(bytes, "application/octet-stream");
24+
}
25+
26+
// POST api/data
27+
[HttpPost]
28+
public async Task<IActionResult> PostAsync()
29+
{
30+
var ms = new MemoryStream();
31+
await Request.Body.CopyToAsync(ms);
32+
var bytes = ms.ToArray();
33+
Array.Reverse(bytes);
34+
35+
for (int i = 0; i <= byte.MaxValue; i++)
36+
{
37+
if (bytes[i] != (byte)i)
38+
{
39+
return BadRequest();
40+
}
41+
}
42+
43+
return File(bytes, "application/octet-stream");
44+
}
45+
}
46+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace TestServer.Controllers
4+
{
5+
[Route("api/[controller]/[action]")]
6+
public class GreetingController : Controller
7+
{
8+
[HttpGet]
9+
public string SayHello() => "Hello";
10+
}
11+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System.Collections.Generic;
2+
using System.ComponentModel.DataAnnotations;
3+
using System.IO;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Cors;
7+
using Microsoft.AspNetCore.Mvc;
8+
9+
namespace TestServer.Controllers
10+
{
11+
[EnableCors("AllowAll")]
12+
[Route("api/[controller]")]
13+
public class PersonController : Controller
14+
{
15+
// GET api/person
16+
[HttpGet]
17+
public IEnumerable<string> Get()
18+
{
19+
HttpContext.Response.Headers.Add("MyCustomHeader", "My custom value");
20+
return new string[] { "value1", "value2" };
21+
}
22+
23+
// POST api/person
24+
[HttpPost]
25+
public async Task<string> Post()
26+
{
27+
using (var reader = new StreamReader(Request.Body))
28+
{
29+
var plainTextBodyContent = await reader.ReadToEndAsync();
30+
return $"You posted: {plainTextBodyContent}";
31+
}
32+
}
33+
34+
[HttpGet("referrer")]
35+
public string GetReferer()
36+
{
37+
return $"The referrer is: {Request.Headers["Referer"].ToString()}";
38+
}
39+
40+
// PUT api/person
41+
[HttpPut]
42+
public Person Put([FromBody, Required] Person person)
43+
{
44+
return person;
45+
}
46+
47+
// DELETE api/person
48+
[HttpDelete]
49+
public string Delete()
50+
{
51+
var result = new StringBuilder();
52+
foreach (var header in Request.Headers)
53+
{
54+
result.AppendLine($"{header.Key}: {string.Join(",", header.Value.ToArray())}");
55+
}
56+
return "REQUEST HEADERS:\n" + result.ToString();
57+
}
58+
59+
public class Person
60+
{
61+
public int Id { get; set; }
62+
public string Name { get; set; }
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)