Standardizing middleware to use configureOptions lambda
This commit is contained in:
parent
2b2c42069c
commit
6f9b827e5b
|
|
@ -1,6 +1,5 @@
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
using Microsoft.AspNet.Hosting;
|
using Microsoft.AspNet.Hosting;
|
||||||
using Microsoft.AspNet.StaticFiles;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
|
@ -18,9 +17,9 @@ namespace StaticFilesSample
|
||||||
// Displays all log levels
|
// Displays all log levels
|
||||||
factory.AddConsole(LogLevel.Debug);
|
factory.AddConsole(LogLevel.Debug);
|
||||||
|
|
||||||
app.UseFileServer(new FileServerOptions()
|
app.UseFileServer(options =>
|
||||||
{
|
{
|
||||||
EnableDirectoryBrowsing = true,
|
options.EnableDirectoryBrowsing = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,53 +15,55 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enables default file mapping on the current path
|
/// Enables default file mapping on the current path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="app"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder builder)
|
public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (app == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.UseDefaultFiles(new DefaultFilesOptions());
|
return app.UseDefaultFiles(options => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enables default file mapping for the given request path
|
/// Enables default file mapping for the given request path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="app"></param>
|
||||||
/// <param name="requestPath">The relative request path.</param>
|
/// <param name="requestPath">The relative request path.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder builder, string requestPath)
|
public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder app, string requestPath)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (app == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.UseDefaultFiles(new DefaultFilesOptions() { RequestPath = new PathString(requestPath) });
|
return app.UseDefaultFiles(options => { options.RequestPath = new PathString(requestPath); });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enables default file mapping with the given options
|
/// Enables default file mapping with the given options
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="app"></param>
|
||||||
/// <param name="options"></param>
|
/// <param name="configureOptions"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder builder, DefaultFilesOptions options)
|
public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder app, Action<DefaultFilesOptions> configureOptions)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (app == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(app));
|
||||||
|
}
|
||||||
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options == null)
|
var options = new DefaultFilesOptions();
|
||||||
{
|
configureOptions(options);
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.UseMiddleware<DefaultFilesMiddleware>(options);
|
return app.UseMiddleware<DefaultFilesMiddleware>(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -15,53 +15,55 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enable directory browsing on the current path
|
/// Enable directory browsing on the current path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="app"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder builder)
|
public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (app == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.UseDirectoryBrowser(new DirectoryBrowserOptions());
|
return app.UseDirectoryBrowser(options => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enables directory browsing for the given request path
|
/// Enables directory browsing for the given request path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="app"></param>
|
||||||
/// <param name="requestPath">The relative request path.</param>
|
/// <param name="requestPath">The relative request path.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder builder, string requestPath)
|
public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder app, string requestPath)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (app == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.UseDirectoryBrowser(new DirectoryBrowserOptions() { RequestPath = new PathString(requestPath) });
|
return app.UseDirectoryBrowser(options => { options.RequestPath = new PathString(requestPath); });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enable directory browsing with the given options
|
/// Enable directory browsing with the given options
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="app"></param>
|
||||||
/// <param name="options"></param>
|
/// <param name="configureOptions"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder builder, DirectoryBrowserOptions options)
|
public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder app, Action<DirectoryBrowserOptions> configureOptions)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (app == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(app));
|
||||||
|
}
|
||||||
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options == null)
|
var options = new DirectoryBrowserOptions();
|
||||||
{
|
configureOptions(options);
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.UseMiddleware<DirectoryBrowserMiddleware>(options);
|
return app.UseMiddleware<DirectoryBrowserMiddleware>(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,45 +16,45 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enable all static file middleware (except directory browsing) for the current request path in the current directory.
|
/// Enable all static file middleware (except directory browsing) for the current request path in the current directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="app"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder)
|
public static IApplicationBuilder UseFileServer(this IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (app == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.UseFileServer(new FileServerOptions());
|
return app.UseFileServer(options => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enable all static file middleware on for the current request path in the current directory.
|
/// Enable all static file middleware on for the current request path in the current directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="app"></param>
|
||||||
/// <param name="enableDirectoryBrowsing">Should directory browsing be enabled?</param>
|
/// <param name="enableDirectoryBrowsing">Should directory browsing be enabled?</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder, bool enableDirectoryBrowsing)
|
public static IApplicationBuilder UseFileServer(this IApplicationBuilder app, bool enableDirectoryBrowsing)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (app == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.UseFileServer(new FileServerOptions() { EnableDirectoryBrowsing = enableDirectoryBrowsing });
|
return app.UseFileServer(options => { options.EnableDirectoryBrowsing = enableDirectoryBrowsing; });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enables all static file middleware (except directory browsing) for the given request path from the directory of the same name
|
/// Enables all static file middleware (except directory browsing) for the given request path from the directory of the same name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="app"></param>
|
||||||
/// <param name="requestPath">The relative request path.</param>
|
/// <param name="requestPath">The relative request path.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder, string requestPath)
|
public static IApplicationBuilder UseFileServer(this IApplicationBuilder app, string requestPath)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (app == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestPath == null)
|
if (requestPath == null)
|
||||||
|
|
@ -62,44 +62,40 @@ namespace Microsoft.AspNet.Builder
|
||||||
throw new ArgumentNullException(nameof(requestPath));
|
throw new ArgumentNullException(nameof(requestPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.UseFileServer(new FileServerOptions() { RequestPath = new PathString(requestPath) });
|
return app.UseFileServer(options => { options.RequestPath = new PathString(requestPath); });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enable all static file middleware with the given options
|
/// Enable all static file middleware with the given options
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="app"></param>
|
||||||
/// <param name="options"></param>
|
/// <param name="configureOptions"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder, FileServerOptions options)
|
public static IApplicationBuilder UseFileServer(this IApplicationBuilder app, Action<FileServerOptions> configureOptions)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (app == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(app));
|
||||||
|
}
|
||||||
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options == null)
|
var fileServerOptions = new FileServerOptions();
|
||||||
|
configureOptions(fileServerOptions);
|
||||||
|
|
||||||
|
if (fileServerOptions.EnableDefaultFiles)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(options));
|
app = app.UseDefaultFiles(options => { options = fileServerOptions.DefaultFilesOptions; });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options == null)
|
if (fileServerOptions.EnableDirectoryBrowsing)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(options));
|
app = app.UseDirectoryBrowser(options => { options = fileServerOptions.DirectoryBrowserOptions; });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.EnableDefaultFiles)
|
return app.UseStaticFiles(options => { options = fileServerOptions.StaticFileOptions; });
|
||||||
{
|
|
||||||
builder = builder.UseDefaultFiles(options.DefaultFilesOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.EnableDirectoryBrowsing)
|
|
||||||
{
|
|
||||||
builder = builder.UseDirectoryBrowser(options.DirectoryBrowserOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder
|
|
||||||
.UseStaticFiles(options.StaticFileOptions);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -15,53 +15,55 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enables static file serving for the current request path
|
/// Enables static file serving for the current request path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="app"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder builder)
|
public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (app == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.UseStaticFiles(new StaticFileOptions());
|
return app.UseStaticFiles(options => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enables static file serving for the given request path
|
/// Enables static file serving for the given request path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="app"></param>
|
||||||
/// <param name="requestPath">The relative request path.</param>
|
/// <param name="requestPath">The relative request path.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder builder, string requestPath)
|
public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder app, string requestPath)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (app == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(app));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.UseStaticFiles(new StaticFileOptions() { RequestPath = new PathString(requestPath) });
|
return app.UseStaticFiles(options => { options.RequestPath = new PathString(requestPath); });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enables static file serving with the given options
|
/// Enables static file serving with the given options
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="app"></param>
|
||||||
/// <param name="options"></param>
|
/// <param name="configureOptions"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder builder, StaticFileOptions options)
|
public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder app, Action<StaticFileOptions> configureOptions)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (app == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(builder));
|
throw new ArgumentNullException(nameof(app));
|
||||||
|
}
|
||||||
|
if (configureOptions == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(configureOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options == null)
|
var options = new StaticFileOptions();
|
||||||
{
|
configureOptions(options);
|
||||||
throw new ArgumentNullException(nameof(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.UseMiddleware<StaticFileMiddleware>(options);
|
return app.UseMiddleware<StaticFileMiddleware>(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
public async Task NullArguments()
|
public async Task NullArguments()
|
||||||
{
|
{
|
||||||
// No exception, default provided
|
// No exception, default provided
|
||||||
StaticFilesTestServer.Create(app => app.UseDefaultFiles(new DefaultFilesOptions() { FileProvider = null }));
|
StaticFilesTestServer.Create(app => app.UseDefaultFiles(options => { options.FileProvider = null; }));
|
||||||
|
|
||||||
// PathString(null) is OK.
|
// PathString(null) is OK.
|
||||||
var server = StaticFilesTestServer.Create(app => app.UseDefaultFiles((string)null));
|
var server = StaticFilesTestServer.Create(app => app.UseDefaultFiles((string)null));
|
||||||
|
|
@ -56,10 +56,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
{
|
{
|
||||||
var server = StaticFilesTestServer.Create(app =>
|
var server = StaticFilesTestServer.Create(app =>
|
||||||
{
|
{
|
||||||
app.UseDefaultFiles(new DefaultFilesOptions()
|
app.UseDefaultFiles(options =>
|
||||||
{
|
{
|
||||||
RequestPath = new PathString(baseUrl),
|
options.RequestPath = new PathString(baseUrl);
|
||||||
FileProvider = fileProvider
|
options.FileProvider = fileProvider;
|
||||||
});
|
});
|
||||||
app.Run(context => context.Response.WriteAsync(context.Request.Path.Value));
|
app.Run(context => context.Response.WriteAsync(context.Request.Path.Value));
|
||||||
});
|
});
|
||||||
|
|
@ -95,10 +95,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
{
|
{
|
||||||
var server = StaticFilesTestServer.Create(app =>
|
var server = StaticFilesTestServer.Create(app =>
|
||||||
{
|
{
|
||||||
app.UseDefaultFiles(new DefaultFilesOptions()
|
app.UseDefaultFiles(options =>
|
||||||
{
|
{
|
||||||
RequestPath = new PathString(baseUrl),
|
options.RequestPath = new PathString(baseUrl);
|
||||||
FileProvider = fileProvider
|
options.FileProvider = fileProvider;
|
||||||
});
|
});
|
||||||
app.Run(context => context.Response.WriteAsync(context.Request.Path.Value));
|
app.Run(context => context.Response.WriteAsync(context.Request.Path.Value));
|
||||||
});
|
});
|
||||||
|
|
@ -132,10 +132,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
{
|
{
|
||||||
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
||||||
{
|
{
|
||||||
var server = StaticFilesTestServer.Create(app => app.UseDefaultFiles(new DefaultFilesOptions()
|
var server = StaticFilesTestServer.Create(app => app.UseDefaultFiles(options =>
|
||||||
{
|
{
|
||||||
RequestPath = new PathString(baseUrl),
|
options.RequestPath = new PathString(baseUrl);
|
||||||
FileProvider = fileProvider
|
options.FileProvider = fileProvider;
|
||||||
}));
|
}));
|
||||||
var response = await server.CreateRequest(requestUrl + queryString).GetAsync();
|
var response = await server.CreateRequest(requestUrl + queryString).GetAsync();
|
||||||
|
|
||||||
|
|
@ -170,10 +170,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
{
|
{
|
||||||
using (var fileProvder = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
using (var fileProvder = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
||||||
{
|
{
|
||||||
var server = StaticFilesTestServer.Create(app => app.UseDefaultFiles(new DefaultFilesOptions()
|
var server = StaticFilesTestServer.Create(app => app.UseDefaultFiles(options =>
|
||||||
{
|
{
|
||||||
RequestPath = new PathString(baseUrl),
|
options.RequestPath = new PathString(baseUrl);
|
||||||
FileProvider = fileProvder
|
options.FileProvider = fileProvder;
|
||||||
}));
|
}));
|
||||||
var response = await server.CreateRequest(requestUrl).GetAsync();
|
var response = await server.CreateRequest(requestUrl).GetAsync();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,12 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
public async Task NullArguments()
|
public async Task NullArguments()
|
||||||
{
|
{
|
||||||
Assert.Throws<ArgumentException>(() => StaticFilesTestServer.Create(
|
Assert.Throws<ArgumentException>(() => StaticFilesTestServer.Create(
|
||||||
app => app.UseDirectoryBrowser(new DirectoryBrowserOptions() { Formatter = null }),
|
app => app.UseDirectoryBrowser(options => { options.Formatter = null; }),
|
||||||
services => services.AddDirectoryBrowser()));
|
services => services.AddDirectoryBrowser()));
|
||||||
|
|
||||||
// No exception, default provided
|
// No exception, default provided
|
||||||
StaticFilesTestServer.Create(
|
StaticFilesTestServer.Create(
|
||||||
app => app.UseDirectoryBrowser(new DirectoryBrowserOptions() { FileProvider = null }),
|
app => app.UseDirectoryBrowser(options => { options.FileProvider = null; }),
|
||||||
services => services.AddDirectoryBrowser());
|
services => services.AddDirectoryBrowser());
|
||||||
|
|
||||||
// PathString(null) is OK.
|
// PathString(null) is OK.
|
||||||
|
|
@ -66,10 +66,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
||||||
{
|
{
|
||||||
var server = StaticFilesTestServer.Create(
|
var server = StaticFilesTestServer.Create(
|
||||||
app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
|
app => app.UseDirectoryBrowser(options =>
|
||||||
{
|
{
|
||||||
RequestPath = new PathString(baseUrl),
|
options.RequestPath = new PathString(baseUrl);
|
||||||
FileProvider = fileProvider
|
options.FileProvider = fileProvider;
|
||||||
}),
|
}),
|
||||||
services => services.AddDirectoryBrowser());
|
services => services.AddDirectoryBrowser());
|
||||||
var response = await server.CreateRequest(requestUrl).GetAsync();
|
var response = await server.CreateRequest(requestUrl).GetAsync();
|
||||||
|
|
@ -103,10 +103,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
||||||
{
|
{
|
||||||
var server = StaticFilesTestServer.Create(
|
var server = StaticFilesTestServer.Create(
|
||||||
app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
|
app => app.UseDirectoryBrowser(options =>
|
||||||
{
|
{
|
||||||
RequestPath = new PathString(baseUrl),
|
options.RequestPath = new PathString(baseUrl);
|
||||||
FileProvider = fileProvider
|
options.FileProvider = fileProvider;
|
||||||
}),
|
}),
|
||||||
services => services.AddDirectoryBrowser());
|
services => services.AddDirectoryBrowser());
|
||||||
var response = await server.CreateRequest(requestUrl).GetAsync();
|
var response = await server.CreateRequest(requestUrl).GetAsync();
|
||||||
|
|
@ -145,10 +145,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
||||||
{
|
{
|
||||||
var server = StaticFilesTestServer.Create(
|
var server = StaticFilesTestServer.Create(
|
||||||
app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
|
app => app.UseDirectoryBrowser(options =>
|
||||||
{
|
{
|
||||||
RequestPath = new PathString(baseUrl),
|
options.RequestPath = new PathString(baseUrl);
|
||||||
FileProvider = fileProvider
|
options.FileProvider = fileProvider;
|
||||||
}),
|
}),
|
||||||
services => services.AddDirectoryBrowser());
|
services => services.AddDirectoryBrowser());
|
||||||
|
|
||||||
|
|
@ -184,10 +184,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
||||||
{
|
{
|
||||||
var server = StaticFilesTestServer.Create(
|
var server = StaticFilesTestServer.Create(
|
||||||
app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
|
app => app.UseDirectoryBrowser(options =>
|
||||||
{
|
{
|
||||||
RequestPath = new PathString(baseUrl),
|
options.RequestPath = new PathString(baseUrl);
|
||||||
FileProvider = fileProvider
|
options.FileProvider = fileProvider;
|
||||||
}),
|
}),
|
||||||
services => services.AddDirectoryBrowser());
|
services => services.AddDirectoryBrowser());
|
||||||
|
|
||||||
|
|
@ -220,10 +220,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
||||||
{
|
{
|
||||||
var server = StaticFilesTestServer.Create(
|
var server = StaticFilesTestServer.Create(
|
||||||
app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
|
app => app.UseDirectoryBrowser(options =>
|
||||||
{
|
{
|
||||||
RequestPath = new PathString(baseUrl),
|
options.RequestPath = new PathString(baseUrl);
|
||||||
FileProvider = fileProvider
|
options.FileProvider = fileProvider;
|
||||||
}),
|
}),
|
||||||
services => services.AddDirectoryBrowser());
|
services => services.AddDirectoryBrowser());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task NullArguments()
|
public async Task NullArguments()
|
||||||
{
|
{
|
||||||
Assert.Throws<ArgumentException>(() => StaticFilesTestServer.Create(app => app.UseStaticFiles(new StaticFileOptions() { ContentTypeProvider = null })));
|
Assert.Throws<ArgumentException>(() => StaticFilesTestServer.Create(app => app.UseStaticFiles(options => { options.ContentTypeProvider = null; })));
|
||||||
|
|
||||||
// No exception, default provided
|
// No exception, default provided
|
||||||
StaticFilesTestServer.Create(app => app.UseStaticFiles(new StaticFileOptions() { FileProvider = null }));
|
StaticFilesTestServer.Create(app => app.UseStaticFiles(options => { options.FileProvider = null; }));
|
||||||
|
|
||||||
// PathString(null) is OK.
|
// PathString(null) is OK.
|
||||||
var server = StaticFilesTestServer.Create(app => app.UseStaticFiles((string)null));
|
var server = StaticFilesTestServer.Create(app => app.UseStaticFiles((string)null));
|
||||||
|
|
@ -52,10 +52,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
{
|
{
|
||||||
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
||||||
{
|
{
|
||||||
var server = StaticFilesTestServer.Create(app => app.UseStaticFiles(new StaticFileOptions()
|
var server = StaticFilesTestServer.Create(app => app.UseStaticFiles(options =>
|
||||||
{
|
{
|
||||||
RequestPath = new PathString(baseUrl),
|
options.RequestPath = new PathString(baseUrl);
|
||||||
FileProvider = fileProvider
|
options.FileProvider = fileProvider;
|
||||||
}));
|
}));
|
||||||
var response = await server.CreateRequest(requestUrl).GetAsync();
|
var response = await server.CreateRequest(requestUrl).GetAsync();
|
||||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
|
|
@ -89,10 +89,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
{
|
{
|
||||||
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
||||||
{
|
{
|
||||||
var server = StaticFilesTestServer.Create(app => app.UseStaticFiles(new StaticFileOptions()
|
var server = StaticFilesTestServer.Create(app => app.UseStaticFiles(options =>
|
||||||
{
|
{
|
||||||
RequestPath = new PathString(baseUrl),
|
options.RequestPath = new PathString(baseUrl);
|
||||||
FileProvider = fileProvider
|
options.FileProvider = fileProvider;
|
||||||
}));
|
}));
|
||||||
var response = await server.CreateRequest(requestUrl).GetAsync();
|
var response = await server.CreateRequest(requestUrl).GetAsync();
|
||||||
|
|
||||||
|
|
@ -113,10 +113,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
{
|
{
|
||||||
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
||||||
{
|
{
|
||||||
var server = StaticFilesTestServer.Create(app => app.UseStaticFiles(new StaticFileOptions()
|
var server = StaticFilesTestServer.Create(app => app.UseStaticFiles(options =>
|
||||||
{
|
{
|
||||||
RequestPath = new PathString(baseUrl),
|
options.RequestPath = new PathString(baseUrl);
|
||||||
FileProvider = fileProvider
|
options.FileProvider = fileProvider;
|
||||||
}));
|
}));
|
||||||
var response = await server.CreateRequest(requestUrl).PostAsync();
|
var response = await server.CreateRequest(requestUrl).PostAsync();
|
||||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
|
|
@ -133,10 +133,10 @@ namespace Microsoft.AspNet.StaticFiles
|
||||||
{
|
{
|
||||||
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
|
||||||
{
|
{
|
||||||
var server = StaticFilesTestServer.Create(app => app.UseStaticFiles(new StaticFileOptions()
|
var server = StaticFilesTestServer.Create(app => app.UseStaticFiles(options =>
|
||||||
{
|
{
|
||||||
RequestPath = new PathString(baseUrl),
|
options.RequestPath = new PathString(baseUrl);
|
||||||
FileProvider = fileProvider
|
options.FileProvider = fileProvider;
|
||||||
}));
|
}));
|
||||||
var response = await server.CreateRequest(requestUrl).SendAsync("HEAD");
|
var response = await server.CreateRequest(requestUrl).SendAsync("HEAD");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue