forked from NuGet/NuGet.Client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironmentVariableWrapperTests.cs
More file actions
63 lines (48 loc) · 2.02 KB
/
EnvironmentVariableWrapperTests.cs
File metadata and controls
63 lines (48 loc) · 2.02 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Xunit;
namespace NuGet.Common.Test
{
public class EnvironmentVariableWrapperTests
{
[Fact]
public void Instance_WhenCalledMultipleTimes_ReturnsSameInstance()
{
var value0 = EnvironmentVariableWrapper.Instance;
var value1 = EnvironmentVariableWrapper.Instance;
Assert.Same(value0, value1);
}
[Fact]
public void GetEnvironmentVariable_WhenVariableDoesNotExist_ReturnsNull()
{
var instance = EnvironmentVariableWrapper.Instance;
var value = instance.GetEnvironmentVariable(Guid.NewGuid().ToString());
Assert.Null(value);
}
[Fact]
public void GetEnvironmentVariable_WhenVariableExists_ReturnsValue()
{
var instance = EnvironmentVariableWrapper.Instance;
var name = Guid.NewGuid().ToString();
var expectedValue = Guid.NewGuid().ToString();
Environment.SetEnvironmentVariable(name, expectedValue);
var actualValue = instance.GetEnvironmentVariable(name);
Assert.Equal(expectedValue, actualValue);
}
[Theory]
[InlineData("Foo", "Foo")]
[InlineData("Foo.Bar", "Foo_Bar")]
[InlineData("Foo-Bar", "Foo_Bar")]
[InlineData("Foo Bar!", "Foo_Bar_")]
[InlineData("^Foo@Bar#", "_Foo_Bar_")]
public void GetEnvironmentVariable_WhenVariableIsNotNormalized_NormalizeValue(string sourceName, string normalizedSourceName)
{
var expectedValue = Guid.NewGuid().ToString();
var instance = EnvironmentVariableWrapper.Instance;
Environment.SetEnvironmentVariable(normalizedSourceName, expectedValue);
var actualValue = instance.GetEnvironmentVariable(sourceName);
Assert.Equal(expectedValue, actualValue);
}
}
}