mirror of
https://github.com/dotnet/skills.git
synced 2026-09-20 09:49:54 +08:00
99 lines
3.8 KiB
YAML
99 lines
3.8 KiB
YAML
name: generate-testability-wrappers
|
|
description: Evaluates the dotnet-test/generate-testability-wrappers skill
|
|
type: capability
|
|
config:
|
|
timeout: 4m
|
|
stimuli:
|
|
- name: Generate TimeProvider adoption for DateTime.UtcNow
|
|
prompt: >
|
|
My ReportGenerator class uses DateTime.UtcNow and I can't write
|
|
deterministic unit tests for it. I'm on .NET 10. Can you create the
|
|
right abstraction so I can mock time in tests?
|
|
environment:
|
|
files:
|
|
- src: ./fixtures/needs-wrappers
|
|
dest: NeedsWrappers
|
|
graders:
|
|
- type: output-matches
|
|
config:
|
|
pattern: (TimeProvider|time provider)
|
|
- type: output-matches
|
|
config:
|
|
pattern: (FakeTimeProvider|fake.*time|mock.*time|test.*time)
|
|
- type: output-matches
|
|
config:
|
|
pattern: (AddSingleton|Register|services\.Add)
|
|
- type: exit-success
|
|
- type: prompt
|
|
rubric:
|
|
- Recommended TimeProvider as the built-in abstraction since the project targets .NET 10
|
|
- Showed how to register TimeProvider.System in the DI container
|
|
- Showed how to inject TimeProvider into the ReportGenerator class
|
|
- Showed how to use FakeTimeProvider in tests to pin time
|
|
- Mentioned the Microsoft.Extensions.TimeProvider.Testing NuGet package for testing
|
|
|
|
- name: Generate custom Environment wrapper
|
|
prompt: >
|
|
My code calls Environment.GetEnvironmentVariable and
|
|
Environment.MachineName directly. I need to make these testable. Can you
|
|
generate a wrapper interface and implementation I can inject?
|
|
environment:
|
|
files:
|
|
- src: ./fixtures/needs-wrappers
|
|
dest: NeedsWrappers
|
|
graders:
|
|
- type: output-matches
|
|
config:
|
|
pattern: (interface|IEnvironment)
|
|
- type: output-matches
|
|
config:
|
|
pattern: (GetEnvironmentVariable|MachineName)
|
|
- type: exit-success
|
|
- type: prompt
|
|
rubric:
|
|
- Generated an interface with methods for GetEnvironmentVariable and MachineName
|
|
- Generated a default implementation that delegates to the real Environment static class
|
|
- Provided DI registration code for the wrapper
|
|
- Only wrapped the two members actually used in the code, not every Environment member
|
|
|
|
- name: Recommend System.IO.Abstractions for file system calls
|
|
prompt: >
|
|
I've got File.WriteAllText, File.ReadAllText, and Directory.Exists
|
|
scattered across my project. What's the best way to make these testable?
|
|
environment:
|
|
files:
|
|
- src: ./fixtures/needs-wrappers
|
|
dest: NeedsWrappers
|
|
graders:
|
|
- type: output-matches
|
|
config:
|
|
pattern: (System\.IO\.Abstractions|IFileSystem)
|
|
- type: output-matches
|
|
config:
|
|
pattern: (MockFileSystem|mock.*file)
|
|
- type: exit-success
|
|
- type: prompt
|
|
rubric:
|
|
- Recommended System.IO.Abstractions NuGet package instead of writing a custom wrapper
|
|
- Showed how to register IFileSystem in DI
|
|
- Showed how to use MockFileSystem in tests
|
|
- Did not generate a custom file system wrapper when the established package exists
|
|
|
|
- name: Decline wrapper generation for already-abstracted code
|
|
prompt: >
|
|
My code already uses IFileSystem from System.IO.Abstractions everywhere.
|
|
Can you generate a file system wrapper for me?
|
|
environment:
|
|
files:
|
|
- src: ./fixtures/decline-already-abstracted/DataService.cs
|
|
dest: Services/DataService.cs
|
|
graders:
|
|
- type: output-matches
|
|
config:
|
|
pattern: (already|exists|abstracted|no need|unnecessary)
|
|
- type: prompt
|
|
rubric:
|
|
- Recognized that IFileSystem is already in use and no wrapper generation is needed
|
|
- Did not generate a redundant wrapper interface
|
|
- May have suggested other improvements but did not create duplicate abstractions
|