Skip to content

Commit

Permalink
Mount test endpoint on /api path
Browse files Browse the repository at this point in the history
  • Loading branch information
raix committed Nov 22, 2023
1 parent 165b5de commit 43a0bf9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public async Task CustomExceptionHandling_WhenThrowingException_ShouldHandleExce
builder.UseSetting(WebHostDefaults.EnvironmentKey, environment);
builder.ConfigureAppConfiguration((_, _) =>
{
// Set the environment variable to enable the test-specific /throwException endpoint.
// Set the environment variable to enable the test-specific /api/throwException endpoint.
Environment.SetEnvironmentVariable("TestEndpointsEnabled", "true");
});
}).CreateClient();

// Act
var response = await client.GetAsync("/throwException");
var response = await client.GetAsync("/api/throwException");

// Assert
if (environment == "Development")
Expand Down
2 changes: 1 addition & 1 deletion application/shared-kernel/ApiCore/ApiCoreConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static WebApplication AddApiCoreConfiguration<TDbContext>(this WebApplica

app.UseMiddleware<ModelBindingExceptionHandlerMiddleware>();

// Add test-specific endpoints when running tests, such as /throwException.
// Add test-specific endpoints when running tests, such as /api/throwException.
app.MapTestEndpoints();

app.Services.ApplyMigrations<TDbContext>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public static void MapTestEndpoints(this IEndpointRouteBuilder routes)
if (!bool.TryParse(Environment.GetEnvironmentVariable("TestEndpointsEnabled"), out _)) return;

// Add a dummy endpoint that throws an InvalidOperationException for testing purposes.
routes.MapGet("/throwException", _ => throw new InvalidOperationException("Dummy endpoint for testing."));
routes.MapGet("/api/throwException", _ => throw new InvalidOperationException("Dummy endpoint for testing."));
}
}

0 comments on commit 43a0bf9

Please sign in to comment.