diff --git a/samples/DatabaseErrorPageSample/Startup.cs b/samples/DatabaseErrorPageSample/Startup.cs index d6ee399eea..2db005de6e 100644 --- a/samples/DatabaseErrorPageSample/Startup.cs +++ b/samples/DatabaseErrorPageSample/Startup.cs @@ -1,9 +1,9 @@ -using System; -using Microsoft.AspNet.Builder; -using Microsoft.Data.Entity; using System.Linq; -using Microsoft.Extensions.DependencyInjection; using System.Threading.Tasks; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; +using Microsoft.Data.Entity; +using Microsoft.Extensions.DependencyInjection; namespace DatabaseErrorPageSample { @@ -26,6 +26,16 @@ namespace DatabaseErrorPageSample return Task.FromResult(0); }); } + + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + application.Run(); + } } public class MyContext : DbContext diff --git a/samples/DatabaseErrorPageSample/hosting.json b/samples/DatabaseErrorPageSample/hosting.json new file mode 100644 index 0000000000..95505372fa --- /dev/null +++ b/samples/DatabaseErrorPageSample/hosting.json @@ -0,0 +1,3 @@ +{ + "server": "Microsoft.AspNet.Server.Kestrel" +} \ No newline at end of file diff --git a/samples/DatabaseErrorPageSample/project.json b/samples/DatabaseErrorPageSample/project.json index 1c7bbee770..723265ec80 100644 --- a/samples/DatabaseErrorPageSample/project.json +++ b/samples/DatabaseErrorPageSample/project.json @@ -1,15 +1,15 @@ { - "webroot": "wwwroot", "dependencies": { "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*", "EntityFramework.MicrosoftSqlServer": "7.0.0-*", "EntityFramework.Commands": "7.0.0-*", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" }, + "compilationOptions": { + "emitEntryPoint": true + }, "commands": { - "ef": "EntityFramework.Commands", - "web": "Microsoft.AspNet.Server.Kestrel" + "web": "DatabaseErrorPageSample" }, "frameworks": { "dnx451": { }, diff --git a/samples/DeveloperExceptionPageSample/Startup.cs b/samples/DeveloperExceptionPageSample/Startup.cs index 7b4c399981..84d20df70e 100644 --- a/samples/DeveloperExceptionPageSample/Startup.cs +++ b/samples/DeveloperExceptionPageSample/Startup.cs @@ -1,5 +1,6 @@ using System; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; namespace DeveloperExceptionPageSample { @@ -17,5 +18,15 @@ namespace DeveloperExceptionPageSample "New Line 3")); }); } + + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + application.Run(); + } } } \ No newline at end of file diff --git a/samples/DeveloperExceptionPageSample/hosting.json b/samples/DeveloperExceptionPageSample/hosting.json new file mode 100644 index 0000000000..f8ef14574d --- /dev/null +++ b/samples/DeveloperExceptionPageSample/hosting.json @@ -0,0 +1,3 @@ +{ + "server": "Microsoft.AspNet.Server.Kestrel" +} diff --git a/samples/DeveloperExceptionPageSample/project.json b/samples/DeveloperExceptionPageSample/project.json index 9e3ae7064e..44c8cea4f1 100644 --- a/samples/DeveloperExceptionPageSample/project.json +++ b/samples/DeveloperExceptionPageSample/project.json @@ -1,11 +1,14 @@ { - "webroot" : "wwwroot", "dependencies": { "Microsoft.AspNet.Diagnostics": "1.0.0-*", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*", - "Microsoft.AspNet.Server.IIS": "1.0.0-*" + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" + }, + "compilationOptions": { + "emitEntryPoint": true + }, + "commands": { + "web": "DeveloperExceptionPageSample" }, - "commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }, "frameworks": { "dnx451": {}, "dnxcore50": {} diff --git a/samples/DeveloperExceptionPageSample/wwwroot/web.config b/samples/DeveloperExceptionPageSample/wwwroot/web.config new file mode 100644 index 0000000000..9a0d90abf8 --- /dev/null +++ b/samples/DeveloperExceptionPageSample/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/samples/ElmPageSample/Startup.cs b/samples/ElmPageSample/Startup.cs index b24ea94d0c..2ad04c59c1 100644 --- a/samples/ElmPageSample/Startup.cs +++ b/samples/ElmPageSample/Startup.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -27,5 +28,15 @@ namespace ElmPageSample app.UseMiddleware(); } + + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + application.Run(); + } } } diff --git a/samples/ElmPageSample/hosting.json b/samples/ElmPageSample/hosting.json new file mode 100644 index 0000000000..f8ef14574d --- /dev/null +++ b/samples/ElmPageSample/hosting.json @@ -0,0 +1,3 @@ +{ + "server": "Microsoft.AspNet.Server.Kestrel" +} diff --git a/samples/ElmPageSample/project.json b/samples/ElmPageSample/project.json index f32a35eaa4..44ece82e8e 100644 --- a/samples/ElmPageSample/project.json +++ b/samples/ElmPageSample/project.json @@ -1,16 +1,17 @@ { - "webroot": "wwwroot", - "exclude": "wwwroot/**/*.*", - "dependencies": { - "Microsoft.AspNet.Diagnostics.Elm": "1.0.0-*", - "Microsoft.AspNet.Server.IIS": "1.0.0-*", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*" - }, - "commands": { - "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000" - }, - "frameworks": { - "dnx451" : { }, - "dnxcore50" : { } - } + "exclude": "wwwroot/**/*.*", + "dependencies": { + "Microsoft.AspNet.Diagnostics.Elm": "1.0.0-*", + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" + }, + "compilationOptions": { + "emitEntryPoint": true + }, + "commands": { + "web": "ElmPageSample" + }, + "frameworks": { + "dnx451": { }, + "dnxcore50": { } + } } diff --git a/samples/ElmPageSample/wwwroot/web.config b/samples/ElmPageSample/wwwroot/web.config new file mode 100644 index 0000000000..9a0d90abf8 --- /dev/null +++ b/samples/ElmPageSample/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/samples/ExceptionHandlerSample/Startup.cs b/samples/ExceptionHandlerSample/Startup.cs index f57adf61b2..ed5848014e 100644 --- a/samples/ExceptionHandlerSample/Startup.cs +++ b/samples/ExceptionHandlerSample/Startup.cs @@ -2,6 +2,7 @@ using System; using System.Text.Encodings.Web; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; @@ -54,5 +55,15 @@ namespace ExceptionHandlerSample await context.Response.WriteAsync("\r\n"); }); } + + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + application.Run(); + } } } diff --git a/samples/ExceptionHandlerSample/hosting.json b/samples/ExceptionHandlerSample/hosting.json new file mode 100644 index 0000000000..95505372fa --- /dev/null +++ b/samples/ExceptionHandlerSample/hosting.json @@ -0,0 +1,3 @@ +{ + "server": "Microsoft.AspNet.Server.Kestrel" +} \ No newline at end of file diff --git a/samples/ExceptionHandlerSample/project.json b/samples/ExceptionHandlerSample/project.json index ae20efb807..b736772f74 100644 --- a/samples/ExceptionHandlerSample/project.json +++ b/samples/ExceptionHandlerSample/project.json @@ -1,17 +1,18 @@ { - "webroot": "wwwroot", - "exclude": "wwwroot/**/*.*", - "dependencies": { - "Microsoft.AspNet.Diagnostics": "1.0.0-*", - "Microsoft.AspNet.Server.IIS": "1.0.0-*", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*", - "Microsoft.AspNet.StaticFiles": "1.0.0-*" - }, - "commands": { - "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000" - }, - "frameworks": { - "dnx451" : { }, - "dnxcore50" : { } - } + "exclude": "wwwroot/**/*.*", + "dependencies": { + "Microsoft.AspNet.Diagnostics": "1.0.0-*", + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", + "Microsoft.AspNet.StaticFiles": "1.0.0-*" + }, + "compilationOptions": { + "emitEntryPoint": true + }, + "commands": { + "web": "ExceptionHandlerSample" + }, + "frameworks": { + "dnx451": { }, + "dnxcore50": { } + } } diff --git a/samples/ExceptionHandlerSample/wwwroot/web.config b/samples/ExceptionHandlerSample/wwwroot/web.config new file mode 100644 index 0000000000..9a0d90abf8 --- /dev/null +++ b/samples/ExceptionHandlerSample/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/samples/MiddlewareAnalysisSample/Startup.cs b/samples/MiddlewareAnalysisSample/Startup.cs index be1ba2c169..1bee7b7822 100644 --- a/samples/MiddlewareAnalysisSample/Startup.cs +++ b/samples/MiddlewareAnalysisSample/Startup.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DiagnosticAdapter; @@ -82,6 +83,16 @@ namespace MiddlewareAnaysisSample // Note there's always a default 404 middleware at the end of the pipeline. } + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + application.Run(); + } + public class TestDiagnosticListener { [DiagnosticName("Microsoft.AspNet.MiddlewareAnalysis.MiddlewareStarting")] diff --git a/samples/MiddlewareAnalysisSample/hosting.json b/samples/MiddlewareAnalysisSample/hosting.json new file mode 100644 index 0000000000..f8ef14574d --- /dev/null +++ b/samples/MiddlewareAnalysisSample/hosting.json @@ -0,0 +1,3 @@ +{ + "server": "Microsoft.AspNet.Server.Kestrel" +} diff --git a/samples/MiddlewareAnalysisSample/project.json b/samples/MiddlewareAnalysisSample/project.json index b717045670..9cf6facce2 100644 --- a/samples/MiddlewareAnalysisSample/project.json +++ b/samples/MiddlewareAnalysisSample/project.json @@ -4,13 +4,14 @@ "Microsoft.AspNet.IISPlatformHandler": "1.0.0-*", "Microsoft.AspNet.MiddlewareAnalysis": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*", "Microsoft.Extensions.Logging.Console": "1.0.0-*" }, + "compilationOptions": { + "emitEntryPoint": true + }, "commands": { - "web": "Microsoft.AspNet.Server.Kestrel", - "weblistener": "Microsoft.AspNet.Server.WebListener" + "web": "MiddlewareAnalysisSample" }, "frameworks": { "dnx451": { }, diff --git a/samples/MiddlewareAnalysisSample/wwwroot/web.config b/samples/MiddlewareAnalysisSample/wwwroot/web.config new file mode 100644 index 0000000000..9a0d90abf8 --- /dev/null +++ b/samples/MiddlewareAnalysisSample/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/samples/RuntimeInfoPageSample/Startup.cs b/samples/RuntimeInfoPageSample/Startup.cs index 7fa53965c7..f62727e88a 100644 --- a/samples/RuntimeInfoPageSample/Startup.cs +++ b/samples/RuntimeInfoPageSample/Startup.cs @@ -1,8 +1,6 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.Diagnostics; -using Microsoft.AspNet.Http; +using Microsoft.AspNet.Hosting; namespace RuntimeInfoPageSample { @@ -20,5 +18,15 @@ namespace RuntimeInfoPageSample return Task.FromResult(0); }); } + + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + application.Run(); + } } } diff --git a/samples/RuntimeInfoPageSample/hosting.json b/samples/RuntimeInfoPageSample/hosting.json new file mode 100644 index 0000000000..f8ef14574d --- /dev/null +++ b/samples/RuntimeInfoPageSample/hosting.json @@ -0,0 +1,3 @@ +{ + "server": "Microsoft.AspNet.Server.Kestrel" +} diff --git a/samples/RuntimeInfoPageSample/project.json b/samples/RuntimeInfoPageSample/project.json index ac82c9348c..53237a83d4 100644 --- a/samples/RuntimeInfoPageSample/project.json +++ b/samples/RuntimeInfoPageSample/project.json @@ -1,12 +1,17 @@ { - "webroot" : "wwwroot", - "exclude": "wwwroot/**/*.*", - "dependencies": { - "Microsoft.AspNet.Diagnostics": "", - "Microsoft.AspNet.Server.IIS": "1.0.0-*" - }, - "frameworks" : { - "dnx451" : { }, - "dnxcore50" : { } - } + "exclude": "wwwroot/**/*.*", + "dependencies": { + "Microsoft.AspNet.Diagnostics": "", + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" + }, + "compilationOptions": { + "emitEntryPoint": true + }, + "commands": { + "web": "RuntimeInfoPageSample" + }, + "frameworks": { + "dnx451": { }, + "dnxcore50": { } + } } diff --git a/samples/StatusCodePagesSample/Startup.cs b/samples/StatusCodePagesSample/Startup.cs index 5f0220db85..eb8a588b82 100644 --- a/samples/StatusCodePagesSample/Startup.cs +++ b/samples/StatusCodePagesSample/Startup.cs @@ -8,6 +8,7 @@ using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; @@ -100,5 +101,15 @@ namespace StatusCodePagesSample await context.Response.WriteAsync(builder.ToString()); }); } + + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + application.Run(); + } } } \ No newline at end of file diff --git a/samples/StatusCodePagesSample/hosting.json b/samples/StatusCodePagesSample/hosting.json new file mode 100644 index 0000000000..70173d92bb --- /dev/null +++ b/samples/StatusCodePagesSample/hosting.json @@ -0,0 +1,4 @@ +{ + "server": "Microsoft.AspNet.Server.Kestrel", + "server.urls": "http://localhost:5001/base" +} diff --git a/samples/StatusCodePagesSample/project.json b/samples/StatusCodePagesSample/project.json index 6a2e911283..ffda530d78 100644 --- a/samples/StatusCodePagesSample/project.json +++ b/samples/StatusCodePagesSample/project.json @@ -1,24 +1,25 @@ { - "webroot": "wwwroot", - "version": "1.0.0-*", - "exclude": [ - "wwwroot" - ], - "packExclude": [ - "node_modules", - "bower_components", - "**.kproj", - "**.user", - "**.vspscc" - ], - "commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001/base" }, - "dependencies": { - "Microsoft.AspNet.Diagnostics": "1.0.0-*", - "Microsoft.AspNet.Server.IIS": "1.0.0-*", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*" - }, - "frameworks" : { - "dnx451" : { }, - "dnxcore50" : { } - } + "version": "1.0.0-*", + "exclude": [ + "wwwroot" + ], + "packExclude": [ + "node_modules", + "bower_components", + "**.kproj", + "**.user", + "**.vspscc" + ], + "compilationOptions": { + "emitEntryPoint": true + }, + "commands": { "web": "StatusCodePagesSample" }, + "dependencies": { + "Microsoft.AspNet.Diagnostics": "1.0.0-*", + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" + }, + "frameworks": { + "dnx451": { }, + "dnxcore50": { } + } } diff --git a/samples/StatusCodePagesSample/wwwroot/web.config b/samples/StatusCodePagesSample/wwwroot/web.config new file mode 100644 index 0000000000..9a0d90abf8 --- /dev/null +++ b/samples/StatusCodePagesSample/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/samples/WelcomePageSample/Startup.cs b/samples/WelcomePageSample/Startup.cs index 24bbfdeee4..70eba38f6c 100644 --- a/samples/WelcomePageSample/Startup.cs +++ b/samples/WelcomePageSample/Startup.cs @@ -1,5 +1,5 @@ -using Microsoft.AspNet; -using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; namespace WelcomePageSample { @@ -9,5 +9,15 @@ namespace WelcomePageSample { app.UseWelcomePage(); } + + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + application.Run(); + } } } diff --git a/samples/WelcomePageSample/hosting.json b/samples/WelcomePageSample/hosting.json new file mode 100644 index 0000000000..f8ef14574d --- /dev/null +++ b/samples/WelcomePageSample/hosting.json @@ -0,0 +1,3 @@ +{ + "server": "Microsoft.AspNet.Server.Kestrel" +} diff --git a/samples/WelcomePageSample/project.json b/samples/WelcomePageSample/project.json index bcf996b045..7a8798879b 100644 --- a/samples/WelcomePageSample/project.json +++ b/samples/WelcomePageSample/project.json @@ -1,13 +1,14 @@ { - "webroot": "wwwroot", - "dependencies": { - "Microsoft.AspNet.Diagnostics": "", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*", - "Microsoft.AspNet.Server.IIS": "1.0.0-*" - }, - "commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" }, - "frameworks": { - "dnx451": { }, - "dnxcore50": { } - } + "dependencies": { + "Microsoft.AspNet.Diagnostics": "", + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" + }, + "compilationOptions": { + "emitEntryPoint": true + }, + "commands": { "web": "WelcomePageSample" }, + "frameworks": { + "dnx451": { }, + "dnxcore50": { } + } } diff --git a/samples/WelcomePageSample/wwwroot/web.config b/samples/WelcomePageSample/wwwroot/web.config new file mode 100644 index 0000000000..9a0d90abf8 --- /dev/null +++ b/samples/WelcomePageSample/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Diagnostics.Entity.FunctionalTests/DatabaseErrorPageMiddlewareTest.cs b/test/Microsoft.AspNet.Diagnostics.Entity.FunctionalTests/DatabaseErrorPageMiddlewareTest.cs index e979e54fc7..66537353c7 100644 --- a/test/Microsoft.AspNet.Diagnostics.Entity.FunctionalTests/DatabaseErrorPageMiddlewareTest.cs +++ b/test/Microsoft.AspNet.Diagnostics.Entity.FunctionalTests/DatabaseErrorPageMiddlewareTest.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics.Entity.FunctionalTests.Helpers; using Microsoft.AspNet.Diagnostics.Entity.Tests.Helpers; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.TestHost; using Microsoft.AspNet.Testing.xunit; @@ -28,9 +29,10 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests [Fact] public async Task Successful_requests_pass_thru() { - TestServer server = TestServer.Create(app => app + var builder = new WebApplicationBuilder().Configure(app => app .UseDatabaseErrorPage() .UseMiddleware()); + var server = new TestServer(builder); HttpResponseMessage response = await server.CreateClient().GetAsync("http://localhost/"); @@ -53,9 +55,10 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests [Fact] public async Task Non_database_exceptions_pass_thru() { - TestServer server = TestServer.Create(app => app + var builder = new WebApplicationBuilder().Configure(app => app .UseDatabaseErrorPage() .UseMiddleware()); + var server = new TestServer(builder); var ex = await Assert.ThrowsAsync(async () => await server.CreateClient().GetAsync("http://localhost/")); @@ -252,25 +255,27 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests using (var database = SqlServerTestStore.CreateScratch()) { - var server = TestServer.Create(app => - { - app.UseDatabaseErrorPage(options => + var builder = new WebApplicationBuilder() + .Configure(app => { - options.EnableAll(); - options.MigrationsEndPointPath = new PathString(migrationsEndpoint); + app.UseDatabaseErrorPage(options => + { + options.EnableAll(); + options.MigrationsEndPointPath = new PathString(migrationsEndpoint); + }); + + app.UseMiddleware(); + }) + .ConfigureServices(services => + { + services.AddEntityFramework().AddSqlServer(); + services.AddScoped(); + + var optionsBuilder = new DbContextOptionsBuilder(); + optionsBuilder.UseSqlServer(database.ConnectionString); + services.AddSingleton(optionsBuilder.Options); }); - - app.UseMiddleware(); - }, - services => - { - services.AddEntityFramework().AddSqlServer(); - services.AddScoped(); - - var optionsBuilder = new DbContextOptionsBuilder(); - optionsBuilder.UseSqlServer(database.ConnectionString); - services.AddSingleton(optionsBuilder.Options); - }); + var server = new TestServer(builder); HttpResponseMessage response = await server.CreateClient().GetAsync("http://localhost/"); @@ -289,26 +294,29 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests { var logProvider = new TestLoggerProvider(); - var server = TestServer.Create(app => - { - app.UseDatabaseErrorPage(); - app.UseMiddleware(); - app.ApplicationServices.GetService().AddProvider(logProvider); - }, - services => - { - services.AddEntityFramework().AddSqlServer(); - var optionsBuilder = new DbContextOptionsBuilder(); - if (!PlatformHelper.IsMono) + var builder = new WebApplicationBuilder() + .Configure(app => { - optionsBuilder.UseSqlServer(database.ConnectionString); - } - else + app.UseDatabaseErrorPage(); + app.UseMiddleware(); + app.ApplicationServices.GetService().AddProvider(logProvider); + }) + .ConfigureServices( + services => { - optionsBuilder.UseInMemoryDatabase(); - } - services.AddSingleton(optionsBuilder.Options); - }); + services.AddEntityFramework().AddSqlServer(); + var optionsBuilder = new DbContextOptionsBuilder(); + if (!PlatformHelper.IsMono) + { + optionsBuilder.UseSqlServer(database.ConnectionString); + } + else + { + optionsBuilder.UseInMemoryDatabase(); + } + services.AddSingleton(optionsBuilder.Options); + }); + var server = new TestServer(builder); var ex = await Assert.ThrowsAsync(async () => await server.CreateClient().GetAsync("http://localhost/")); @@ -404,35 +412,37 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests { using (var database = SqlServerTestStore.CreateScratch()) { - return TestServer.Create(app => - { - app.UseDatabaseErrorPage(); - - app.UseMiddleware(); - - if (logProvider != null) + var builder = new WebApplicationBuilder() + .Configure(app => { - app.ApplicationServices.GetService().AddProvider(logProvider); - } - }, - services => - { - services.AddEntityFramework() - .AddSqlServer(); + app.UseDatabaseErrorPage(); - services.AddScoped(); + app.UseMiddleware(); - var optionsBuilder = new DbContextOptionsBuilder(); - if (!PlatformHelper.IsMono) + if (logProvider != null) + { + app.ApplicationServices.GetService().AddProvider(logProvider); + } + }) + .ConfigureServices(services => { - optionsBuilder.UseSqlServer(database.ConnectionString); - } - else - { - optionsBuilder.UseInMemoryDatabase(); - } - services.AddSingleton(optionsBuilder.Options); - }); + services.AddEntityFramework() + .AddSqlServer(); + + services.AddScoped(); + + var optionsBuilder = new DbContextOptionsBuilder(); + if (!PlatformHelper.IsMono) + { + optionsBuilder.UseSqlServer(database.ConnectionString); + } + else + { + optionsBuilder.UseInMemoryDatabase(); + } + services.AddSingleton(optionsBuilder.Options); + }); + return new TestServer(builder); } } diff --git a/test/Microsoft.AspNet.Diagnostics.Entity.FunctionalTests/MigrationsEndPointMiddlewareTest.cs b/test/Microsoft.AspNet.Diagnostics.Entity.FunctionalTests/MigrationsEndPointMiddlewareTest.cs index 32af175ef1..fe747343b6 100644 --- a/test/Microsoft.AspNet.Diagnostics.Entity.FunctionalTests/MigrationsEndPointMiddlewareTest.cs +++ b/test/Microsoft.AspNet.Diagnostics.Entity.FunctionalTests/MigrationsEndPointMiddlewareTest.cs @@ -9,6 +9,7 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics.Entity.Tests.Helpers; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.TestHost; using Microsoft.AspNet.Testing.xunit; @@ -26,9 +27,10 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests [Fact] public async Task Non_migration_requests_pass_thru() { - TestServer server = TestServer.Create(app => app + var builder = new WebApplicationBuilder().Configure(app => app .UseMigrationsEndPoint() .UseMiddleware()); + var server = new TestServer(builder); HttpResponseMessage response = await server.CreateClient().GetAsync("http://localhost/"); @@ -71,23 +73,25 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests var path = useCustomPath ? new PathString("/EndPoints/ApplyMyMigrations") : MigrationsEndPointOptions.DefaultPath; - TestServer server = TestServer.Create(app => - { - if (useCustomPath) + var builder = new WebApplicationBuilder() + .Configure(app => { - app.UseMigrationsEndPoint(o => o.Path = path); - } - else + if (useCustomPath) + { + app.UseMigrationsEndPoint(o => o.Path = path); + } + else + { + app.UseMigrationsEndPoint(); + } + }) + .ConfigureServices(services => { - app.UseMigrationsEndPoint(); - } - }, - services => - { - services.AddEntityFramework().AddSqlServer(); - services.AddScoped(); - services.AddSingleton(optionsBuilder.Options); - }); + services.AddEntityFramework().AddSqlServer(); + services.AddScoped(); + services.AddSingleton(optionsBuilder.Options); + }); + var server = new TestServer(builder); using (var db = BloggingContextWithMigrations.CreateWithoutExternalServiceProvider(optionsBuilder.Options)) { @@ -118,10 +122,12 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests [Fact] public async Task Context_type_not_specified() { - var server = TestServer.Create(app => - { - app.UseMigrationsEndPoint(); - }); + var builder = new WebApplicationBuilder() + .Configure(app => + { + app.UseMigrationsEndPoint(); + }); + var server = new TestServer(builder); var formData = new FormUrlEncodedContent(new List>()); @@ -136,10 +142,12 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests [Fact] public async Task Invalid_context_type_specified() { - var server = TestServer.Create(app => - { - app.UseMigrationsEndPoint(); - }); + var builder = new WebApplicationBuilder() + .Configure(app => + { + app.UseMigrationsEndPoint(); + }); + var server = new TestServer(builder); var typeName = "You won't find this type ;)"; var formData = new FormUrlEncodedContent(new List> @@ -158,9 +166,10 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests [Fact] public async Task Context_not_registered_in_services() { - var server = TestServer.Create( - app => app.UseMigrationsEndPoint(), - services => services.AddEntityFramework().AddSqlServer()); + var builder = new WebApplicationBuilder() + .Configure(app => app.UseMigrationsEndPoint()) + .ConfigureServices(services => services.AddEntityFramework().AddSqlServer()); + var server = new TestServer(builder); var formData = new FormUrlEncodedContent(new List> { @@ -184,14 +193,15 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests var optionsBuilder = new DbContextOptionsBuilder(); optionsBuilder.UseSqlServer(database.ConnectionString); - TestServer server = TestServer.Create( - app => app.UseMigrationsEndPoint(), - services => + var builder = new WebApplicationBuilder() + .Configure(app => app.UseMigrationsEndPoint()) + .ConfigureServices(services => { services.AddEntityFramework().AddSqlServer(); services.AddScoped(); services.AddSingleton(optionsBuilder.Options); }); + var server = new TestServer(builder); var formData = new FormUrlEncodedContent(new List> { diff --git a/test/Microsoft.AspNet.Diagnostics.Tests/DeveloperExceptionPageMiddlewareTest.cs b/test/Microsoft.AspNet.Diagnostics.Tests/DeveloperExceptionPageMiddlewareTest.cs index 7bd1840cb3..bb1bb28e25 100644 --- a/test/Microsoft.AspNet.Diagnostics.Tests/DeveloperExceptionPageMiddlewareTest.cs +++ b/test/Microsoft.AspNet.Diagnostics.Tests/DeveloperExceptionPageMiddlewareTest.cs @@ -13,6 +13,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.FileProviders; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.TestHost; using Microsoft.AspNet.Testing; using Microsoft.Extensions.PlatformAbstractions; @@ -485,15 +486,17 @@ namespace Microsoft.AspNet.Diagnostics { // Arrange DiagnosticListener diagnosticListener = null; - var server = TestServer.Create(app => - { - diagnosticListener = app.ApplicationServices.GetRequiredService(); - app.UseDeveloperExceptionPage(); - app.Run(context => + var builder = new WebApplicationBuilder() + .Configure(app => { - throw new Exception("Test exception"); + diagnosticListener = app.ApplicationServices.GetRequiredService(); + app.UseDeveloperExceptionPage(); + app.Run(context => + { + throw new Exception("Test exception"); + }); }); - }); + var server = new TestServer(builder); var listener = new TestDiagnosticListener(); diagnosticListener.SubscribeWithAdapter(listener); diff --git a/test/Microsoft.AspNet.Diagnostics.Tests/ExceptionHandlerTest.cs b/test/Microsoft.AspNet.Diagnostics.Tests/ExceptionHandlerTest.cs index 0a939252eb..5cf130d007 100644 --- a/test/Microsoft.AspNet.Diagnostics.Tests/ExceptionHandlerTest.cs +++ b/test/Microsoft.AspNet.Diagnostics.Tests/ExceptionHandlerTest.cs @@ -10,6 +10,7 @@ using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.TestHost; using Microsoft.Extensions.DependencyInjection; @@ -25,25 +26,28 @@ namespace Microsoft.AspNet.Diagnostics [InlineData(HttpStatusCode.InternalServerError)] public async Task OnlyHandles_UnhandledExceptions(HttpStatusCode expectedStatusCode) { - using (var server = TestServer.Create(app => - { - app.UseExceptionHandler("/handle-errors"); - - app.Map("/handle-errors", (innerAppBuilder) => + var builder = new WebApplicationBuilder() + .Configure(app => { - innerAppBuilder.Run(async (httpContext) => + app.UseExceptionHandler("/handle-errors"); + + app.Map("/handle-errors", (innerAppBuilder) => { - await httpContext.Response.WriteAsync("Handled error in a custom way."); + innerAppBuilder.Run(async (httpContext) => + { + await httpContext.Response.WriteAsync("Handled error in a custom way."); + }); }); + + app.Run((RequestDelegate)(async (context) => + { + context.Response.StatusCode = (int)expectedStatusCode; + context.Response.ContentType = "text/plain; charset=utf-8"; + await context.Response.WriteAsync("An error occurred while adding a product"); + })); }); - app.Run((RequestDelegate)(async (context) => - { - context.Response.StatusCode = (int)expectedStatusCode; - context.Response.ContentType = "text/plain; charset=utf-8"; - await context.Response.WriteAsync("An error occurred while adding a product"); - })); - })) + using (var server = new TestServer(builder)) { var client = server.CreateClient(); var response = await client.GetAsync(string.Empty); @@ -55,40 +59,43 @@ namespace Microsoft.AspNet.Diagnostics [Fact] public async Task DoesNotHandle_UnhandledExceptions_WhenResponseAlreadyStarted() { - using (var server = TestServer.Create(app => - { - app.Use(async (httpContext, next) => + var builder = new WebApplicationBuilder() + .Configure(app => { - Exception exception = null; - try + app.Use(async (httpContext, next) => { - await next(); - } - catch (InvalidOperationException ex) + Exception exception = null; + try + { + await next(); + } + catch (InvalidOperationException ex) + { + exception = ex; + } + + Assert.NotNull(exception); + Assert.Equal("Something bad happened", exception.Message); + }); + + app.UseExceptionHandler("/handle-errors"); + + app.Map("/handle-errors", (innerAppBuilder) => { - exception = ex; - } + innerAppBuilder.Run(async (httpContext) => + { + await httpContext.Response.WriteAsync("Handled error in a custom way."); + }); + }); - Assert.NotNull(exception); - Assert.Equal("Something bad happened", exception.Message); - }); - - app.UseExceptionHandler("/handle-errors"); - - app.Map("/handle-errors", (innerAppBuilder) => - { - innerAppBuilder.Run(async (httpContext) => + app.Run(async (httpContext) => { - await httpContext.Response.WriteAsync("Handled error in a custom way."); + await httpContext.Response.WriteAsync("Hello"); + throw new InvalidOperationException("Something bad happened"); }); }); - app.Run(async (httpContext) => - { - await httpContext.Response.WriteAsync("Hello"); - throw new InvalidOperationException("Something bad happened"); - }); - })) + using (var server = new TestServer(builder)) { var client = server.CreateClient(); var response = await client.GetAsync(string.Empty); @@ -101,51 +108,54 @@ namespace Microsoft.AspNet.Diagnostics public async Task ClearsResponseBuffer_BeforeRequestIsReexecuted() { var expectedResponseBody = "New response body"; - using (var server = TestServer.Create(app => - { - // add response buffering - app.Use(async (httpContext, next) => + var builder = new WebApplicationBuilder() + .Configure(app => { - var response = httpContext.Response; - var originalResponseBody = response.Body; - var bufferingStream = new MemoryStream(); - response.Body = bufferingStream; - - try + // add response buffering + app.Use(async (httpContext, next) => { - await next(); + var response = httpContext.Response; + var originalResponseBody = response.Body; + var bufferingStream = new MemoryStream(); + response.Body = bufferingStream; - response.Body = originalResponseBody; - bufferingStream.Seek(0, SeekOrigin.Begin); - await bufferingStream.CopyToAsync(response.Body); - } - finally + try + { + await next(); + + response.Body = originalResponseBody; + bufferingStream.Seek(0, SeekOrigin.Begin); + await bufferingStream.CopyToAsync(response.Body); + } + finally + { + response.Body = originalResponseBody; + } + }); + + app.UseExceptionHandler("/handle-errors"); + + app.Map("/handle-errors", (innerAppBuilder) => { - response.Body = originalResponseBody; - } - }); + innerAppBuilder.Run(async (httpContext) => + { + Assert.True(httpContext.Response.Body.CanSeek); + Assert.Equal(0, httpContext.Response.Body.Position); - app.UseExceptionHandler("/handle-errors"); + await httpContext.Response.WriteAsync(expectedResponseBody); + }); + }); - app.Map("/handle-errors", (innerAppBuilder) => - { - innerAppBuilder.Run(async (httpContext) => + app.Run(async (context) => { - Assert.True(httpContext.Response.Body.CanSeek); - Assert.Equal(0, httpContext.Response.Body.Position); + // Write some content into the response before throwing exception + await context.Response.WriteAsync(new string('a', 100)); - await httpContext.Response.WriteAsync(expectedResponseBody); + throw new InvalidOperationException("Invalid input provided."); }); }); - app.Run(async (context) => - { - // Write some content into the response before throwing exception - await context.Response.WriteAsync(new string('a', 100)); - - throw new InvalidOperationException("Invalid input provided."); - }); - })) + using (var server = new TestServer(builder)) { var client = server.CreateClient(); var response = await client.GetAsync(string.Empty); @@ -170,29 +180,32 @@ namespace Microsoft.AspNet.Diagnostics { var expiresTime = DateTime.UtcNow.AddDays(5).ToString("R"); var expectedResponseBody = "Handled error in a custom way."; - using (var server = TestServer.Create(app => - { - app.UseExceptionHandler("/handle-errors"); - - app.Map("/handle-errors", (innerAppBuilder) => + var builder = new WebApplicationBuilder() + .Configure(app => { - innerAppBuilder.Run(async (httpContext) => - { - httpContext.Response.Headers.Add("Cache-Control", new[] { "max-age=600" }); - httpContext.Response.Headers.Add("Pragma", new[] { "max-age=600" }); - httpContext.Response.Headers.Add( - "Expires", new[] { expiresTime }); - httpContext.Response.Headers.Add("ETag", new[] { "12345" }); + app.UseExceptionHandler("/handle-errors"); - await httpContext.Response.WriteAsync(expectedResponseBody); + app.Map("/handle-errors", (innerAppBuilder) => + { + innerAppBuilder.Run(async (httpContext) => + { + httpContext.Response.Headers.Add("Cache-Control", new[] { "max-age=600" }); + httpContext.Response.Headers.Add("Pragma", new[] { "max-age=600" }); + httpContext.Response.Headers.Add( + "Expires", new[] { expiresTime }); + httpContext.Response.Headers.Add("ETag", new[] { "12345" }); + + await httpContext.Response.WriteAsync(expectedResponseBody); + }); + }); + + app.Run((context) => + { + throw new InvalidOperationException("Invalid input provided."); }); }); - app.Run((context) => - { - throw new InvalidOperationException("Invalid input provided."); - }); - })) + using (var server = new TestServer(builder)) { var client = server.CreateClient(); var response = await client.GetAsync(string.Empty); @@ -217,28 +230,31 @@ namespace Microsoft.AspNet.Diagnostics { var expiresTime = DateTime.UtcNow.AddDays(10).ToString("R"); var expectedResponseBody = "Hello world!"; - using (var server = TestServer.Create(app => - { - app.UseExceptionHandler("/handle-errors"); - - app.Map("/handle-errors", (innerAppBuilder) => + var builder = new WebApplicationBuilder() + .Configure(app => { - innerAppBuilder.Run(async (httpContext) => + app.UseExceptionHandler("/handle-errors"); + + app.Map("/handle-errors", (innerAppBuilder) => { - await httpContext.Response.WriteAsync("Handled error in a custom way."); + innerAppBuilder.Run(async (httpContext) => + { + await httpContext.Response.WriteAsync("Handled error in a custom way."); + }); + }); + + app.Run(async (httpContext) => + { + httpContext.Response.Headers.Add("Cache-Control", new[] { "max-age=3600" }); + httpContext.Response.Headers.Add("Pragma", new[] { "max-age=3600" }); + httpContext.Response.Headers.Add("Expires", new[] { expiresTime }); + httpContext.Response.Headers.Add("ETag", new[] { "abcdef" }); + + await httpContext.Response.WriteAsync(expectedResponseBody); }); }); - app.Run(async (httpContext) => - { - httpContext.Response.Headers.Add("Cache-Control", new[] { "max-age=3600" }); - httpContext.Response.Headers.Add("Pragma", new[] { "max-age=3600" }); - httpContext.Response.Headers.Add("Expires", new[] { expiresTime }); - httpContext.Response.Headers.Add("ETag", new[] { "abcdef" }); - - await httpContext.Response.WriteAsync(expectedResponseBody); - }); - })) + using (var server = new TestServer(builder)) { var client = server.CreateClient(); var response = await client.GetAsync(string.Empty); @@ -264,46 +280,49 @@ namespace Microsoft.AspNet.Diagnostics public async Task DoesNotClearCacheHeaders_WhenResponseHasAlreadyStarted() { var expiresTime = DateTime.UtcNow.AddDays(10).ToString("R"); - using (var server = TestServer.Create(app => - { - app.Use(async (httpContext, next) => + var builder = new WebApplicationBuilder() + .Configure(app => { - Exception exception = null; - try + app.Use(async (httpContext, next) => { - await next(); - } - catch (InvalidOperationException ex) + Exception exception = null; + try + { + await next(); + } + catch (InvalidOperationException ex) + { + exception = ex; + } + + Assert.NotNull(exception); + Assert.Equal("Something bad happened", exception.Message); + }); + + app.UseExceptionHandler("/handle-errors"); + + app.Map("/handle-errors", (innerAppBuilder) => { - exception = ex; - } + innerAppBuilder.Run(async (httpContext) => + { + await httpContext.Response.WriteAsync("Handled error in a custom way."); + }); + }); - Assert.NotNull(exception); - Assert.Equal("Something bad happened", exception.Message); - }); - - app.UseExceptionHandler("/handle-errors"); - - app.Map("/handle-errors", (innerAppBuilder) => - { - innerAppBuilder.Run(async (httpContext) => + app.Run(async (httpContext) => { - await httpContext.Response.WriteAsync("Handled error in a custom way."); + httpContext.Response.Headers.Add("Cache-Control", new[] { "max-age=3600" }); + httpContext.Response.Headers.Add("Pragma", new[] { "max-age=3600" }); + httpContext.Response.Headers.Add("Expires", new[] { expiresTime }); + httpContext.Response.Headers.Add("ETag", new[] { "abcdef" }); + + await httpContext.Response.WriteAsync("Hello"); + + throw new InvalidOperationException("Something bad happened"); }); }); - app.Run(async (httpContext) => - { - httpContext.Response.Headers.Add("Cache-Control", new[] { "max-age=3600" }); - httpContext.Response.Headers.Add("Pragma", new[] { "max-age=3600" }); - httpContext.Response.Headers.Add("Expires", new[] { expiresTime }); - httpContext.Response.Headers.Add("ETag", new[] { "abcdef" }); - - await httpContext.Response.WriteAsync("Hello"); - - throw new InvalidOperationException("Something bad happened"); - }); - })) + using (var server = new TestServer(builder)) { var client = server.CreateClient(); var response = await client.GetAsync(string.Empty); @@ -331,23 +350,25 @@ namespace Microsoft.AspNet.Diagnostics // Arrange DiagnosticListener diagnosticListener = null; - var server = TestServer.Create(app => - { - diagnosticListener = app.ApplicationServices.GetRequiredService(); - - app.UseExceptionHandler("/handle-errors"); - app.Map("/handle-errors", (innerAppBuilder) => + var builder = new WebApplicationBuilder() + .Configure(app => { - innerAppBuilder.Run(async (httpContext) => + diagnosticListener = app.ApplicationServices.GetRequiredService(); + + app.UseExceptionHandler("/handle-errors"); + app.Map("/handle-errors", (innerAppBuilder) => { - await httpContext.Response.WriteAsync("Handled error in a custom way."); + innerAppBuilder.Run(async (httpContext) => + { + await httpContext.Response.WriteAsync("Handled error in a custom way."); + }); + }); + app.Run(context => + { + throw new Exception("Test exception"); }); }); - app.Run(context => - { - throw new Exception("Test exception"); - }); - }); + var server = new TestServer(builder); var listener = new TestDiagnosticListener(); diagnosticListener.SubscribeWithAdapter(listener); diff --git a/test/Microsoft.AspNet.MiddlewareAnalysis.Tests/MiddlewareAnalysisTests.cs b/test/Microsoft.AspNet.MiddlewareAnalysis.Tests/MiddlewareAnalysisTests.cs index 9c50479053..4f1327d929 100644 --- a/test/Microsoft.AspNet.MiddlewareAnalysis.Tests/MiddlewareAnalysisTests.cs +++ b/test/Microsoft.AspNet.MiddlewareAnalysis.Tests/MiddlewareAnalysisTests.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.TestHost; using Microsoft.Extensions.DependencyInjection; using Xunit; @@ -18,16 +19,19 @@ namespace Microsoft.AspNet.MiddlewareAnalysis { DiagnosticListener diagnosticListener = null; - var server = TestServer.Create(app => - { - diagnosticListener = app.ApplicationServices.GetRequiredService(); - - app.UseDeveloperExceptionPage(); - app.Run(context => + var builder = new WebApplicationBuilder() + .Configure(app => { - throw new Exception("Test exception"); - }); - }, services => services.AddMiddlewareAnalysis()); + diagnosticListener = app.ApplicationServices.GetRequiredService(); + + app.UseDeveloperExceptionPage(); + app.Run(context => + { + throw new Exception("Test exception"); + }); + }) + .ConfigureServices(services => services.AddMiddlewareAnalysis()); + var server = new TestServer(builder); var listener = new TestDiagnosticListener(); diagnosticListener.SubscribeWithAdapter(listener);