From 335895d9b49042312eca12a089340adf3ca0a219 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Wed, 10 Sep 2014 11:45:02 -0700 Subject: [PATCH] #122 - Rename IBuilder to IApplicationBuilder. --- .../Extensions/MapExtensions.cs | 6 ++--- .../Extensions/MapWhenExtensions.cs | 8 +++---- .../Extensions/RunExtensions.cs | 2 +- .../Extensions/UseExtensions.cs | 2 +- .../{IBuilder.cs => IApplicationBuilder.cs} | 6 ++--- src/Microsoft.AspNet.Owin/OwinExtensions.cs | 10 ++++----- .../{Builder.cs => ApplicationBuilder.cs} | 13 +++++------ .../MapPathMiddlewareTests.cs | 22 +++++++++---------- .../MapPredicateMiddlewareTests.cs | 22 +++++++++---------- ...derTests.cs => ApplicationBuilderTests.cs} | 4 ++-- 10 files changed, 47 insertions(+), 48 deletions(-) rename src/Microsoft.AspNet.Http/{IBuilder.cs => IApplicationBuilder.cs} (75%) rename src/Microsoft.AspNet.PipelineCore/{Builder.cs => ApplicationBuilder.cs} (86%) rename test/Microsoft.AspNet.PipelineCore.Tests/{BuilderTests.cs => ApplicationBuilderTests.cs} (89%) diff --git a/src/Microsoft.AspNet.Http/Extensions/MapExtensions.cs b/src/Microsoft.AspNet.Http/Extensions/MapExtensions.cs index b4a44adddf..9696b99da7 100644 --- a/src/Microsoft.AspNet.Http/Extensions/MapExtensions.cs +++ b/src/Microsoft.AspNet.Http/Extensions/MapExtensions.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Builder /// The path to match /// The branch to take for positive path matches /// - public static IBuilder Map([NotNull] this IBuilder app, [NotNull] string pathMatch, [NotNull] Action configuration) + public static IApplicationBuilder Map([NotNull] this IApplicationBuilder app, [NotNull] string pathMatch, [NotNull] Action configuration) { return Map(app, new PathString(pathMatch), configuration); } @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Builder /// The path to match /// The branch to take for positive path matches /// - public static IBuilder Map([NotNull] this IBuilder app, PathString pathMatch, [NotNull] Action configuration) + public static IApplicationBuilder Map([NotNull] this IApplicationBuilder app, PathString pathMatch, [NotNull] Action configuration) { if (pathMatch.HasValue && pathMatch.Value.EndsWith("/", StringComparison.Ordinal)) { @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Builder } // create branch - IBuilder branchBuilder = app.New(); + var branchBuilder = app.New(); configuration(branchBuilder); var branch = branchBuilder.Build(); diff --git a/src/Microsoft.AspNet.Http/Extensions/MapWhenExtensions.cs b/src/Microsoft.AspNet.Http/Extensions/MapWhenExtensions.cs index b46bbbe0e9..63e65a0a11 100644 --- a/src/Microsoft.AspNet.Http/Extensions/MapWhenExtensions.cs +++ b/src/Microsoft.AspNet.Http/Extensions/MapWhenExtensions.cs @@ -23,10 +23,10 @@ namespace Microsoft.AspNet.Builder /// Invoked with the request environment to determine if the branch should be taken /// Configures a branch to take /// - public static IBuilder MapWhen([NotNull] this IBuilder app, [NotNull] Predicate predicate, [NotNull] Action configuration) + public static IApplicationBuilder MapWhen([NotNull] this IApplicationBuilder app, [NotNull] Predicate predicate, [NotNull] Action configuration) { // create branch - IBuilder branchBuilder = app.New(); + var branchBuilder = app.New(); configuration(branchBuilder); var branch = branchBuilder.Build(); @@ -46,10 +46,10 @@ namespace Microsoft.AspNet.Builder /// Invoked asynchronously with the request environment to determine if the branch should be taken /// Configures a branch to take /// - public static IBuilder MapWhenAsync([NotNull] this IBuilder app, [NotNull] PredicateAsync predicate, [NotNull] Action configuration) + public static IApplicationBuilder MapWhenAsync([NotNull] this IApplicationBuilder app, [NotNull] PredicateAsync predicate, [NotNull] Action configuration) { // create branch - IBuilder branchBuilder = app.New(); + var branchBuilder = app.New(); configuration(branchBuilder); var branch = branchBuilder.Build(); diff --git a/src/Microsoft.AspNet.Http/Extensions/RunExtensions.cs b/src/Microsoft.AspNet.Http/Extensions/RunExtensions.cs index de565c2e3d..694dd3ec0f 100644 --- a/src/Microsoft.AspNet.Http/Extensions/RunExtensions.cs +++ b/src/Microsoft.AspNet.Http/Extensions/RunExtensions.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Builder { public static class RunExtensions { - public static void Run([NotNull] this IBuilder app, [NotNull] RequestDelegate handler) + public static void Run([NotNull] this IApplicationBuilder app, [NotNull] RequestDelegate handler) { app.Use(_ => handler); } diff --git a/src/Microsoft.AspNet.Http/Extensions/UseExtensions.cs b/src/Microsoft.AspNet.Http/Extensions/UseExtensions.cs index 3f0f8f51c3..038b14e03e 100644 --- a/src/Microsoft.AspNet.Http/Extensions/UseExtensions.cs +++ b/src/Microsoft.AspNet.Http/Extensions/UseExtensions.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Builder /// /// A function that handles the request or calls the given next function. /// - public static IBuilder Use(this IBuilder app, Func, Task> middleware) + public static IApplicationBuilder Use(this IApplicationBuilder app, Func, Task> middleware) { return app.Use(next => { diff --git a/src/Microsoft.AspNet.Http/IBuilder.cs b/src/Microsoft.AspNet.Http/IApplicationBuilder.cs similarity index 75% rename from src/Microsoft.AspNet.Http/IBuilder.cs rename to src/Microsoft.AspNet.Http/IApplicationBuilder.cs index 1673390e07..bed7c50f0d 100644 --- a/src/Microsoft.AspNet.Http/IBuilder.cs +++ b/src/Microsoft.AspNet.Http/IApplicationBuilder.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; namespace Microsoft.AspNet.Builder { - public interface IBuilder + public interface IApplicationBuilder { IServiceProvider ApplicationServices { get; set; } @@ -14,9 +14,9 @@ namespace Microsoft.AspNet.Builder IDictionary Properties { get; set; } - IBuilder Use(Func middleware); + IApplicationBuilder Use(Func middleware); - IBuilder New(); + IApplicationBuilder New(); RequestDelegate Build(); } diff --git a/src/Microsoft.AspNet.Owin/OwinExtensions.cs b/src/Microsoft.AspNet.Owin/OwinExtensions.cs index 674befa4f9..5bd2e0a9fa 100644 --- a/src/Microsoft.AspNet.Owin/OwinExtensions.cs +++ b/src/Microsoft.AspNet.Owin/OwinExtensions.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Builder public static class OwinExtensions { - public static AddMiddleware UseOwin(this IBuilder builder) + public static AddMiddleware UseOwin(this IApplicationBuilder builder) { AddMiddleware add = middleware => { @@ -58,17 +58,17 @@ namespace Microsoft.AspNet.Builder return add; } - public static IBuilder UseOwin(this IBuilder builder, Action pipeline) + public static IApplicationBuilder UseOwin(this IApplicationBuilder builder, Action pipeline) { pipeline(builder.UseOwin()); return builder; } - public static IBuilder UseBuilder(this AddMiddleware app) + public static IApplicationBuilder UseBuilder(this AddMiddleware app) { // Adapt WebSockets by default. app(OwinWebSocketAcceptAdapter.AdaptWebSockets); - var builder = new Builder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null); CreateMiddleware middleware = CreateMiddlewareFactory(exit => { @@ -111,7 +111,7 @@ namespace Microsoft.AspNet.Builder }; } - public static AddMiddleware UseBuilder(this AddMiddleware app, Action pipeline) + public static AddMiddleware UseBuilder(this AddMiddleware app, Action pipeline) { var builder = app.UseBuilder(); pipeline(builder); diff --git a/src/Microsoft.AspNet.PipelineCore/Builder.cs b/src/Microsoft.AspNet.PipelineCore/ApplicationBuilder.cs similarity index 86% rename from src/Microsoft.AspNet.PipelineCore/Builder.cs rename to src/Microsoft.AspNet.PipelineCore/ApplicationBuilder.cs index 12a95ebd8f..71f6ef267b 100644 --- a/src/Microsoft.AspNet.PipelineCore/Builder.cs +++ b/src/Microsoft.AspNet.PipelineCore/ApplicationBuilder.cs @@ -5,22 +5,21 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Infrastructure; namespace Microsoft.AspNet.Builder { - public class Builder : IBuilder + public class ApplicationBuilder : IApplicationBuilder { private readonly IList> _components = new List>(); - public Builder(IServiceProvider serviceProvider) + public ApplicationBuilder(IServiceProvider serviceProvider) { Properties = new Dictionary(); ApplicationServices = serviceProvider; } - private Builder(Builder builder) + private ApplicationBuilder(ApplicationBuilder builder) { Properties = builder.Properties; } @@ -62,15 +61,15 @@ namespace Microsoft.AspNet.Builder Properties[key] = value; } - public IBuilder Use(Func middleware) + public IApplicationBuilder Use(Func middleware) { _components.Add(middleware); return this; } - public IBuilder New() + public IApplicationBuilder New() { - return new Builder(this); + return new ApplicationBuilder(this); } public RequestDelegate Build() diff --git a/test/Microsoft.AspNet.Http.Tests/MapPathMiddlewareTests.cs b/test/Microsoft.AspNet.Http.Tests/MapPathMiddlewareTests.cs index 4a9d68dd45..bdaa1eeedb 100644 --- a/test/Microsoft.AspNet.Http.Tests/MapPathMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Http.Tests/MapPathMiddlewareTests.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Builder.Extensions { public class MapPathMiddlewareTests { - private static readonly Action ActionNotImplemented = new Action(_ => { throw new NotImplementedException(); }); + private static readonly Action ActionNotImplemented = new Action(_ => { throw new NotImplementedException(); }); private static Task Success(HttpContext context) { @@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Builder.Extensions return Task.FromResult(null); } - private static void UseSuccess(IBuilder app) + private static void UseSuccess(IApplicationBuilder app) { app.Run(Success); } @@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Builder.Extensions throw new NotImplementedException(); } - private static void UseNotImplemented(IBuilder app) + private static void UseNotImplemented(IApplicationBuilder app) { app.Run(NotImplemented); } @@ -41,8 +41,8 @@ namespace Microsoft.AspNet.Builder.Extensions [Fact] public void NullArguments_ArgumentNullException() { - var builder = new Builder(serviceProvider: null); - var noMiddleware = new Builder(serviceProvider: null).Build(); + var builder = new ApplicationBuilder(serviceProvider: null); + var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build(); var noOptions = new MapOptions(); // TODO: [NotNull] Assert.Throws(() => builder.Map(null, ActionNotImplemented)); // TODO: [NotNull] Assert.Throws(() => builder.Map("/foo", (Action)null)); @@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Builder.Extensions public void PathMatchFunc_BranchTaken(string matchPath, string basePath, string requestPath) { HttpContext context = CreateRequest(basePath, requestPath); - IBuilder builder = new Builder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null); builder.Map(matchPath, UseSuccess); var app = builder.Build(); app.Invoke(context).Wait(); @@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Builder.Extensions public void PathMatchAction_BranchTaken(string matchPath, string basePath, string requestPath) { HttpContext context = CreateRequest(basePath, requestPath); - IBuilder builder = new Builder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null); builder.Map(matchPath, subBuilder => subBuilder.Run(Success)); var app = builder.Build(); app.Invoke(context).Wait(); @@ -98,7 +98,7 @@ namespace Microsoft.AspNet.Builder.Extensions [InlineData("/foo/cho/")] public void MatchPathWithTrailingSlashThrowsException(string matchPath) { - Should.Throw(() => new Builder(serviceProvider: null).Map(matchPath, map => { }).Build()); + Should.Throw(() => new ApplicationBuilder(serviceProvider: null).Map(matchPath, map => { }).Build()); } [Theory] @@ -112,7 +112,7 @@ namespace Microsoft.AspNet.Builder.Extensions public void PathMismatchFunc_PassedThrough(string matchPath, string basePath, string requestPath) { HttpContext context = CreateRequest(basePath, requestPath); - IBuilder builder = new Builder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null); builder.Map(matchPath, UseNotImplemented); builder.Run(Success); var app = builder.Build(); @@ -134,7 +134,7 @@ namespace Microsoft.AspNet.Builder.Extensions public void PathMismatchAction_PassedThrough(string matchPath, string basePath, string requestPath) { HttpContext context = CreateRequest(basePath, requestPath); - IBuilder builder = new Builder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null); builder.Map(matchPath, UseNotImplemented); builder.Run(Success); var app = builder.Build(); @@ -148,7 +148,7 @@ namespace Microsoft.AspNet.Builder.Extensions [Fact] public void ChainedRoutes_Success() { - IBuilder builder = new Builder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null); builder.Map("/route1", map => { map.Map((string)"/subroute1", UseSuccess); diff --git a/test/Microsoft.AspNet.Http.Tests/MapPredicateMiddlewareTests.cs b/test/Microsoft.AspNet.Http.Tests/MapPredicateMiddlewareTests.cs index eb8ee8be9c..c5016f3064 100644 --- a/test/Microsoft.AspNet.Http.Tests/MapPredicateMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Http.Tests/MapPredicateMiddlewareTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Builder.Extensions return Task.FromResult(null); } - private static void UseSuccess(IBuilder app) + private static void UseSuccess(IApplicationBuilder app) { app.Run(Success); } @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Builder.Extensions throw new NotImplementedException(); } - private static void UseNotImplemented(IBuilder app) + private static void UseNotImplemented(IApplicationBuilder app) { app.Run(NotImplemented); } @@ -64,8 +64,8 @@ namespace Microsoft.AspNet.Builder.Extensions [Fact] public void NullArguments_ArgumentNullException() { - var builder = new Builder(serviceProvider: null); - var noMiddleware = new Builder(serviceProvider: null).Build(); + var builder = new ApplicationBuilder(serviceProvider: null); + var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build(); var noOptions = new MapWhenOptions(); // TODO: [NotNull] Assert.Throws(() => builder.MapWhen(null, UseNotImplemented)); // TODO: [NotNull] Assert.Throws(() => builder.MapWhen(NotImplementedPredicate, (Action)null)); @@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Builder.Extensions public void PredicateTrue_BranchTaken() { HttpContext context = CreateRequest(); - IBuilder builder = new Builder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null); builder.MapWhen(TruePredicate, UseSuccess); var app = builder.Build(); app.Invoke(context).Wait(); @@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Builder.Extensions public void PredicateTrueAction_BranchTaken() { HttpContext context = CreateRequest(); - IBuilder builder = new Builder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null); builder.MapWhen(TruePredicate, UseSuccess); var app = builder.Build(); app.Invoke(context).Wait(); @@ -106,7 +106,7 @@ namespace Microsoft.AspNet.Builder.Extensions public void PredicateFalseAction_PassThrough() { HttpContext context = CreateRequest(); - IBuilder builder = new Builder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null); builder.MapWhen(FalsePredicate, UseNotImplemented); builder.Run(Success); var app = builder.Build(); @@ -119,7 +119,7 @@ namespace Microsoft.AspNet.Builder.Extensions public void PredicateAsyncTrueAction_BranchTaken() { HttpContext context = CreateRequest(); - IBuilder builder = new Builder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null); builder.MapWhenAsync(TruePredicateAsync, UseSuccess); var app = builder.Build(); app.Invoke(context).Wait(); @@ -131,7 +131,7 @@ namespace Microsoft.AspNet.Builder.Extensions public void PredicateAsyncFalseAction_PassThrough() { HttpContext context = CreateRequest(); - IBuilder builder = new Builder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null); builder.MapWhenAsync(FalsePredicateAsync, UseNotImplemented); builder.Run(Success); var app = builder.Build(); @@ -143,7 +143,7 @@ namespace Microsoft.AspNet.Builder.Extensions [Fact] public void ChainedPredicates_Success() { - IBuilder builder = new Builder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null); builder.MapWhen(TruePredicate, map1 => { map1.MapWhen((Predicate)FalsePredicate, UseNotImplemented); @@ -160,7 +160,7 @@ namespace Microsoft.AspNet.Builder.Extensions [Fact] public void ChainedPredicatesAsync_Success() { - IBuilder builder = new Builder(serviceProvider: null); + var builder = new ApplicationBuilder(serviceProvider: null); builder.MapWhenAsync(TruePredicateAsync, map1 => { map1.MapWhenAsync((PredicateAsync)FalsePredicateAsync, UseNotImplemented); diff --git a/test/Microsoft.AspNet.PipelineCore.Tests/BuilderTests.cs b/test/Microsoft.AspNet.PipelineCore.Tests/ApplicationBuilderTests.cs similarity index 89% rename from test/Microsoft.AspNet.PipelineCore.Tests/BuilderTests.cs rename to test/Microsoft.AspNet.PipelineCore.Tests/ApplicationBuilderTests.cs index 1fab0f3938..755eee5f76 100644 --- a/test/Microsoft.AspNet.PipelineCore.Tests/BuilderTests.cs +++ b/test/Microsoft.AspNet.PipelineCore.Tests/ApplicationBuilderTests.cs @@ -6,12 +6,12 @@ using Xunit; namespace Microsoft.AspNet.Builder.Tests { - public class BuilderTests + public class ApplicationBuilderTests { [Fact] public void BuildReturnsCallableDelegate() { - var builder = new Builder(null); + var builder = new ApplicationBuilder(null); var app = builder.Build(); var mockHttpContext = new Moq.Mock();