Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b3ea441

Browse files
committed
Address code review feedback for System.Environment tests.
1 parent c825f02 commit b3ea441

File tree

4 files changed

+38
-49
lines changed

4 files changed

+38
-49
lines changed

src/System.Runtime.Extensions/tests/System.Runtime.Extensions.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
</PropertyGroup>
1919
<ItemGroup>
2020
<Compile Include="System\Diagnostics\Stopwatch.cs" />
21-
<Compile Include="System\Environment.NewLine.cs" />
22-
<Compile Include="System\Environment.ProcessorCount.cs" />
23-
<Compile Include="System\Environment.StackTrace.cs" />
2421
<Compile Include="System\Runtime\Versioning\FrameworkName.cs" />
2522
<Compile Include="System\IO\Path.cs" />
2623
<Compile Include="System\IO\Path.Combine.cs" />
@@ -48,7 +45,11 @@
4845
<Compile Include="System\Convert.ToUInt64.cs" />
4946
<Compile Include="System\Environment.ExpandEnvironmentVariables.cs" />
5047
<Compile Include="System\Environment.GetEnvironmentVariable.cs" />
48+
<Compile Include="System\Environment.NewLine.cs" />
49+
<Compile Include="System\Environment.ProcessorCount.cs" />
5150
<Compile Include="System\Environment.SetEnvironmentVariable.cs" />
51+
<Compile Include="System\Environment.StackTrace.cs" />
52+
<Compile Include="System\Environment.TickCount.cs" />
5253
<Compile Include="System\Math.cs" />
5354
<Compile Include="System\Progress.cs" />
5455
<Compile Include="System\Random.cs" />
@@ -59,7 +60,6 @@
5960
</ItemGroup>
6061
<ItemGroup>
6162
<None Include="project.json" />
62-
<Compile Include="System\Environment.TickCount.cs" />
6363
</ItemGroup>
6464
<ItemGroup>
6565
<ProjectReference Include="..\src\System.Runtime.Extensions.CoreCLR.csproj">

src/System.Runtime.Extensions/tests/System/Environment.NewLine.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@ namespace System.Runtime.Extensions.Tests
99
{
1010
public class EnvironmentNewLine
1111
{
12+
[PlatformSpecific(PlatformID.Windows)]
1213
[Fact]
13-
public void NewLineTest()
14+
public void Windows_NewLineTest()
1415
{
15-
//arrange
16-
string expectedNewLine = Interop.IsWindows ? "\r\n" : "\n";
17-
18-
//act
19-
string actualNewLine = Environment.NewLine;
16+
Assert.Equal("\r\n", Environment.NewLine);
17+
}
2018

21-
//assert
22-
Assert.Equal(expectedNewLine, actualNewLine);
19+
[PlatformSpecific(PlatformID.AnyUnix)]
20+
[Fact]
21+
public void Unix_NewLineTest()
22+
{
23+
Assert.Equal("\n", Environment.NewLine);
2324
}
2425
}
25-
26-
27-
28-
2926
}

src/System.Runtime.Extensions/tests/System/Environment.ProcessorCount.cs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,30 @@ namespace System.Runtime.Extensions.Tests
99
{
1010
public class EnvironmentProcessorCount
1111
{
12+
[PlatformSpecific(PlatformID.Windows)]
1213
[Fact]
13-
public void ProcessorCountTest()
14+
public void Windows_ProcessorCountTest()
1415
{
1516
//arrange
16-
int expected;
17+
SYSTEM_INFO sysInfo = new SYSTEM_INFO();
18+
GetSystemInfo(ref sysInfo);
19+
int expected = sysInfo.dwNumberOfProcessors;
1720

18-
if(Interop.IsWindows)
19-
{
20-
SYSTEM_INFO sysInfo = new SYSTEM_INFO();
21-
SYSTEM_INFO.GetSystemInfo(ref sysInfo);
22-
expected = sysInfo.dwNumberOfProcessors;
23-
}
24-
else
25-
{
26-
int _SC_NPROCESSORS_ONLN = Interop.IsOSX ? 58 : 84;
27-
expected = (int)sysconf(_SC_NPROCESSORS_ONLN);
28-
}
21+
//act
22+
int actual = Environment.ProcessorCount;
23+
24+
//assert
25+
Assert.True(actual > 0);
26+
Assert.Equal(expected, actual);
27+
}
28+
29+
[PlatformSpecific(PlatformID.AnyUnix)]
30+
[Fact]
31+
public void Unix_ProcessorCountTest()
32+
{
33+
//arrange
34+
int _SC_NPROCESSORS_ONLN = Interop.IsOSX || Interop.IsFreeBSD ? 58 : 84;
35+
int expected = (int)sysconf(_SC_NPROCESSORS_ONLN);
2936

3037
//act
3138
int actual = Environment.ProcessorCount;
@@ -38,6 +45,9 @@ public void ProcessorCountTest()
3845
[DllImport("libc")]
3946
private static extern long sysconf(int name);
4047

48+
[DllImport("api-ms-win-core-sysinfo-l1-1-0.dll", SetLastError = true)]
49+
internal static extern void GetSystemInfo(ref SYSTEM_INFO lpSystemInfo);
50+
4151
[StructLayout(LayoutKind.Sequential)]
4252
internal struct SYSTEM_INFO
4353
{
@@ -51,14 +61,6 @@ internal struct SYSTEM_INFO
5161
internal int dwAllocationGranularity;
5262
internal short wProcessorLevel;
5363
internal short wProcessorRevision;
54-
[DllImport("api-ms-win-core-sysinfo-l1-1-0.dll", SetLastError = true)]
55-
internal static extern void GetSystemInfo(ref SYSTEM_INFO lpSystemInfo);
5664
}
57-
58-
5965
}
60-
61-
62-
63-
6466
}

src/System.Runtime.Extensions/tests/System/Environment.TickCount.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System;
55
using System.Runtime.InteropServices;
6-
using System.Threading.Tasks;
6+
using System.Threading;
77
using Xunit;
88

99
namespace System.Runtime.Extensions.Tests
@@ -13,18 +13,8 @@ public class EnvironmentTickCount
1313
[Fact]
1414
public void TickCountTest()
1515
{
16-
//arrange
17-
const int milliSeconds = 1000;
1816
int start = Environment.TickCount;
19-
20-
//act
21-
Task.Delay(milliSeconds).Wait();
22-
int end = Environment.TickCount;
23-
24-
//assert
25-
Console.WriteLine("Start - " + start);
26-
Console.WriteLine("End - " + end);
27-
Assert.True(end - start >= milliSeconds);
17+
Assert.True(SpinWait.SpinUntil(() => Environment.TickCount > start, TimeSpan.FromSeconds(1)));
2818
}
2919
}
3020
}

0 commit comments

Comments
 (0)