/// <summary> /// If the request path starts with the given pathMatch, execute the app configured via configuration parameter instead of /// continuing to the next component in the pipeline. /// </summary> /// <param name="app"></param> /// <param name="pathMatch">The path to match</param> /// <param name="configuration">The branch to take for positive path matches</param> /// <returns></returns> public static IApplicationBuilder Map(this IApplicationBuilder app, PathString pathMatch, Action<IApplicationBuilder> configuration) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (pathMatch.HasValue && pathMatch.Value.EndsWith("/", StringComparison.Ordinal)) { throw new ArgumentException("The path must not end with a '/'", nameof(pathMatch)); } // create branch var branchBuilder = app.New(); configuration(branchBuilder); var branch = branchBuilder.Build(); var options = new MapOptions() { Branch = branch, PathMatch = pathMatch, }; return app.Use(next => new MapMiddleware(next, options).Invoke); }
public void NullArguments_ArgumentNullException() { var builder = new ApplicationBuilder(serviceProvider: null); var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build(); var noOptions = new MapOptions(); Assert.Throws<ArgumentNullException>(() => builder.Map("/foo", configuration: null)); Assert.Throws<ArgumentNullException>(() => new MapMiddleware(noMiddleware, null)); }
public void NullArguments_ArgumentNullException() { var builder = new ApplicationBuilder(serviceProvider: null); var noMiddleware = new ApplicationBuilder(serviceProvider: null).Build(); var noOptions = new MapOptions(); Assert.Throws <ArgumentNullException>(() => builder.Map("/foo", configuration: null)); Assert.Throws <ArgumentNullException>(() => new MapMiddleware(noMiddleware, null)); }
public void NullArguments_ArgumentNullException() { 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)); // TODO: [NotNull] Assert.Throws<ArgumentNullException>(() => new MapMiddleware(null, noOptions)); // TODO: [NotNull] Assert.Throws<ArgumentNullException>(() => new MapMiddleware(noMiddleware, null)); }
/// <summary> /// Creates a new instace of <see cref="MapMiddleware"/>. /// </summary> /// <param name="next">The delegate representing the next middleware in the request pipeline.</param> /// <param name="options">The middleware options.</param> public MapMiddleware(RequestDelegate next, MapOptions options) { if (next == null) { throw new ArgumentNullException(nameof(next)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } _next = next; _options = options; }
public MapMiddleware([NotNull] RequestDelegate next, [NotNull] MapOptions options) { _next = next; _options = options; }