Add delay to requests to simulate slow connection
This commit is contained in:
22
EstusShots.Server/Filters/DebugDelayFilter.cs
Normal file
22
EstusShots.Server/Filters/DebugDelayFilter.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,17 +32,15 @@ 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 =>
|
||||||
{
|
{
|
||||||
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
|
// Register business logic services
|
||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user