test: MSTEST0061 — add edge case tests for OSPlatform.Create and mobile OS platforms - #9818
Conversation
…le OS platforms
Add four tests covering previously untested code paths in
UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzer:
1. WhenOSPlatformCreateWithKnownPlatform_Diagnostic - exercises the
OSPlatform.Create("Windows") branch in TryGetOSPlatformFromIsOSPlatformCall.
The fixer maps "Windows" to OperatingSystems.Windows and applies the fix.
2. WhenOSPlatformCreateWithUnknownPlatform_Diagnostic - same OSPlatform.Create()
branch with a custom platform name ("CustomOS") that has no OperatingSystems
enum mapping; the analyzer fires but the fixer produces no change.
3. WhenOperatingSystemIsIOS_Diagnostic - OperatingSystem.IsIOS() maps to "iOS",
which has no OperatingSystems enum value; analyzer fires, fixer has no fix.
4. WhenOperatingSystemIsAndroid_Diagnostic - same as above for IsAndroid().
Fixes #9808
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds MSTEST0061 edge-case coverage for OSPlatform.Create and unsupported mobile platforms.
Changes:
- Tests known and custom
OSPlatform.Createvalues. - Tests iOS and Android diagnostics.
- Validates the supported Windows code fix.
Show a summary per file
| File | Description |
|---|---|
UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzerTests.cs |
Adds four analyzer and fixer edge-case tests. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 3
- Review effort level: Medium
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
Review Summary
All 22 dimensions reviewed — no findings.
| Dimension | Verdict |
|---|---|
| 1. Algorithmic Correctness | ✅ N/A — test-only change |
| 2. Error Handling | ✅ N/A |
| 3. Concurrency / Thread Safety | ✅ N/A |
| 4. Performance | ✅ N/A |
| 5. Security | ✅ N/A |
| 6. Public API Surface | ✅ N/A — no public API changes |
| 7. Backward Compatibility | ✅ N/A |
| 8. Cross-TFM Correctness | ✅ N/A |
| 9. Localization | ✅ N/A |
| 10. Naming & Conventions | ✅ Clean — test names follow existing patterns |
| 11. Code Style | ✅ Clean — consistent with adjacent tests |
| 12. Documentation / Comments | ✅ Clean — each test has a clear comment explaining the code path exercised |
| 13. Test Quality | ✅ Clean — tests cover distinct code paths (Create branch, unknown platform, mobile OS methods) |
| 14. Test Assertion Conventions | ✅ Clean — uses VerifyCS.VerifyCodeFixAsync / VerifyAnalyzerAsync per project conventions |
| 15. Scope Discipline | ✅ Clean — single concern (edge-case test coverage) |
| 16. Duplication | ✅ Clean — no unnecessary repetition beyond the structural boilerplate inherent to Roslyn verifier tests |
| 17. Disposal & Lifetime | ✅ N/A |
| 18. Configuration | ✅ N/A |
| 19. Logging & Diagnostics | ✅ N/A |
| 20. IPC / Wire Compat | ✅ N/A |
| 21. Build Infrastructure | ✅ N/A |
| 22. TODO Policy | ✅ N/A — no TODOs |
Verdict: All clear. Four well-targeted tests covering previously untested analyzer branches. No issues found.
This comment has been minimized.
This comment has been minimized.
Review feedback pointed out that the three unsupported-platform tests used VerifyAnalyzerAsync, which never invokes the code-fix provider and would not catch a regression that corrupted the code. Rather than leaving the fixer registering a no-op code action for platforms that have no OperatingSystems enum value (the "known limitation" noted in the issue), suppress the code action entirely: move the OperatingSystems mapping check up to RegisterCodeFixesAsync so no fix is offered when the platform is unmappable. This is the improvement the issue flagged as future work. The three tests now use VerifyCodeFixAsync(code, code), which exercises the code-fix provider and asserts no fix is offered (0 iterations), consistent with the rest of the suite. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
🧪 Test quality grade — PR #9818
This advisory comment was generated automatically. Grades are heuristic
|
Summary
Adds four tests covering previously untested code paths in
UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzer(MSTEST0061).The analyzer has two distinct code paths for extracting the OS platform name from
RuntimeInformation.IsOSPlatform()calls:OSPlatform.Windows,OSPlatform.Linux, etc. — already testedOSPlatform.Create()path:OSPlatform.Create("Windows")— not previously testedAdditionally,
OperatingSystem.Is*()methods for mobile/embedded platforms (iOS, Android) were not tested. These map to platform names that have no correspondingOperatingSystemsenum value, so the analyzer fires but the fixer cannot produce a code fix.Tests added
WhenOSPlatformCreateWithKnownPlatform_DiagnosticOSPlatform.Create("Windows")→TryGetOSPlatformFromIsOSPlatformCallCreate branch[OSCondition(OperatingSystems.Windows)]WhenOSPlatformCreateWithUnknownPlatform_DiagnosticOSPlatform.Create("CustomOS")→ Create branch, noOperatingSystemsmappingWhenOperatingSystemIsIOS_DiagnosticOperatingSystem.IsIOS()→ maps to"iOS", noOperatingSystems.iOSWhenOperatingSystemIsAndroid_DiagnosticOperatingSystem.IsAndroid()→ maps to"Android", noOperatingSystems.AndroidThe unknown-platform and mobile-platform tests confirm that the fixer silently does nothing for unsupported platforms — a known limitation documented in the issue.
Test status
All 27 tests in
UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzerTestspass locally:Fixes #9808