From ea6b6bcd19915f45c5933c616b97140b712dc911 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Fri, 23 Feb 2018 13:07:49 +0000 Subject: [PATCH] Add an example API server project that can be used in E2E tests --- Blazor.sln | 9 +++- .../Tests/RoutingTest.cs | 5 ++- .../Controllers/PersonController.cs | 41 +++++++++++++++++++ test/testapps/TestServer/Program.cs | 25 +++++++++++ test/testapps/TestServer/Startup.cs | 40 ++++++++++++++++++ test/testapps/TestServer/TestServer.csproj | 15 +++++++ .../TestServer/appsettings.Development.json | 10 +++++ test/testapps/TestServer/appsettings.json | 15 +++++++ 8 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 test/testapps/TestServer/Controllers/PersonController.cs create mode 100644 test/testapps/TestServer/Program.cs create mode 100644 test/testapps/TestServer/Startup.cs create mode 100644 test/testapps/TestServer/TestServer.csproj create mode 100644 test/testapps/TestServer/appsettings.Development.json create mode 100644 test/testapps/TestServer/appsettings.json diff --git a/Blazor.sln b/Blazor.sln index 7ac8f8f225..ce8883d29c 100644 --- a/Blazor.sln +++ b/Blazor.sln @@ -66,7 +66,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AngleSharpBuilder", "src\an EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Blazor.Razor.Extensions", "src\Microsoft.AspNetCore.Blazor.Razor.Extensions\Microsoft.AspNetCore.Blazor.Razor.Extensions.csproj", "{D652A019-B765-4922-B7B8-3AB1C58338D7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Blazor.Browser.Test", "test\Microsoft.AspNetCore.Blazor.Browser.Test\Microsoft.AspNetCore.Blazor.Browser.Test.csproj", "{EC2A38BF-6E77-4A8E-A731-15929544F29C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Blazor.Browser.Test", "test\Microsoft.AspNetCore.Blazor.Browser.Test\Microsoft.AspNetCore.Blazor.Browser.Test.csproj", "{EC2A38BF-6E77-4A8E-A731-15929544F29C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestServer", "test\testapps\TestServer\TestServer.csproj", "{29CD3FC6-49E3-4756-B5DF-E03B46E5CD45}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -166,6 +168,10 @@ Global {EC2A38BF-6E77-4A8E-A731-15929544F29C}.Debug|Any CPU.Build.0 = Debug|Any CPU {EC2A38BF-6E77-4A8E-A731-15929544F29C}.Release|Any CPU.ActiveCfg = Release|Any CPU {EC2A38BF-6E77-4A8E-A731-15929544F29C}.Release|Any CPU.Build.0 = Release|Any CPU + {29CD3FC6-49E3-4756-B5DF-E03B46E5CD45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {29CD3FC6-49E3-4756-B5DF-E03B46E5CD45}.Debug|Any CPU.Build.0 = Debug|Any CPU + {29CD3FC6-49E3-4756-B5DF-E03B46E5CD45}.Release|Any CPU.ActiveCfg = Release|Any CPU + {29CD3FC6-49E3-4756-B5DF-E03B46E5CD45}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -199,6 +205,7 @@ Global {36706AC2-C851-4038-B161-9C1E44B668C8} = {4E3BD19A-6159-4548-A88F-700443E6D934} {D652A019-B765-4922-B7B8-3AB1C58338D7} = {B867E038-B3CE-43E3-9292-61568C46CDEB} {EC2A38BF-6E77-4A8E-A731-15929544F29C} = {ADA3AE29-F6DE-49F6-8C7C-B321508CAE8E} + {29CD3FC6-49E3-4756-B5DF-E03B46E5CD45} = {4AE0D35B-D97A-44D0-8392-C9240377DCCE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {504DA352-6788-4DC0-8705-82167E72A4D3} diff --git a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/RoutingTest.cs b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/RoutingTest.cs index 09c9524b77..66a4bb1fd0 100644 --- a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/RoutingTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/RoutingTest.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using BasicTestApp; using BasicTestApp.RouterTest; using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure; diff --git a/test/testapps/TestServer/Controllers/PersonController.cs b/test/testapps/TestServer/Controllers/PersonController.cs new file mode 100644 index 0000000000..07e166d5e5 --- /dev/null +++ b/test/testapps/TestServer/Controllers/PersonController.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; + +namespace TestServer.Controllers +{ + [Route("api/[controller]")] + public class PersonController : Controller + { + // GET api/values + [HttpGet] + public IEnumerable Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api/values/5 + [HttpGet("{id}")] + public string Get(int id) + { + return "value"; + } + + // POST api/values + [HttpPost] + public void Post([FromBody]string value) + { + } + + // PUT api/values/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody]string value) + { + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/test/testapps/TestServer/Program.cs b/test/testapps/TestServer/Program.cs new file mode 100644 index 0000000000..630210191e --- /dev/null +++ b/test/testapps/TestServer/Program.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace TestServer +{ + public class Program + { + public static void Main(string[] args) + { + BuildWebHost(args).Run(); + } + + public static IWebHost BuildWebHost(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup() + .Build(); + } +} diff --git a/test/testapps/TestServer/Startup.cs b/test/testapps/TestServer/Startup.cs new file mode 100644 index 0000000000..f26d799fcc --- /dev/null +++ b/test/testapps/TestServer/Startup.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +namespace TestServer +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseMvc(); + } + } +} diff --git a/test/testapps/TestServer/TestServer.csproj b/test/testapps/TestServer/TestServer.csproj new file mode 100644 index 0000000000..b36fc56a53 --- /dev/null +++ b/test/testapps/TestServer/TestServer.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp2.0 + + + + + + + + + + + diff --git a/test/testapps/TestServer/appsettings.Development.json b/test/testapps/TestServer/appsettings.Development.json new file mode 100644 index 0000000000..fa8ce71a97 --- /dev/null +++ b/test/testapps/TestServer/appsettings.Development.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/test/testapps/TestServer/appsettings.json b/test/testapps/TestServer/appsettings.json new file mode 100644 index 0000000000..26bb0ac7ac --- /dev/null +++ b/test/testapps/TestServer/appsettings.json @@ -0,0 +1,15 @@ +{ + "Logging": { + "IncludeScopes": false, + "Debug": { + "LogLevel": { + "Default": "Warning" + } + }, + "Console": { + "LogLevel": { + "Default": "Warning" + } + } + } +}