Add delay to requests to simulate slow connection

This commit is contained in:
2020-03-09 17:47:49 +01:00
parent 13a87b7094
commit 2262340754
2 changed files with 32 additions and 14 deletions

View File

@@ -0,0 +1,22 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Filters;
namespace EstusShots.Server.Filters
{
/// <summary>
/// Adds 2 seconds of wait time to each request
/// </summary>
public class DebugDelayFilter : IActionFilter
{
public void OnActionExecuted(ActionExecutedContext context)
{
}
public void OnActionExecuting(ActionExecutingContext context)
{
Task.Delay(2000).Wait();
}
}
}

View File

@@ -1,4 +1,5 @@
using AutoMapper; using AutoMapper;
using EstusShots.Server.Filters;
using EstusShots.Server.Services; using EstusShots.Server.Services;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
@@ -31,13 +32,11 @@ namespace EstusShots.Server
opt.UseSqlite(Configuration.GetConnectionString("Sqlite")); opt.UseSqlite(Configuration.GetConnectionString("Sqlite"));
}); });
services.AddAutoMapper(typeof(Startup)); services.AddAutoMapper(typeof(Startup));
services.AddControllers().AddJsonOptions(options => services.AddControllers(options => { options.Filters.Add(typeof(DebugDelayFilter)); })
.AddJsonOptions(options =>
{ {
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true; options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
if (IsDevelopment) if (IsDevelopment) options.JsonSerializerOptions.WriteIndented = true;
{
options.JsonSerializerOptions.WriteIndented = true;
}
}); });
services.AddSwaggerGen(options => services.AddSwaggerGen(options =>
{ {
@@ -67,10 +66,7 @@ namespace EstusShots.Server
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint. // specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c => app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Estus Shots API V1"); });
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Estus Shots API V1");
});
app.UseRouting(); app.UseRouting();
app.UseAuthorization(); app.UseAuthorization();