forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuntimeConfigTests.cs
More file actions
235 lines (208 loc) · 6.46 KB
/
RuntimeConfigTests.cs
File metadata and controls
235 lines (208 loc) · 6.46 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#nullable disable
using System.Runtime.CompilerServices;
using Microsoft.DotNet.Cli;
namespace Microsoft.DotNet.Tests
{
public class RuntimeConfigTests : SdkTest
{
public RuntimeConfigTests(ITestOutputHelper log) : base(log)
{
}
[Fact]
void ParseBasicRuntimeConfig()
{
var tempPath = GetTempPath();
File.WriteAllText(tempPath, Basic);
var runtimeConfig = new RuntimeConfig(tempPath);
Asset(runtimeConfig);
}
[Fact]
void ParseRuntimeConfigWithTrailingComma()
{
var tempPath = GetTempPath();
File.WriteAllText(tempPath, TrailingComma);
var runtimeConfig = new RuntimeConfig(tempPath);
Asset(runtimeConfig);
}
[Fact]
void ParseRuntimeConfigWithComment()
{
var tempPath = GetTempPath();
File.WriteAllText(tempPath, WithComment);
var runtimeConfig = new RuntimeConfig(tempPath);
Asset(runtimeConfig);
}
[Fact]
void ParseRuntimeConfigWithDifferentOrder()
{
var tempPath = GetTempPath();
File.WriteAllText(tempPath, Order);
var runtimeConfig = new RuntimeConfig(tempPath);
Asset(runtimeConfig);
}
[Fact]
void ParseRuntimeConfigWithDifferentCasingOnNameAndVersionField()
{
var tempPath = GetTempPath();
File.WriteAllText(tempPath, CasingOnNameAndVersionField);
var runtimeConfig = new RuntimeConfig(tempPath);
Asset(runtimeConfig);
}
[Fact]
void ParseRuntimeConfigWithDifferentCasingOnFrameworkField()
{
var tempPath = GetTempPath();
File.WriteAllText(tempPath, CasingOnFrameworkField);
var runtimeConfig = new RuntimeConfig(tempPath);
runtimeConfig.Framework.Should().BeNull();
}
[Fact]
void ParseRuntimeConfigWithDifferentCasingOnRuntimeOptionsField()
{
var tempPath = GetTempPath();
File.WriteAllText(tempPath, CasingOnRuntimeOptionsField);
var runtimeConfig = new RuntimeConfig(tempPath);
runtimeConfig.Framework.Should().BeNull();
}
[Fact]
void ParseRuntimeConfigWithEmpty()
{
var tempPath = GetTempPath();
File.WriteAllText(tempPath, "");
Action a = () => new RuntimeConfig(tempPath);
a.Should().Throw<System.Text.Json.JsonException>();
}
[Fact]
void ParseRuntimeConfigWithDifferentWithExtraField()
{
var tempPath = GetTempPath();
File.WriteAllText(tempPath, ExtraField);
var runtimeConfig = new RuntimeConfig(tempPath);
Asset(runtimeConfig);
}
[Fact]
void ParseRuntimeConfigWithDifferentWithNoFramework()
{
var tempPath = GetTempPath();
File.WriteAllText(tempPath, NoFramework);
var runtimeConfig = new RuntimeConfig(tempPath);
runtimeConfig.Framework.Should().BeNull();
runtimeConfig.IsPortable.Should().BeFalse();
}
[Fact]
void ParseRuntimeConfigWithDifferentWithMissingField()
{
var tempPath = GetTempPath();
File.WriteAllText(tempPath, Missing);
var runtimeConfig = new RuntimeConfig(tempPath);
Asset(runtimeConfig);
}
private static void Asset(RuntimeConfig runtimeConfig)
{
runtimeConfig.Framework.Version.Should().Be("2.1.0");
runtimeConfig.Framework.Name.Should().Be("Microsoft.NETCore.App");
runtimeConfig.IsPortable.Should().BeTrue();
}
private string GetTempPath([CallerMemberName] string callingMethod = null)
{
return Path.Combine(_testAssetsManager.CreateTestDirectory(callingMethod).Path, Path.GetTempFileName());
}
private const string Basic =
$@"{{
""runtimeOptions"": {{
""tfm"": ""{ToolsetInfo.CurrentTargetFramework}"",
""framework"": {{
""name"": ""Microsoft.NETCore.App"",
""version"": ""2.1.0""
}}
}}
}}";
private const string TrailingComma =
$@"{{
""runtimeOptions"": {{
""tfm"": ""{ToolsetInfo.CurrentTargetFramework}"",
""framework"": {{
""name"": ""Microsoft.NETCore.App"",
""version"": ""2.1.0"",
}}
}}
}}";
private const string WithComment =
$@"{{
""runtimeOptions"": {{
""tfm"": ""{ToolsetInfo.CurrentTargetFramework}"",
""framework"": {{
""name"": ""Microsoft.NETCore.App"",
""version"": ""2.1.0"" // with comment
}}
}}
}}";
private const string Order =
$@"{{
""runtimeOptions"": {{
""framework"": {{
""version"": ""2.1.0"",
""name"": ""Microsoft.NETCore.App""
}},
""tfm"": ""{ToolsetInfo.CurrentTargetFramework}""
}}
}}";
private const string CasingOnNameAndVersionField =
$@"{{
""runtimeOptions"": {{
""tfm"": ""{ToolsetInfo.CurrentTargetFramework}"",
""framework"": {{
""Name"": ""Microsoft.NETCore.App"",
""Version"": ""2.1.0""
}}
}}
}}";
private const string CasingOnFrameworkField =
$@"{{
""runtimeOptions"": {{
""tfm"": ""{ToolsetInfo.CurrentTargetFramework}"",
""Framework"": {{
""name"": ""Microsoft.NETCore.App"",
""version"": ""2.1.0""
}}
}}
}}";
private const string CasingOnRuntimeOptionsField =
$@"{{
""RuntimeOptions"": {{
""tfm"": ""{ToolsetInfo.CurrentTargetFramework}"",
""framework"": {{
""name"": ""Microsoft.NETCore.App"",
""version"": ""2.1.0""
}}
}}
}}";
private const string ExtraField =
$@"{{
""runtimeOptions"": {{
""tfm"": ""{ToolsetInfo.CurrentTargetFramework}"",
""framework"": {{
""name"": ""Microsoft.NETCore.App"",
""version"": ""2.1.0""
}},
""extra"": ""field""
}}
}}";
private const string Missing =
@"{
""runtimeOptions"": {
""framework"": {
""name"": ""Microsoft.NETCore.App"",
""version"": ""2.1.0""
}
}
}";
private const string NoFramework =
@"{
""runtimeOptions"": {
}
}";
}
}