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 EstusShots.Server.Filters;
using EstusShots.Server.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@@ -31,17 +32,15 @@ namespace EstusShots.Server
opt.UseSqlite(Configuration.GetConnectionString("Sqlite"));
});
services.AddAutoMapper(typeof(Startup));
services.AddControllers().AddJsonOptions(options =>
services.AddControllers(options => { options.Filters.Add(typeof(DebugDelayFilter)); })
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
if (IsDevelopment)
{
options.JsonSerializerOptions.WriteIndented = true;
}
if (IsDevelopment) options.JsonSerializerOptions.WriteIndented = true;
});
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Estus Shots API", Version = "v1" });
options.SwaggerDoc("v1", new OpenApiInfo {Title = "Estus Shots API", Version = "v1"});
});
// Register business logic services
@@ -67,10 +66,7 @@ namespace EstusShots.Server
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Estus Shots API V1");
});
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Estus Shots API V1"); });
app.UseRouting();
app.UseAuthorization();