-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathEnvironment.UserName.cs
49 lines (44 loc) · 1.46 KB
/
Environment.UserName.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Xunit;
namespace System.Tests
{
public class EnvironmentUserName
{
[Fact]
public void UserNameIsCorrect()
{
if (PlatformDetection.IsInAppContainer)
{
Assert.Equal("Windows User", Environment.UserName);
}
else
{
// Highly unlikely anyone is using user with this name
Assert.NotEqual("Windows User", Environment.UserName);
}
}
[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "Not valid on iOS or tvOS")]
public void UserName_Valid()
{
string name = Environment.UserName;
Assert.False(string.IsNullOrWhiteSpace(name));
Assert.Equal(-1, name.IndexOf('\0'));
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
public void UserName_MatchesEnvironment_Windows()
{
Assert.Equal(Environment.GetEnvironmentVariable("USERNAME"), Environment.UserName);
}
[Fact]
[PlatformSpecific(TestPlatforms.Browser)]
public void UserName_MatchesEnvironment_Browser()
{
string name = Environment.UserName;
Assert.False(string.IsNullOrWhiteSpace(name));
Assert.Equal("Browser", name);
}
}
}