Skip to content

Commit bbacf11

Browse files
authored
Merge pull request #312 from Umplify/copilot/fix-311
Add comprehensive GitHub Copilot instructions for development workflow
2 parents a946196 + 221f404 commit bbacf11

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed

.github/copilot-instructions.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Xunit Dependency Injection Library for .NET 9.0
2+
3+
Xunit Dependency Injection is a .NET library that brings Microsoft's dependency injection container to Xunit by leveraging Xunit's fixture pattern. This library enables dependency injection in xUnit tests using familiar Microsoft.Extensions.DependencyInjection patterns.
4+
5+
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
6+
7+
## Working Effectively
8+
9+
### Prerequisites and Installation
10+
- **CRITICAL**: This project requires .NET 9.0 SDK (version 9.0.304 or later) and .NET 9.0 runtime (version 9.0.8 or later).
11+
- Install .NET 9.0 SDK:
12+
```bash
13+
# Download the install script
14+
curl -sSL -o dotnet-install.sh https://dot.net/v1/dotnet-install.sh
15+
# Download the official SHA-256 checksum (replace URL with actual checksum file if available)
16+
curl -sSL -o dotnet-install.sh.sha256 https://dot.net/v1/dotnet-install.sh.sha256
17+
# Verify checksum
18+
sha256sum -c dotnet-install.sh.sha256
19+
# If verification passes, install .NET SDK
20+
bash dotnet-install.sh --version 9.0.304 --install-dir /tmp/dotnet
21+
export PATH="/tmp/dotnet:$PATH"
22+
export DOTNET_ROOT="/tmp/dotnet"
23+
```
24+
- Verify installation: `dotnet --version` should return `9.0.304` or later
25+
- Verify runtime: `dotnet --list-runtimes` should show `Microsoft.NETCore.App 9.0.8`
26+
27+
### Build and Test Commands
28+
- **Navigate to source directory**: `cd /path/to/xunit-dependency-injection/src`
29+
- **Restore packages**: `dotnet restore` -- takes ~8 seconds. NEVER CANCEL. Set timeout to 30+ seconds.
30+
- **Build library**: `dotnet build --configuration Release` -- takes ~5.5 seconds. NEVER CANCEL. Set timeout to 30+ seconds.
31+
- **Build examples**: The build command automatically builds both the main library and example tests.
32+
- **Run example tests**:
33+
```bash
34+
cd ../examples/Xunit.Microsoft.DependencyInjection.ExampleTests
35+
dotnet test --configuration Release
36+
```
37+
-- takes ~10.8 seconds with 9 tests passing. NEVER CANCEL. Set timeout to 60+ seconds.
38+
- **Package library**: `dotnet pack --configuration Release` -- takes ~1.9 seconds. NEVER CANCEL. Set timeout to 30+ seconds.
39+
40+
### Code Quality and Formatting
41+
- **Format code**: `dotnet format Xunit.Microsoft.DependencyInjection.sln` -- fixes whitespace and code style issues per .editorconfig
42+
- **Verify formatting**: `dotnet format Xunit.Microsoft.DependencyInjection.sln --verify-no-changes --verbosity diagnostic`
43+
- **ALWAYS** run `dotnet format` before committing changes to maintain code style consistency
44+
- The project uses .editorconfig with specific C# coding standards including tabs for indentation and CRLF line endings
45+
46+
### Development Workflow
47+
- Always set `PATH="/tmp/dotnet:$PATH"` and `DOTNET_ROOT="/tmp/dotnet"` in your session when working with .NET 9.0
48+
- Test your changes by running the example tests which demonstrate real usage scenarios
49+
- The library targets `net9.0` framework exclusively
50+
- Use Visual Studio Code tasks defined in `.vscode/tasks.json` for build, publish, and watch operations
51+
52+
## Validation Scenarios
53+
54+
After making any changes to the library code:
55+
1. **Build validation**: Run `dotnet build --configuration Release` and ensure it completes successfully
56+
2. **Test validation**: Run example tests with `dotnet test --configuration Release` and verify all 9 tests pass
57+
3. **Format validation**: Run `dotnet format` to ensure code follows project standards
58+
4. **Package validation**: Run `dotnet pack --configuration Release` to ensure the library can be packaged
59+
60+
### Manual Testing Scenarios
61+
The example tests demonstrate complete usage patterns:
62+
- **Dependency injection setup**: Tests show how to configure services in `TestProjectFixture`
63+
- **Service resolution**: Tests verify both scoped and singleton service resolution
64+
- **Keyed services**: Tests validate keyed service injection (new in .NET 9.0)
65+
- **Configuration binding**: Tests demonstrate configuration file and user secrets integration
66+
- **Test ordering**: Tests show the test ordering feature with `TestOrder` attributes
67+
68+
## Project Structure
69+
70+
### Key Directories and Files
71+
- `/src/` - Main library source code
72+
- `Abstracts/TestBedFixture.cs` - Base class for test fixtures
73+
- `Abstracts/TestBed.cs` - Base class for test classes
74+
- `TestsOrder/TestPriorityOrderer.cs` - Test ordering implementation
75+
- `.editorconfig` - Code style configuration
76+
- `/examples/Xunit.Microsoft.DependencyInjection.ExampleTests/` - Working examples and integration tests
77+
- `Fixtures/TestProjectFixture.cs` - Example fixture setup
78+
- Various test files demonstrating usage patterns
79+
- `.github/workflows/` - CI/CD automation (Azure Pipelines used, not GitHub Actions)
80+
- `.vscode/` - VS Code configuration for development
81+
82+
### Important Configuration Files
83+
- `src/Xunit.Microsoft.DependencyInjection.csproj` - Main project file targeting net9.0
84+
- `azure-pipelines.yml` - Build automation configuration
85+
- `examples/*/Xunit.Microsoft.DependencyInjection.ExampleTests.csproj` - Example test project
86+
87+
## Common Development Tasks
88+
89+
### Adding New Features
90+
1. Modify source code in `/src/` directory
91+
2. Add corresponding tests in `/examples/` directory
92+
3. Run build and test validation
93+
4. Format code with `dotnet format`
94+
5. Verify all example tests still pass
95+
96+
### Troubleshooting Build Issues
97+
- **SDK Version Error**: Ensure .NET 9.0 SDK is installed and in PATH
98+
- **Runtime Error during Tests**: Ensure .NET 9.0 runtime is installed and DOTNET_ROOT is set
99+
- **Format Issues**: Run `dotnet format` to auto-fix most style problems
100+
- **Missing Dependencies**: Run `dotnet restore` to restore NuGet packages
101+
102+
### Working with Examples
103+
The examples project is a fully functional test suite that demonstrates:
104+
- Service registration and dependency injection patterns
105+
- Configuration file usage with `appsettings.json`
106+
- User secrets integration for sensitive data
107+
- Keyed services (Porsche/Toyota car maker examples)
108+
- Test ordering with custom attributes
109+
- Both synchronous and asynchronous test patterns
110+
111+
Always use the examples to validate that your changes don't break real-world usage scenarios.
112+
113+
## Build Times and Performance Expectations
114+
- **Package restore**: ~1-8 seconds (varies with cache state)
115+
- **Build (Release)**: ~4-6 seconds
116+
- **Test execution**: ~9-11 seconds (9 tests pass)
117+
- **Code formatting**: ~7-10 seconds
118+
- **Package creation**: ~1-2 seconds
119+
- **Complete workflow**: ~20-25 seconds total
120+
121+
**CRITICAL**: NEVER CANCEL builds or tests. These times are normal. Set timeouts to 2-5 minutes to catch actual hanging processes, but actual operations complete much faster.
122+
123+
## Azure DevOps Integration
124+
The project uses Azure Pipelines (not GitHub Actions) for CI/CD:
125+
- Build configuration in `azure-pipelines.yml`
126+
- Targets Ubuntu 22.04 build agents
127+
- Uses .NET 9.0.304 SDK version
128+
- Publishes to NuGet.org on successful builds
129+
- Example tests are run as part of the pipeline
130+
131+
## Frequently Used Commands Summary
132+
```bash
133+
# Setup environment
134+
export PATH="/tmp/dotnet:$PATH"
135+
export DOTNET_ROOT="/tmp/dotnet"
136+
137+
# Build and test workflow
138+
cd src
139+
dotnet restore # ~8s
140+
dotnet build --configuration Release # ~5.5s
141+
cd ../examples/Xunit.Microsoft.DependencyInjection.ExampleTests
142+
dotnet test --configuration Release # ~10.8s
143+
144+
# Code quality
145+
cd ../../src
146+
dotnet format Xunit.Microsoft.DependencyInjection.sln
147+
148+
# Package
149+
dotnet pack --configuration Release # ~1.9s
150+
```
151+
152+
Always validate your changes by running through this complete workflow before committing.

0 commit comments

Comments
 (0)