name: csharp-expert-tests
skill: csharp-expert
version: 1.0.0
cases:
  - id: result-wait-deadlock
    description: Should reject .Result or .Wait() on async code and explain the deadlock risk
    prompt: I have an async method but the calling method is synchronous, so I'm using .Result to get the value. Is that okay?
    expected:
      contains_any:
        - deadlock
        - ".Result"
        - ".Wait()"
        - async all the way
        - synchronization context
        - async Task
      not_contains:
        - .Result is fine
      min_length: 80
    tags: [core, async]

  - id: nullable-reference-types
    description: Should recommend enabling nullable reference types project-wide
    prompt: I keep getting NullReferenceException at runtime in my .NET application. How can I catch these at compile time?
    expected:
      contains_any:
        - "<Nullable>enable</Nullable>"
        - Nullable
        - nullable reference types
        - compile time
        - NullReferenceException
        - "?"
      min_length: 80
    tags: [core, null-safety]

  - id: records-for-data
    description: Should recommend records for immutable data types instead of mutable classes
    prompt: I'm creating a C# class for a command object that just carries data from the API to my service layer. Should it be a regular class?
    expected:
      contains_any:
        - record
        - immutable
        - value equality
        - "with"
        - positional
        - data carrier
      min_length: 80
    tags: [core, types]

  - id: service-locator-antipattern
    description: Should reject service locator pattern in business logic
    prompt: Inside my service class I'm calling IServiceProvider.GetRequiredService to get dependencies when I need them. Is this acceptable?
    expected:
      contains_any:
        - service locator
        - constructor injection
        - anti-pattern
        - hidden dependency
        - testability
        - composition root
      min_length: 80
    tags: [core, di]

  - id: cancellation-token
    description: Should recommend threading CancellationToken through all async methods
    prompt: Should I add a CancellationToken parameter to my async service methods? It seems like extra overhead.
    expected:
      contains_any:
        - CancellationToken
        - cancellation
        - timeout
        - HTTP request
        - thread through
        - propagate
        - last parameter
      min_length: 80
    tags: [core, async]

  - id: async-void
    description: Should reject async void except for event handlers
    prompt: I made a method async void because I don't need to await it. The caller just fires and forgets. Is this okay?
    expected:
      contains_any:
        - async void
        - exception
        - unobservable
        - crash
        - async Task
        - event handler
      min_length: 80
    tags: [core, async]

  - id: coding-easy-retry-policy
    description: "Coding challenge (easy): Write a generic retry method with exponential backoff"
    prompt: "Write a C# static method RetryAsync<T> that takes a Func<Task<T>>, max retry count, and initial delay. It should retry the operation on exception with exponential backoff, accept a CancellationToken, and log each retry attempt. Use modern C# patterns."
    expected:
      contains_any:
        - async
        - await
        - Task
        - retry
        - delay
        - CancellationToken
      contains:
        - static
      not_contains:
        - "I can't write"
      min_length: 100
    tags:
      - coding-easy

  - id: coding-medium-channel-pipeline
    description: "Coding challenge (medium): Implement an async pipeline using System.Threading.Channels"
    prompt: "Write a C# pipeline framework using System.Threading.Channels where you chain processing stages. Each stage reads from an input Channel<T>, transforms items, and writes to an output Channel<T>. Support configurable bounded capacity per stage (backpressure), cancellation via CancellationToken, and error propagation that completes downstream channels."
    expected:
      contains_any:
        - Channel
        - BoundedChannelOptions
        - ReadAsync
        - WriteAsync
        - CancellationToken
        - Complete
      contains:
        - class
        - async
      min_length: 200
    tags:
      - coding-medium

  - id: coding-hard-middleware-chain
    description: "Coding challenge (hard): Implement a composable middleware pipeline like ASP.NET Core"
    prompt: "Write a C# middleware pipeline system similar to ASP.NET Core's. Define a Context class, a middleware delegate type, and a PipelineBuilder that lets you Use() middleware functions and Build() the pipeline. Middleware should be able to short-circuit (stop the chain), modify the context, and run logic both before and after the next middleware. Support dependency injection for middleware classes."
    expected:
      contains_any:
        - delegate
        - Func
        - next
        - middleware
        - Build
        - IServiceProvider
      contains:
        - class
      min_length: 300
    tags:
      - coding-hard
