mirror of
https://github.com/dotnet/skills.git
synced 2026-09-20 09:49:54 +08:00
2d163bb600
* Initial plan * Rename dotnet-aspnet plugin to dotnet-aspnetcore --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
136 lines
5.7 KiB
YAML
136 lines
5.7 KiB
YAML
scenarios:
|
|
- name: "Create a CRUD Web API with minimal APIs, OpenAPI, and proper HTTP semantics"
|
|
prompt: |
|
|
Create an ASP.NET Core Web API (.NET 10) project for managing products.
|
|
Each product has a name, price, category (an enum: Electronics, Clothing,
|
|
Food, Books), and a createdAt timestamp.
|
|
|
|
The API should have these endpoints:
|
|
- GET /api/products (list all)
|
|
- GET /api/products/{id} (get by ID)
|
|
- POST /api/products (create a product)
|
|
|
|
Use an in-memory service behind an interface for data storage.
|
|
Add OpenAPI documentation with rich metadata on each endpoint.
|
|
assertions:
|
|
- type: "output_matches"
|
|
pattern: "(MapGet|MapPost)"
|
|
- type: "output_matches"
|
|
pattern: "(TypedResults|Results<)"
|
|
- type: "output_matches"
|
|
pattern: "sealed"
|
|
- type: "output_contains"
|
|
value: "DateTimeOffset"
|
|
- type: "output_matches"
|
|
pattern: "/// <summary>"
|
|
- type: "output_contains"
|
|
value: "AddOpenApi"
|
|
- type: "output_contains"
|
|
value: "MapOpenApi"
|
|
- type: "output_matches"
|
|
pattern: "(WithName|WithSummary|WithDescription)"
|
|
- type: "output_not_contains"
|
|
value: "Swashbuckle"
|
|
- type: "output_not_matches"
|
|
pattern: "(UseSwagger|UseSwaggerUI)"
|
|
- type: "output_contains"
|
|
value: "JsonStringEnumConverter"
|
|
- type: "output_contains"
|
|
value: "CancellationToken"
|
|
rubric:
|
|
- "Uses minimal APIs (MapGet, MapPost, etc.) rather than controllers for new projects"
|
|
- "POST endpoint returns 201 Created with a Location header, not 200 OK"
|
|
- "Uses TypedResults with explicit Results<T1, T2> return types for compile-time type safety"
|
|
- "DTOs are sealed records, not mutable classes"
|
|
- "Uses a service layer with interfaces instead of injecting a data store directly into endpoints"
|
|
- "CancellationToken is accepted in endpoint signatures and forwarded through all async calls"
|
|
- "Date/time properties use DateTimeOffset, not DateTime"
|
|
- "All request and response DTOs include XML doc summary comments"
|
|
- "Enum properties serialize as strings by default using JsonStringEnumConverter"
|
|
- "Uses builder.Services.AddOpenApi() and app.MapOpenApi() (built-in .NET 9+ support)"
|
|
- "Does NOT add any Swashbuckle NuGet packages"
|
|
- "Chains .WithName(), .WithSummary(), and .WithDescription() on endpoints for OpenAPI metadata"
|
|
timeout: 600
|
|
|
|
- name: "Add error handling with ProblemDetails and IExceptionHandler"
|
|
prompt: |
|
|
I have an existing ASP.NET Core minimal API project. I need to add
|
|
global error handling so that:
|
|
- All error responses use RFC 7807 Problem Details format
|
|
- KeyNotFoundException maps to 404
|
|
- ArgumentException maps to 400
|
|
- InvalidOperationException maps to 409
|
|
- Unhandled exceptions return 500 with no sensitive details
|
|
|
|
Show me how to implement this without adding try-catch blocks in
|
|
every endpoint.
|
|
assertions:
|
|
- type: "output_contains"
|
|
value: "IExceptionHandler"
|
|
- type: "output_contains"
|
|
value: "ProblemDetails"
|
|
- type: "output_contains"
|
|
value: "AddProblemDetails"
|
|
- type: "output_contains"
|
|
value: "UseExceptionHandler"
|
|
rubric:
|
|
- "Implements IExceptionHandler (the modern .NET 8+ approach) rather than convention-based middleware"
|
|
- "Returns ProblemDetails for all error responses (RFC 7807)"
|
|
- "Maps exception types to appropriate HTTP status codes (404, 400, 409)"
|
|
- "Does not expose internal exception details in production error responses"
|
|
- "Registers the handler with AddExceptionHandler<T>() and AddProblemDetails()"
|
|
- "Exception handler class is sealed"
|
|
- "Exception handler is placed in a Middleware/ folder"
|
|
timeout: 600
|
|
|
|
- name: "Add a new API endpoint to an existing controller-based project"
|
|
prompt: |
|
|
I have an existing ASP.NET Core Web API that uses controllers. Here is
|
|
one of the existing controllers:
|
|
|
|
```csharp
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class CustomersController : ControllerBase
|
|
{
|
|
private readonly ICustomerService _service;
|
|
|
|
public CustomersController(ICustomerService service)
|
|
{
|
|
_service = service;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<ActionResult<List<CustomerResponse>>> GetAll()
|
|
{
|
|
return Ok(await _service.GetAllAsync());
|
|
}
|
|
}
|
|
```
|
|
|
|
Add a new OrdersController with a GET endpoint to list orders and a
|
|
POST endpoint to create an order. Each order has a customer ID, a
|
|
placedAt timestamp, a total amount, and an OrderStatus (Pending,
|
|
Processing, Shipped, Delivered, Cancelled).
|
|
assertions:
|
|
- type: "output_contains"
|
|
value: "ControllerBase"
|
|
- type: "output_contains"
|
|
value: "[ApiController]"
|
|
- type: "output_contains"
|
|
value: "CancellationToken"
|
|
- type: "output_not_matches"
|
|
pattern: "app\\.(MapGet|MapPost|MapPut|MapDelete|MapPatch)|\\b(MapGet|MapPost|MapPut|MapDelete|MapPatch)\\b"
|
|
- type: "output_contains"
|
|
value: "DateTimeOffset"
|
|
- type: "output_matches"
|
|
pattern: "/// <summary>"
|
|
rubric:
|
|
- "Continues with the controller pattern since the existing project uses controllers (does not mix minimal APIs)"
|
|
- "Includes CancellationToken in all endpoint signatures"
|
|
- "POST create returns CreatedAtAction with 201 status, not Ok with 200"
|
|
- "Uses sealed record DTOs with proper naming (CreateOrderRequest, OrderResponse)"
|
|
- "Date/time properties use DateTimeOffset, not DateTime"
|
|
- "All request and response DTOs include XML doc summary comments"
|
|
timeout: 600
|