-
Notifications
You must be signed in to change notification settings - Fork 1k
/
GivenWriteAppConfigWithSupportedRuntimeTask.cs
173 lines (146 loc) · 7.34 KB
/
GivenWriteAppConfigWithSupportedRuntimeTask.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
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using FluentAssertions;
using NuGet.Frameworks;
using Xunit;
namespace Microsoft.NET.Build.Tasks.UnitTests
{
public class GivenWriteAppConfigWithSupportedRuntimeTask
{
[Fact]
public void It_creates_startup_and_supportedRuntime_node_when_there_is_not_any()
{
var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "true"),
new XElement("configuration"));
WriteAppConfigWithSupportedRuntime.AddSupportedRuntimeToAppconfig(doc, ".NETFramework", "v4.5.2");
doc.Element("configuration")
.Elements("startup")
.Single().Elements()
.Should().Contain(e => e.Name.LocalName == "supportedRuntime");
}
[Fact]
public void It_creates_supportedRuntime_node_when_there_is_startup()
{
var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "true"),
new XElement("configuration", new XElement("startup")));
WriteAppConfigWithSupportedRuntime.AddSupportedRuntimeToAppconfig(doc, ".NETFramework", "v4.5.2");
doc.Element("configuration")
.Elements("startup")
.Single().Elements()
.Should().Contain(e => e.Name.LocalName == "supportedRuntime");
}
[Fact]
public void It_does_not_change_supportedRuntime_node_when_there_is_supportedRuntime()
{
var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "true"),
new XElement("configuration",
new XElement("startup",
new XElement("supportedRuntime",
new XAttribute("version", "v4.0"),
new XAttribute("sku", ".NETFramework,Version=v4.7.2")))));
WriteAppConfigWithSupportedRuntime.AddSupportedRuntimeToAppconfig(doc, ".NETFramework", "v4.6.2");
XElement supportedRuntime = doc.Element("configuration")
.Elements("startup")
.Single().Elements("supportedRuntime")
.Single();
supportedRuntime.Should().HaveAttribute("version", "v4.0");
supportedRuntime.Should().HaveAttribute("sku", ".NETFramework,Version=v4.7.2");
}
// intersection of https://docs.microsoft.com/en-us/nuget/reference/target-frameworks
// and https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/startup/supportedruntime-element#version
[Theory]
[InlineData(".NETFramework", "v1.1", "v1.1.4322")]
[InlineData(".NETFramework", "v2.0", "v2.0.50727")]
[InlineData(".NETFramework", "v3.5", "v2.0.50727")]
public void It_generate_correct_version_and_sku_for_below40(
string targetFrameworkIdentifier,
string targetFrameworkVersion,
string expectedVersion)
{
var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "true"),
new XElement("configuration"));
WriteAppConfigWithSupportedRuntime.AddSupportedRuntimeToAppconfig(doc, targetFrameworkIdentifier, targetFrameworkVersion);
XElement supportedRuntime = doc.Element("configuration")
.Elements("startup")
.Single().Elements("supportedRuntime")
.Single();
supportedRuntime.Should().HaveAttribute("version", expectedVersion);
supportedRuntime.Attribute("sku").Should().BeNull();
}
[Theory]
[InlineData(".NETFramework", "v4.5", "v4.0", ".NETFramework,Version=v4.5")]
[InlineData(".NETFramework", "v4.5.1", "v4.0", ".NETFramework,Version=v4.5.1")]
[InlineData(".NETFramework", "v4.5.2", "v4.0", ".NETFramework,Version=v4.5.2")]
[InlineData(".NETFramework", "v4.6", "v4.0", ".NETFramework,Version=v4.6")]
[InlineData(".NETFramework", "v4.6.1", "v4.0", ".NETFramework,Version=v4.6.1")]
[InlineData(".NETFramework", "v4.6.2", "v4.0", ".NETFramework,Version=v4.6.2")]
[InlineData(".NETFramework", "v4.7", "v4.0", ".NETFramework,Version=v4.7")]
[InlineData(".NETFramework", "v4.7.1", "v4.0", ".NETFramework,Version=v4.7.1")]
[InlineData(".NETFramework", "v4.7.2", "v4.0", ".NETFramework,Version=v4.7.2")]
public void It_generate_correct_version_and_sku_for_above40(
string targetFrameworkIdentifier,
string targetFrameworkVersion,
string expectedVersion,
string expectedSku)
{
var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "true"),
new XElement("configuration"));
WriteAppConfigWithSupportedRuntime.AddSupportedRuntimeToAppconfig(doc, targetFrameworkIdentifier, targetFrameworkVersion);
XElement supportedRuntime = doc.Element("configuration")
.Elements("startup")
.Single().Elements("supportedRuntime")
.Single();
supportedRuntime.Should().HaveAttribute("version", expectedVersion);
supportedRuntime.Should().HaveAttribute("sku", expectedSku);
}
[Theory]
[InlineData(".NETFramework", "v4.0", "Client", "v4.0", ".NETFramework,Version=v4.0,Profile=Client")]
public void It_generate_correct_version_and_sku_and_profile(
string targetFrameworkIdentifier,
string targetFrameworkVersion,
string targetFrameworkProfile,
string expectedVersion,
string expectedSku)
{
var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "true"),
new XElement("configuration"));
WriteAppConfigWithSupportedRuntime.AddSupportedRuntimeToAppconfig(doc,
targetFrameworkIdentifier,
targetFrameworkVersion,
targetFrameworkProfile);
XElement supportedRuntime = doc.Element("configuration")
.Elements("startup")
.Single().Elements("supportedRuntime")
.Single();
supportedRuntime.Should().HaveAttribute("version", expectedVersion);
supportedRuntime.Should().HaveAttribute("sku", expectedSku);
}
[Theory]
[InlineData("net999")]
[InlineData("netstandard20")]
public void It_does_not_generate_version_and_sku_for_non_supported(string targetframework)
{
var targetFrameworkParsed = NuGetFramework.Parse(targetframework);
var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "true"),
new XElement("configuration"));
var parsedFramework = NuGetFramework.ParseFolder(targetframework);
WriteAppConfigWithSupportedRuntime.AddSupportedRuntimeToAppconfig(doc, parsedFramework.Framework, parsedFramework.Version.ToString());
doc.Element("configuration")
.Elements("startup").Should().BeNullOrEmpty();
}
}
}