Permalink
Browse files

#122 - Rename IBuilder to IApplicationBuilder.

  • Loading branch information...
Tratcher committed Sep 10, 2014
1 parent ba4f44c commit 335895d9b49042312eca12a089340adf3ca0a219
@@ -17,7 +17,7 @@ public static class MapExtensions
/// <param name="pathMatch">The path to match</param>
/// <param name="configuration">The branch to take for positive path matches</param>
/// <returns></returns>
public static IBuilder Map([NotNull] this IBuilder app, [NotNull] string pathMatch, [NotNull] Action<IBuilder> configuration)
public static IApplicationBuilder Map([NotNull] this IApplicationBuilder app, [NotNull] string pathMatch, [NotNull] Action<IApplicationBuilder> configuration)
{
return Map(app, new PathString(pathMatch), configuration);
}
@@ -30,15 +30,15 @@ public static IBuilder Map([NotNull] this IBuilder app, [NotNull] string pathMat
/// <param name="pathMatch">The path to match</param>
/// <param name="configuration">The branch to take for positive path matches</param>
/// <returns></returns>
public static IBuilder Map([NotNull] this IBuilder app, PathString pathMatch, [NotNull] Action<IBuilder> configuration)
public static IApplicationBuilder Map([NotNull] this IApplicationBuilder app, PathString pathMatch, [NotNull] Action<IApplicationBuilder> configuration)
{
if (pathMatch.HasValue && pathMatch.Value.EndsWith("/", StringComparison.Ordinal))
{
throw new ArgumentException("The path must not end with a '/'", "pathMatch");
}
// create branch
IBuilder branchBuilder = app.New();
var branchBuilder = app.New();
configuration(branchBuilder);
var branch = branchBuilder.Build();
@@ -23,10 +23,10 @@ public static class MapWhenExtensions
/// <param name="predicate">Invoked with the request environment to determine if the branch should be taken</param>
/// <param name="configuration">Configures a branch to take</param>
/// <returns></returns>
public static IBuilder MapWhen([NotNull] this IBuilder app, [NotNull] Predicate predicate, [NotNull] Action<IBuilder> configuration)
public static IApplicationBuilder MapWhen([NotNull] this IApplicationBuilder app, [NotNull] Predicate predicate, [NotNull] Action<IApplicationBuilder> configuration)
{
// create branch
IBuilder branchBuilder = app.New();
var branchBuilder = app.New();
configuration(branchBuilder);
var branch = branchBuilder.Build();
@@ -46,10 +46,10 @@ public static IBuilder MapWhen([NotNull] this IBuilder app, [NotNull] Predicate
/// <param name="predicate">Invoked asynchronously with the request environment to determine if the branch should be taken</param>
/// <param name="configuration">Configures a branch to take</param>
/// <returns></returns>
public static IBuilder MapWhenAsync([NotNull] this IBuilder app, [NotNull] PredicateAsync predicate, [NotNull] Action<IBuilder> configuration)
public static IApplicationBuilder MapWhenAsync([NotNull] this IApplicationBuilder app, [NotNull] PredicateAsync predicate, [NotNull] Action<IApplicationBuilder> configuration)
{
// create branch
IBuilder branchBuilder = app.New();
var branchBuilder = app.New();
configuration(branchBuilder);
var branch = branchBuilder.Build();
@@ -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);
}
@@ -15,7 +15,7 @@ public static class UseExtensions
/// <param name="app"></param>
/// <param name="middleware">A function that handles the request or calls the given next function.</param>
/// <returns></returns>
public static IBuilder Use(this IBuilder app, Func<HttpContext, Func<Task>, Task> middleware)
public static IApplicationBuilder Use(this IApplicationBuilder app, Func<HttpContext, Func<Task>, Task> middleware)
{
return app.Use(next =>
{
@@ -6,17 +6,17 @@
namespace Microsoft.AspNet.Builder
{
public interface IBuilder
public interface IApplicationBuilder
{
IServiceProvider ApplicationServices { get; set; }
IServerInformation Server { get; set; }
IDictionary<string, object> Properties { get; set; }
IBuilder Use(Func<RequestDelegate, RequestDelegate> middleware);
IApplicationBuilder Use(Func<RequestDelegate, RequestDelegate> middleware);
IBuilder New();
IApplicationBuilder New();
RequestDelegate Build();
}
@@ -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 @@ public static AddMiddleware UseOwin(this IBuilder builder)
return add;
}
public static IBuilder UseOwin(this IBuilder builder, Action<AddMiddleware> pipeline)
public static IApplicationBuilder UseOwin(this IApplicationBuilder builder, Action<AddMiddleware> 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 @@ private static CreateMiddleware CreateMiddlewareFactory(Func<RequestDelegate, Re
};
}
public static AddMiddleware UseBuilder(this AddMiddleware app, Action<IBuilder> pipeline)
public static AddMiddleware UseBuilder(this AddMiddleware app, Action<IApplicationBuilder> pipeline)
{
var builder = app.UseBuilder();
pipeline(builder);
@@ -5,22 +5,21 @@
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<Func<RequestDelegate, RequestDelegate>> _components = new List<Func<RequestDelegate, RequestDelegate>>();
public Builder(IServiceProvider serviceProvider)
public ApplicationBuilder(IServiceProvider serviceProvider)
{
Properties = new Dictionary<string, object>();
ApplicationServices = serviceProvider;
}
private Builder(Builder builder)
private ApplicationBuilder(ApplicationBuilder builder)
{
Properties = builder.Properties;
}
@@ -62,15 +61,15 @@ private void SetProperty<T>(string key, T value)
Properties[key] = value;
}
public IBuilder Use(Func<RequestDelegate, RequestDelegate> middleware)
public IApplicationBuilder Use(Func<RequestDelegate, RequestDelegate> middleware)
{
_components.Add(middleware);
return this;
}
public IBuilder New()
public IApplicationBuilder New()
{
return new Builder(this);
return new ApplicationBuilder(this);
}
public RequestDelegate Build()
@@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Builder.Extensions
{
public class MapPathMiddlewareTests
{
private static readonly Action<IBuilder> ActionNotImplemented = new Action<IBuilder>(_ => { throw new NotImplementedException(); });
private static readonly Action<IApplicationBuilder> ActionNotImplemented = new Action<IApplicationBuilder>(_ => { throw new NotImplementedException(); });
private static Task Success(HttpContext context)
{
@@ -23,7 +23,7 @@ private static Task Success(HttpContext context)
return Task.FromResult<object>(null);
}
private static void UseSuccess(IBuilder app)
private static void UseSuccess(IApplicationBuilder app)
{
app.Run(Success);
}
@@ -33,16 +33,16 @@ private static Task NotImplemented(HttpContext context)
throw new NotImplementedException();
}
private static void UseNotImplemented(IBuilder app)
private static void UseNotImplemented(IApplicationBuilder app)
{
app.Run(NotImplemented);
}
[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<ArgumentNullException>(() => builder.Map(null, ActionNotImplemented));
// TODO: [NotNull] Assert.Throws<ArgumentNullException>(() => builder.Map("/foo", (Action<IBuilder>)null));
@@ -61,7 +61,7 @@ public void NullArguments_ArgumentNullException()
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 @@ public void PathMatchFunc_BranchTaken(string matchPath, string basePath, string
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 @@ public void PathMatchAction_BranchTaken(string matchPath, string basePath, strin
[InlineData("/foo/cho/")]
public void MatchPathWithTrailingSlashThrowsException(string matchPath)
{
Should.Throw<ArgumentException>(() => new Builder(serviceProvider: null).Map(matchPath, map => { }).Build());
Should.Throw<ArgumentException>(() => new ApplicationBuilder(serviceProvider: null).Map(matchPath, map => { }).Build());
}
[Theory]
@@ -112,7 +112,7 @@ public void MatchPathWithTrailingSlashThrowsException(string matchPath)
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 @@ public void PathMismatchFunc_PassedThrough(string matchPath, string basePath, st
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 @@ public void PathMismatchAction_PassedThrough(string matchPath, string basePath,
[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);
@@ -26,7 +26,7 @@ private static Task Success(HttpContext context)
return Task.FromResult<object>(null);
}
private static void UseSuccess(IBuilder app)
private static void UseSuccess(IApplicationBuilder app)
{
app.Run(Success);
}
@@ -36,7 +36,7 @@ private static Task NotImplemented(HttpContext context)
throw new NotImplementedException();
}
private static void UseNotImplemented(IBuilder app)
private static void UseNotImplemented(IApplicationBuilder app)
{
app.Run(NotImplemented);
}
@@ -64,8 +64,8 @@ private Task<bool> FalsePredicateAsync(HttpContext context)
[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<ArgumentNullException>(() => builder.MapWhen(null, UseNotImplemented));
// TODO: [NotNull] Assert.Throws<ArgumentNullException>(() => builder.MapWhen(NotImplementedPredicate, (Action<IBuilder>)null));
@@ -82,7 +82,7 @@ public void NullArguments_ArgumentNullException()
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 @@ public void PredicateTrue_BranchTaken()
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 @@ public void PredicateTrueAction_BranchTaken()
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 @@ public void PredicateFalseAction_PassThrough()
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 @@ public void PredicateAsyncTrueAction_BranchTaken()
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 @@ public void PredicateAsyncFalseAction_PassThrough()
[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 @@ public void ChainedPredicates_Success()
[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);
@@ -6,12 +6,12 @@
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<HttpContext>();

0 comments on commit 335895d

Please sign in to comment.