Skip to content

Commit f419bfc

Browse files
Copilotnkolev92
andcommitted
Enhance RuntimeEnvironmentHelper tests with exception safety verification
Co-authored-by: nkolev92 <[email protected]>
1 parent f77957c commit f419bfc

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

test/NuGet.Core.Tests/NuGet.Common.Test/RuntimeEnvironmentHelperTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public void PlatformDetection_ShouldBeExclusive()
5252
// Assert - Only one platform should be true
5353
var trueCount = (isWindows ? 1 : 0) + (isMacOS ? 1 : 0) + (isLinux ? 1 : 0);
5454
Assert.True(trueCount <= 1, $"Multiple platforms detected as true: Windows={isWindows}, macOS={isMacOS}, Linux={isLinux}");
55+
56+
// At least one should be detected (we're running on some platform)
57+
Assert.True(trueCount >= 1, $"No platform detected as true: Windows={isWindows}, macOS={isMacOS}, Linux={isLinux}");
5558
}
5659

5760
[PlatformFact(Platform.Windows)]
@@ -123,5 +126,22 @@ public void IsMacOSX_OnLinux_ShouldReturnFalse()
123126
// Assert
124127
Assert.False(result);
125128
}
129+
130+
[Fact]
131+
public void IsMacOSX_ShouldNotThrowException()
132+
{
133+
// Arrange & Act & Assert
134+
// This test specifically verifies that no first-chance exception is thrown
135+
// when calling IsMacOSX on any platform, especially Windows
136+
var exception = Record.Exception(() =>
137+
{
138+
var result = RuntimeEnvironmentHelper.IsMacOSX;
139+
// Multiple calls to ensure consistency and no exceptions on repeated access
140+
var result2 = RuntimeEnvironmentHelper.IsMacOSX;
141+
Assert.Equal(result, result2);
142+
});
143+
144+
Assert.Null(exception);
145+
}
126146
}
127147
}

0 commit comments

Comments
 (0)