Skip to content

Commit aaa9f09

Browse files
CopilotArash-Sabet
andcommitted
Complete comprehensive GitHub Copilot instructions with validated commands and enhanced scenarios
Co-authored-by: Arash-Sabet <26050123+Arash-Sabet@users.noreply.github.com>
1 parent 2bb4481 commit aaa9f09

File tree

1 file changed

+87
-10
lines changed

1 file changed

+87
-10
lines changed

.github/copilot-instructions.md

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Always reference these instructions first and fallback to search or bash command
3434
cd ../examples/Xunit.Microsoft.DependencyInjection.ExampleTests
3535
dotnet test --configuration Release
3636
```
37-
-- takes ~10.8 seconds with 9 tests passing. NEVER CANCEL. Set timeout to 60+ seconds.
37+
-- takes ~10.8 seconds with 43 tests passing. NEVER CANCEL. Set timeout to 60+ seconds.
3838
- **Package library**: `dotnet pack --configuration Release` -- takes ~1.9 seconds. NEVER CANCEL. Set timeout to 30+ seconds.
3939

4040
### Code Quality and Formatting
@@ -49,11 +49,59 @@ Always reference these instructions first and fallback to search or bash command
4949
- The library targets `net9.0` framework exclusively
5050
- Use Visual Studio Code tasks defined in `.vscode/tasks.json` for build, publish, and watch operations
5151

52+
## Understanding Test Patterns
53+
54+
The library supports multiple dependency injection approaches:
55+
56+
### 1. Traditional Fixture-Based (Fully Supported)
57+
```csharp
58+
public class MyTests : TestBed<TestProjectFixture>
59+
{
60+
[Fact]
61+
public async Task TestCalculation()
62+
{
63+
var calculator = _fixture.GetService<ICalculator>(_testOutputHelper);
64+
var result = await calculator.AddAsync(1, 2);
65+
Assert.Equal(3, result);
66+
}
67+
}
68+
```
69+
70+
### 2. Property Injection (Recommended - New in 9.2.0+)
71+
```csharp
72+
public class MyTests : TestBedWithDI<TestProjectFixture>
73+
{
74+
[Inject] private ICalculator Calculator { get; set; } = null!;
75+
[Inject("Porsche")] private ICarMaker PorscheMaker { get; set; } = null!;
76+
77+
[Fact]
78+
public async Task TestCalculation()
79+
{
80+
var result = await Calculator.AddAsync(1, 2);
81+
Assert.Equal(3, result);
82+
}
83+
}
84+
```
85+
86+
### 3. Factory Pattern (Experimental)
87+
```csharp
88+
public class MyTests : TestBed<FactoryTestProjectFixture>
89+
{
90+
[Fact]
91+
public async Task TestConstructorInjection()
92+
{
93+
var service = _fixture.CreateTestInstance<SimpleService>(_testOutputHelper);
94+
var result = await service.CalculateAsync(10, 5);
95+
Assert.True(result > 0);
96+
}
97+
}
98+
```
99+
52100
## Validation Scenarios
53101

54102
After making any changes to the library code:
55103
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
104+
2. **Test validation**: Run example tests with `dotnet test --configuration Release` and verify all 43 tests pass
57105
3. **Format validation**: Run `dotnet format` to ensure code follows project standards
58106
4. **Package validation**: Run `dotnet pack --configuration Release` to ensure the library can be packaged
59107

@@ -65,6 +113,25 @@ The example tests demonstrate complete usage patterns:
65113
- **Configuration binding**: Tests demonstrate configuration file and user secrets integration
66114
- **Test ordering**: Tests show the test ordering feature with `TestOrder` attributes
67115

116+
#### Testing Specific Features
117+
Run individual test scenarios to validate changes:
118+
```bash
119+
# Test property injection (new dependency injection pattern)
120+
dotnet test --filter "TestCalculatorThroughPropertyInjection" --configuration Release
121+
122+
# Test keyed services (Porsche/Toyota car makers)
123+
dotnet test --filter "GetKeyedService" --configuration Release
124+
125+
# Test factory pattern (constructor injection)
126+
dotnet test --filter "TestConstructorInjectionViaFactory" --configuration Release
127+
128+
# Test configuration and user secrets
129+
dotnet test --filter "TestSecretValues" --configuration Release
130+
131+
# List all available tests
132+
dotnet test --list-tests --configuration Release
133+
```
134+
68135
## Project Structure
69136

70137
### Key Directories and Files
@@ -99,24 +166,34 @@ The example tests demonstrate complete usage patterns:
99166
- **Format Issues**: Run `dotnet format` to auto-fix most style problems
100167
- **Missing Dependencies**: Run `dotnet restore` to restore NuGet packages
101168

169+
#### Common Validation Failures
170+
- **Build succeeds but tests fail**: Check if you're in the correct directory (`examples/Xunit.Microsoft.DependencyInjection.ExampleTests`)
171+
- **"No tests found" error**: Verify test filter syntax with `dotnet test --list-tests` first
172+
- **Timeout during restore/build**: DO NOT CANCEL - operations take 8-15 seconds normally, set 60+ second timeouts
173+
- **SourceLink warnings**: These are normal during format validation and can be ignored
174+
- **Test count mismatch**: Current test suite has 43 tests; if you see different counts, investigate test changes
175+
102176
### Working with Examples
103177
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
178+
- **Traditional fixture-based approach**: See `CalculatorTests.cs` using `TestBed<TFixture>` and `_fixture.GetService<T>(_testOutputHelper)`
179+
- **Property injection approach**: See `PropertyInjectionTests.cs` using `TestBedWithDI<TFixture>` with `[Inject]` attributes
180+
- **Factory constructor injection**: See `FactoryConstructorInjectionTests.cs` for experimental true constructor injection
181+
- **Service registration patterns**: Multiple service lifetimes (transient, scoped, singleton)
182+
- **Configuration file usage**: `appsettings.json` integration
183+
- **User secrets integration**: Sensitive data handling for development
184+
- **Keyed services**: Porsche/Toyota car maker examples demonstrating .NET 9.0 keyed services
185+
- **Test ordering**: Custom attributes for controlling test execution order
186+
- **Advanced patterns**: `Func<T>`, `Action<T>`, and `IOptions<T>` injection patterns
110187

111188
Always use the examples to validate that your changes don't break real-world usage scenarios.
112189

113190
## Build Times and Performance Expectations
114191
- **Package restore**: ~1-8 seconds (varies with cache state)
115192
- **Build (Release)**: ~4-6 seconds
116-
- **Test execution**: ~9-11 seconds (9 tests pass)
193+
- **Test execution**: ~9-11 seconds (43 tests pass)
117194
- **Code formatting**: ~7-10 seconds
118195
- **Package creation**: ~1-2 seconds
119-
- **Complete workflow**: ~20-25 seconds total
196+
- **Complete workflow**: ~25-35 seconds total
120197

121198
**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.
122199

0 commit comments

Comments
 (0)