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