Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 7d7cd5f

Browse files
committed
#265 Remove some overloads for Run, Map, and MapWhen.
1 parent 43c3913 commit 7d7cd5f

File tree

7 files changed

+12
-141
lines changed

7 files changed

+12
-141
lines changed

src/Microsoft.AspNet.Http.Core/Extensions/MapExtensions.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ namespace Microsoft.AspNet.Builder
1010
{
1111
public static class MapExtensions
1212
{
13-
/// <summary>
14-
/// If the request path starts with the given pathMatch, execute the app configured via configuration parameter instead of
15-
/// continuing to the next component in the pipeline.
16-
/// </summary>
17-
/// <param name="app"></param>
18-
/// <param name="pathMatch">The path to match</param>
19-
/// <param name="configuration">The branch to take for positive path matches</param>
20-
/// <returns></returns>
21-
public static IApplicationBuilder Map([NotNull] this IApplicationBuilder app, [NotNull] string pathMatch, [NotNull] Action<IApplicationBuilder> configuration)
22-
{
23-
return Map(app, new PathString(pathMatch), configuration);
24-
}
25-
2613
/// <summary>
2714
/// If the request path starts with the given pathMatch, execute the app configured via configuration parameter instead of
2815
/// continuing to the next component in the pipeline.

src/Microsoft.AspNet.Http.Core/Extensions/MapWhenExtensions.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
using System.Threading.Tasks;
66
using Microsoft.AspNet.Http;
77
using Microsoft.AspNet.Builder.Extensions;
8+
using Microsoft.Framework.Internal;
89

910
namespace Microsoft.AspNet.Builder
1011
{
11-
using Microsoft.Framework.Internal;
1212
using Predicate = Func<HttpContext, bool>;
13-
using PredicateAsync = Func<HttpContext, Task<bool>>;
1413

1514
/// <summary>
1615
/// Extension methods for the MapWhenMiddleware
@@ -39,28 +38,5 @@ public static IApplicationBuilder MapWhen([NotNull] this IApplicationBuilder app
3938
};
4039
return app.Use(next => new MapWhenMiddleware(next, options).Invoke);
4140
}
42-
43-
/// <summary>
44-
/// Branches the request pipeline based on the async result of the given predicate.
45-
/// </summary>
46-
/// <param name="app"></param>
47-
/// <param name="predicate">Invoked asynchronously with the request environment to determine if the branch should be taken</param>
48-
/// <param name="configuration">Configures a branch to take</param>
49-
/// <returns></returns>
50-
public static IApplicationBuilder MapWhenAsync([NotNull] this IApplicationBuilder app, [NotNull] PredicateAsync predicate, [NotNull] Action<IApplicationBuilder> configuration)
51-
{
52-
// create branch
53-
var branchBuilder = app.New();
54-
configuration(branchBuilder);
55-
var branch = branchBuilder.Build();
56-
57-
// put middleware in pipeline
58-
var options = new MapWhenOptions
59-
{
60-
PredicateAsync = predicate,
61-
Branch = branch,
62-
};
63-
return app.Use(next => new MapWhenMiddleware(next, options).Invoke);
64-
}
6541
}
6642
}

src/Microsoft.AspNet.Http.Core/Extensions/MapWhenMiddleware.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,13 @@ public MapWhenMiddleware([NotNull] RequestDelegate next, [NotNull] MapWhenOption
2020

2121
public async Task Invoke([NotNull] HttpContext context)
2222
{
23-
if (_options.Predicate != null)
23+
if (_options.Predicate(context))
2424
{
25-
if (_options.Predicate(context))
26-
{
27-
await _options.Branch(context);
28-
}
29-
else
30-
{
31-
await _next(context);
32-
}
25+
await _options.Branch(context);
3326
}
3427
else
3528
{
36-
if (await _options.PredicateAsync(context))
37-
{
38-
await _options.Branch(context);
39-
}
40-
else
41-
{
42-
await _next(context);
43-
}
29+
await _next(context);
4430
}
4531
}
4632
}

src/Microsoft.AspNet.Http.Core/Extensions/MapWhenOptions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ public class MapWhenOptions
1717
/// </summary>
1818
public Func<HttpContext, bool> Predicate { get; set; }
1919

20-
/// <summary>
21-
/// The async user callback that determines if the branch should be taken
22-
/// </summary>
23-
public Func<HttpContext, Task<bool>> PredicateAsync { get; set; }
24-
2520
/// <summary>
2621
/// The branch taken for a positive match
2722
/// </summary>

src/Microsoft.AspNet.Http.Core/Extensions/RunExtensions.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,5 @@ public static void Run([NotNull] this IApplicationBuilder app, [NotNull] Request
1414
{
1515
app.Use(_ => handler);
1616
}
17-
18-
public static void Run<TService1>(this IApplicationBuilder app, Func<HttpContext, TService1, Task> handler)
19-
{
20-
app.Use<TService1>((ctx, _, s1) => handler(ctx, s1));
21-
}
22-
23-
public static void Run<TService1, TService2>(this IApplicationBuilder app, Func<HttpContext, TService1, TService2, Task> handler)
24-
{
25-
app.Use<TService1, TService2>((ctx, _, s1, s2) => handler(ctx, s1, s2));
26-
}
27-
28-
public static void Run<TService1, TService2, TService3>(this IApplicationBuilder app, Func<HttpContext, TService1, TService2, TService3, Task> handler)
29-
{
30-
app.Use<TService1, TService2, TService3>((ctx, _, s1, s2, s3) => handler(ctx, s1, s2, s3));
31-
}
32-
33-
public static void Run<TService1, TService2, TService3, TService4>(this IApplicationBuilder app, Func<HttpContext, TService1, TService2, TService3, TService4, Task> handler)
34-
{
35-
app.Use<TService1, TService2, TService3, TService4>((ctx, _, s1, s2, s3, s4) => handler(ctx, s1, s2, s3, s4));
36-
}
3717
}
3818
}

test/Microsoft.AspNet.Http.Core.Tests/MapPathMiddlewareTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void PathMatchFunc_BranchTaken(string matchPath, string basePath, string
6060
{
6161
HttpContext context = CreateRequest(basePath, requestPath);
6262
var builder = new ApplicationBuilder(serviceProvider: null);
63-
builder.Map(matchPath, UseSuccess);
63+
builder.Map(new PathString(matchPath), UseSuccess);
6464
var app = builder.Build();
6565
app.Invoke(context).Wait();
6666

@@ -81,7 +81,7 @@ public void PathMatchAction_BranchTaken(string matchPath, string basePath, strin
8181
{
8282
HttpContext context = CreateRequest(basePath, requestPath);
8383
var builder = new ApplicationBuilder(serviceProvider: null);
84-
builder.Map(matchPath, subBuilder => subBuilder.Run(Success));
84+
builder.Map(new PathString(matchPath), subBuilder => subBuilder.Run(Success));
8585
var app = builder.Build();
8686
app.Invoke(context).Wait();
8787

@@ -96,7 +96,7 @@ public void PathMatchAction_BranchTaken(string matchPath, string basePath, strin
9696
[InlineData("/foo/cho/")]
9797
public void MatchPathWithTrailingSlashThrowsException(string matchPath)
9898
{
99-
Should.Throw<ArgumentException>(() => new ApplicationBuilder(serviceProvider: null).Map(matchPath, map => { }).Build());
99+
Should.Throw<ArgumentException>(() => new ApplicationBuilder(serviceProvider: null).Map(new PathString(matchPath), map => { }).Build());
100100
}
101101

102102
[Theory]
@@ -111,7 +111,7 @@ public void PathMismatchFunc_PassedThrough(string matchPath, string basePath, st
111111
{
112112
HttpContext context = CreateRequest(basePath, requestPath);
113113
var builder = new ApplicationBuilder(serviceProvider: null);
114-
builder.Map(matchPath, UseNotImplemented);
114+
builder.Map(new PathString(matchPath), UseNotImplemented);
115115
builder.Run(Success);
116116
var app = builder.Build();
117117
app.Invoke(context).Wait();
@@ -133,7 +133,7 @@ public void PathMismatchAction_PassedThrough(string matchPath, string basePath,
133133
{
134134
HttpContext context = CreateRequest(basePath, requestPath);
135135
var builder = new ApplicationBuilder(serviceProvider: null);
136-
builder.Map(matchPath, UseNotImplemented);
136+
builder.Map(new PathString(matchPath), UseNotImplemented);
137137
builder.Run(Success);
138138
var app = builder.Build();
139139
app.Invoke(context).Wait();
@@ -147,12 +147,12 @@ public void PathMismatchAction_PassedThrough(string matchPath, string basePath,
147147
public void ChainedRoutes_Success()
148148
{
149149
var builder = new ApplicationBuilder(serviceProvider: null);
150-
builder.Map("/route1", map =>
150+
builder.Map(new PathString("/route1"), map =>
151151
{
152-
map.Map((string)"/subroute1", UseSuccess);
152+
map.Map(new PathString("/subroute1"), UseSuccess);
153153
map.Run(NotImplemented);
154154
});
155-
builder.Map("/route2/subroute2", UseSuccess);
155+
builder.Map(new PathString("/route2/subroute2"), UseSuccess);
156156
var app = builder.Build();
157157

158158
HttpContext context = CreateRequest(string.Empty, "/route1");

test/Microsoft.AspNet.Http.Core.Tests/MapPredicateMiddlewareTests.cs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace Microsoft.AspNet.Builder.Extensions
1616
public class MapPredicateMiddlewareTests
1717
{
1818
private static readonly Predicate NotImplementedPredicate = new Predicate(envionment => { throw new NotImplementedException(); });
19-
private static readonly PredicateAsync NotImplementedPredicateAsync = new PredicateAsync(envionment => { throw new NotImplementedException(); });
2019

2120
private static Task Success(HttpContext context)
2221
{
@@ -49,16 +48,6 @@ private bool FalsePredicate(HttpContext context)
4948
return false;
5049
}
5150

52-
private Task<bool> TruePredicateAsync(HttpContext context)
53-
{
54-
return Task.FromResult<bool>(true);
55-
}
56-
57-
private Task<bool> FalsePredicateAsync(HttpContext context)
58-
{
59-
return Task.FromResult<bool>(false);
60-
}
61-
6251
[Fact]
6352
public void NullArguments_ArgumentNullException()
6453
{
@@ -113,31 +102,6 @@ public void PredicateFalseAction_PassThrough()
113102
Assert.Equal(200, context.Response.StatusCode);
114103
}
115104

116-
[Fact]
117-
public void PredicateAsyncTrueAction_BranchTaken()
118-
{
119-
HttpContext context = CreateRequest();
120-
var builder = new ApplicationBuilder(serviceProvider: null);
121-
builder.MapWhenAsync(TruePredicateAsync, UseSuccess);
122-
var app = builder.Build();
123-
app.Invoke(context).Wait();
124-
125-
Assert.Equal(200, context.Response.StatusCode);
126-
}
127-
128-
[Fact]
129-
public void PredicateAsyncFalseAction_PassThrough()
130-
{
131-
HttpContext context = CreateRequest();
132-
var builder = new ApplicationBuilder(serviceProvider: null);
133-
builder.MapWhenAsync(FalsePredicateAsync, UseNotImplemented);
134-
builder.Run(Success);
135-
var app = builder.Build();
136-
app.Invoke(context).Wait();
137-
138-
Assert.Equal(200, context.Response.StatusCode);
139-
}
140-
141105
[Fact]
142106
public void ChainedPredicates_Success()
143107
{
@@ -155,23 +119,6 @@ public void ChainedPredicates_Success()
155119
Assert.Equal(200, context.Response.StatusCode);
156120
}
157121

158-
[Fact]
159-
public void ChainedPredicatesAsync_Success()
160-
{
161-
var builder = new ApplicationBuilder(serviceProvider: null);
162-
builder.MapWhenAsync(TruePredicateAsync, map1 =>
163-
{
164-
map1.MapWhenAsync((PredicateAsync)FalsePredicateAsync, UseNotImplemented);
165-
map1.MapWhenAsync((PredicateAsync)TruePredicateAsync, map2 => map2.MapWhenAsync((PredicateAsync)TruePredicateAsync, UseSuccess));
166-
map1.Run(NotImplemented);
167-
});
168-
var app = builder.Build();
169-
170-
HttpContext context = CreateRequest();
171-
app.Invoke(context).Wait();
172-
Assert.Equal(200, context.Response.StatusCode);
173-
}
174-
175122
private HttpContext CreateRequest()
176123
{
177124
HttpContext context = new DefaultHttpContext();

0 commit comments

Comments
 (0)