|
| 1 | +# RootNamespace Test Sample |
| 2 | + |
| 3 | +This sample project demonstrates and validates that the source generator correctly respects the `RootNamespace` property in the .csproj file. |
| 4 | + |
| 5 | +## Purpose |
| 6 | + |
| 7 | +When a project sets `<RootNamespace>Popcorn.Toolkit</RootNamespace>` in its .csproj file, the generated `R` class should be placed in the `Popcorn.Toolkit` namespace rather than defaulting to the assembly name. |
| 8 | + |
| 9 | +## Project Configuration |
| 10 | + |
| 11 | +The project is configured with: |
| 12 | +- **AssemblyName**: RootNamespaceTest |
| 13 | +- **RootNamespace**: Popcorn.Toolkit |
| 14 | +- **Resources**: Contains sample.txt and config.json |
| 15 | + |
| 16 | +## Expected Behavior |
| 17 | + |
| 18 | +The source generator should: |
| 19 | +1. Read the `RootNamespace` property from MSBuild |
| 20 | +2. Generate the `R` class in the `Popcorn.Toolkit` namespace |
| 21 | +3. The Program.cs can access `R` class directly since it's in the same namespace |
| 22 | + |
| 23 | +## Running the Test |
| 24 | + |
| 25 | +```bash |
| 26 | +dotnet run --project samples/RootNamespaceTest/RootNamespaceTest.csproj |
| 27 | +``` |
| 28 | + |
| 29 | +Expected output: |
| 30 | +``` |
| 31 | +RootNamespace Test - Verifying generated R class namespace |
| 32 | +============================================================= |
| 33 | +
|
| 34 | +R class is accessible in namespace: Popcorn.Toolkit |
| 35 | +Expected namespace: Popcorn.Toolkit |
| 36 | +
|
| 37 | +Available resource keys: |
| 38 | + - R.Keys.sample: sample |
| 39 | + - R.Keys.config: config |
| 40 | +
|
| 41 | +Sample resource content: This is a sample resource file for testing RootNamespace property. |
| 42 | +Config resource content: { |
| 43 | + "message": "Hello from RootNamespace test!", |
| 44 | + "version": "1.0" |
| 45 | +} |
| 46 | +
|
| 47 | +✓ Test PASSED: R class is in the correct namespace (Popcorn.Toolkit) |
| 48 | +``` |
| 49 | + |
| 50 | +## Verification |
| 51 | + |
| 52 | +The test program: |
| 53 | +1. Accesses the `R` class without qualification (proving it's in `Popcorn.Toolkit`) |
| 54 | +2. Verifies the namespace using reflection |
| 55 | +3. Reads resources to ensure functionality works correctly |
0 commit comments