@@ -19,109 +19,45 @@ public class ProjectFileUpdaterTests : TestBase
19
19
private IVariableProvider variableProvider ;
20
20
private ILog log ;
21
21
private IFileSystem fileSystem ;
22
+ private IProjectFileUpdater projectFileUpdater ;
23
+ private List < string > logMessages ;
22
24
23
25
[ SetUp ]
24
26
public void Setup ( )
25
27
{
26
28
ShouldlyConfiguration . ShouldMatchApprovedDefaults . LocateTestMethodUsingAttribute < TestCaseAttribute > ( ) ;
27
29
var sp = ConfigureServices ( ) ;
28
- this . log = Substitute . For < ILog > ( ) ;
29
- this . fileSystem = sp . GetService < IFileSystem > ( ) ;
30
- this . variableProvider = sp . GetService < IVariableProvider > ( ) ;
31
- }
32
-
33
- [ TestCase ( @"
34
- <Project Sdk=""Microsoft.NET.Sdk"">
35
- <PropertyGroup>
36
- <OutputType>Exe</OutputType>
37
- <TargetFramework>netcoreapp3.1</TargetFramework>
38
- </PropertyGroup>
39
- </Project>
40
- " ) ]
41
- [ Category ( NoMono ) ]
42
- [ Description ( NoMonoDescription ) ]
43
- public void CanUpdateProjectFileWithStandardProjectFileXml ( string xml )
44
- {
45
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ) ;
46
-
47
- var canUpdate = projectFileUpdater . CanUpdateProjectFile ( XElement . Parse ( xml ) ) ;
48
-
49
- canUpdate . ShouldBe ( true ) ;
50
- }
51
30
52
- [ TestCase ( @"
53
- <Project Sdk=""Microsoft.NET.Sdk.Worker"">
54
- <PropertyGroup>
55
- <OutputType>Exe</OutputType>
56
- <TargetFramework>netcoreapp3.1</TargetFramework>
57
- </PropertyGroup>
58
- </Project>
59
- " ) ]
60
- [ Category ( NoMono ) ]
61
- [ Description ( NoMonoDescription ) ]
62
- public void CanUpdateProjectFileWithStandardWorkerProjectFileXml ( string xml )
63
- {
64
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ) ;
31
+ this . logMessages = new List < string > ( ) ;
32
+ this . log = new Log ( new TestLogAppender ( this . logMessages . Add ) ) ;
65
33
66
- var canUpdate = projectFileUpdater . CanUpdateProjectFile ( XElement . Parse ( xml ) ) ;
67
-
68
- canUpdate . ShouldBe ( true ) ;
34
+ this . fileSystem = sp . GetService < IFileSystem > ( ) ;
35
+ this . variableProvider = sp . GetService < IVariableProvider > ( ) ;
36
+ this . projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ! ) ;
69
37
}
70
38
71
- [ TestCase ( @"
72
- <Project Sdk=""Microsoft.NET.Sdk.Web"">
73
- <PropertyGroup>
74
- <OutputType>Exe</OutputType>
75
- <TargetFramework>netcoreapp3.1</TargetFramework>
76
- </PropertyGroup>
77
- </Project>
78
- " ) ]
79
39
[ Category ( NoMono ) ]
80
40
[ Description ( NoMonoDescription ) ]
81
- public void CanUpdateProjectFileWithStandardWebProjectFileXml ( string xml )
41
+ [ TestCase ( "Microsoft.NET.Sdk" ) ]
42
+ [ TestCase ( "Microsoft.NET.Sdk.Worker" ) ]
43
+ [ TestCase ( "Microsoft.NET.Sdk.Web" ) ]
44
+ [ TestCase ( "Microsoft.NET.Sdk.WindowsDesktop" ) ]
45
+ [ TestCase ( "Microsoft.NET.Sdk.Razor" ) ]
46
+ [ TestCase ( "Microsoft.NET.Sdk.BlazorWebAssembly" ) ]
47
+ public void CanUpdateProjectFileWithSdkProjectFileXml ( string sdk )
82
48
{
83
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ) ;
84
-
85
- var canUpdate = projectFileUpdater . CanUpdateProjectFile ( XElement . Parse ( xml ) ) ;
86
-
87
- canUpdate . ShouldBe ( true ) ;
88
- }
89
-
90
- [ TestCase ( @"
91
- <Project Sdk=""Microsoft.NET.Sdk.WindowsDesktop"">
49
+ var xml = $@ "
50
+ <Project Sdk=""{ sdk } "">
92
51
<PropertyGroup>
93
52
<OutputType>Exe</OutputType>
94
- <TargetFramework>net461</TargetFramework>
95
- </PropertyGroup>
96
- </Project>
97
- " ) ]
98
- [ Category ( NoMono ) ]
99
- [ Description ( NoMonoDescription ) ]
100
- public void CanUpdateProjectFileWithStandardDesktopProjectFileXml ( string xml )
101
- {
102
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ) ;
103
-
104
- var canUpdate = projectFileUpdater . CanUpdateProjectFile ( XElement . Parse ( xml ) ) ;
105
-
106
- canUpdate . ShouldBe ( true ) ;
107
- }
108
-
109
- [ TestCase ( @"
110
- <Project Sdk=""Microsoft.NET.Sdk.Razor"">
111
- <PropertyGroup>
112
53
<TargetFramework>netcoreapp3.1</TargetFramework>
113
54
</PropertyGroup>
114
55
</Project>
115
- " ) ]
116
- [ Category ( NoMono ) ]
117
- [ Description ( NoMonoDescription ) ]
118
- public void CanUpdateProjectFileWithRazorClassLibraryProjectFileXml ( string xml )
119
- {
120
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ) ;
121
-
56
+ " ;
122
57
var canUpdate = projectFileUpdater . CanUpdateProjectFile ( XElement . Parse ( xml ) ) ;
123
58
124
59
canUpdate . ShouldBe ( true ) ;
60
+ logMessages . ShouldBeEmpty ( ) ;
125
61
}
126
62
127
63
[ TestCase ( @"
@@ -136,11 +72,13 @@ public void CanUpdateProjectFileWithRazorClassLibraryProjectFileXml(string xml)
136
72
[ Description ( NoMonoDescription ) ]
137
73
public void CannotUpdateProjectFileWithIncorrectProjectSdk ( string xml )
138
74
{
139
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ) ;
140
-
141
75
var canUpdate = projectFileUpdater . CanUpdateProjectFile ( XElement . Parse ( xml ) ) ;
142
76
143
77
canUpdate . ShouldBe ( false ) ;
78
+
79
+ logMessages . ShouldNotBeEmpty ( ) ;
80
+ logMessages . Count . ShouldBe ( 1 ) ;
81
+ logMessages . First ( ) . ShouldContain ( "Specified project file Sdk (SomeOtherProject.Sdk) is not supported, please ensure the project sdk starts with 'Microsoft.NET.Sdk'" ) ;
144
82
}
145
83
146
84
[ TestCase ( @"
@@ -155,11 +93,13 @@ public void CannotUpdateProjectFileWithIncorrectProjectSdk(string xml)
155
93
[ Description ( NoMonoDescription ) ]
156
94
public void CannotUpdateProjectFileWithMissingProjectSdk ( string xml )
157
95
{
158
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ) ;
159
-
160
96
var canUpdate = projectFileUpdater . CanUpdateProjectFile ( XElement . Parse ( xml ) ) ;
161
97
162
98
canUpdate . ShouldBe ( false ) ;
99
+
100
+ logMessages . ShouldNotBeEmpty ( ) ;
101
+ logMessages . Count . ShouldBe ( 1 ) ;
102
+ logMessages . First ( ) . ShouldContain ( "Specified project file Sdk () is not supported, please ensure the project sdk starts with 'Microsoft.NET.Sdk'" ) ;
163
103
}
164
104
165
105
[ TestCase ( @"
@@ -175,11 +115,13 @@ public void CannotUpdateProjectFileWithMissingProjectSdk(string xml)
175
115
[ Description ( NoMonoDescription ) ]
176
116
public void CannotUpdateProjectFileWithoutAssemblyInfoGeneration ( string xml )
177
117
{
178
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ) ;
179
-
180
118
var canUpdate = projectFileUpdater . CanUpdateProjectFile ( XElement . Parse ( xml ) ) ;
181
119
182
120
canUpdate . ShouldBe ( false ) ;
121
+
122
+ logMessages . ShouldNotBeEmpty ( ) ;
123
+ logMessages . Count . ShouldBe ( 1 ) ;
124
+ logMessages . First ( ) . ShouldContain ( "Project file specifies <GenerateAssemblyInfo>false</GenerateAssemblyInfo>: versions set in this project file will not affect the output artifacts" ) ;
183
125
}
184
126
185
127
[ TestCase ( @"
@@ -190,11 +132,13 @@ public void CannotUpdateProjectFileWithoutAssemblyInfoGeneration(string xml)
190
132
[ Description ( NoMonoDescription ) ]
191
133
public void CannotUpdateProjectFileWithoutAPropertyGroup ( string xml )
192
134
{
193
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ) ;
194
-
195
135
var canUpdate = projectFileUpdater . CanUpdateProjectFile ( XElement . Parse ( xml ) ) ;
196
136
197
137
canUpdate . ShouldBe ( false ) ;
138
+
139
+ logMessages . ShouldNotBeEmpty ( ) ;
140
+ logMessages . Count . ShouldBe ( 1 ) ;
141
+ logMessages . First ( ) . ShouldContain ( "Unable to locate any <PropertyGroup> elements in specified project file. Are you sure it is in a correct format?" ) ;
198
142
}
199
143
200
144
[ TestCase ( @"
@@ -209,11 +153,9 @@ public void CannotUpdateProjectFileWithoutAPropertyGroup(string xml)
209
153
[ Description ( NoMonoDescription ) ]
210
154
public void UpdateProjectXmlVersionElementWithStandardXmlInsertsElement ( string xml )
211
155
{
212
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ) ;
213
-
214
156
var variables = this . variableProvider . GetVariablesFor ( SemanticVersion . Parse ( "2.0.0" , "v" ) , new TestEffectiveConfiguration ( ) , false ) ;
215
157
var xmlRoot = XElement . Parse ( xml ) ;
216
- ProjectFileUpdater . UpdateProjectVersionElement ( xmlRoot , ProjectFileUpdater . AssemblyVersionElement , variables . AssemblySemVer ) ;
158
+ ProjectFileUpdater . UpdateProjectVersionElement ( xmlRoot , ProjectFileUpdater . AssemblyVersionElement , variables . AssemblySemVer ! ) ;
217
159
218
160
var expectedXml = XElement . Parse ( @"
219
161
<Project Sdk=""Microsoft.NET.Sdk"">
@@ -239,11 +181,9 @@ public void UpdateProjectXmlVersionElementWithStandardXmlInsertsElement(string x
239
181
[ Description ( NoMonoDescription ) ]
240
182
public void UpdateProjectXmlVersionElementWithStandardXmlModifiesElement ( string xml )
241
183
{
242
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ) ;
243
-
244
184
var variables = this . variableProvider . GetVariablesFor ( SemanticVersion . Parse ( "2.0.0" , "v" ) , new TestEffectiveConfiguration ( ) , false ) ;
245
185
var xmlRoot = XElement . Parse ( xml ) ;
246
- ProjectFileUpdater . UpdateProjectVersionElement ( xmlRoot , ProjectFileUpdater . AssemblyVersionElement , variables . AssemblySemVer ) ;
186
+ ProjectFileUpdater . UpdateProjectVersionElement ( xmlRoot , ProjectFileUpdater . AssemblyVersionElement , variables . AssemblySemVer ! ) ;
247
187
248
188
var expectedXml = XElement . Parse ( @"
249
189
<Project Sdk=""Microsoft.NET.Sdk"">
@@ -272,11 +212,9 @@ public void UpdateProjectXmlVersionElementWithStandardXmlModifiesElement(string
272
212
[ Description ( NoMonoDescription ) ]
273
213
public void UpdateProjectXmlVersionElementWithDuplicatePropertyGroupsModifiesLastElement ( string xml )
274
214
{
275
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ) ;
276
-
277
215
var variables = this . variableProvider . GetVariablesFor ( SemanticVersion . Parse ( "2.0.0" , "v" ) , new TestEffectiveConfiguration ( ) , false ) ;
278
216
var xmlRoot = XElement . Parse ( xml ) ;
279
- ProjectFileUpdater . UpdateProjectVersionElement ( xmlRoot , ProjectFileUpdater . AssemblyVersionElement , variables . AssemblySemVer ) ;
217
+ ProjectFileUpdater . UpdateProjectVersionElement ( xmlRoot , ProjectFileUpdater . AssemblyVersionElement , variables . AssemblySemVer ! ) ;
280
218
281
219
var expectedXml = XElement . Parse ( @"
282
220
<Project Sdk=""Microsoft.NET.Sdk"">
@@ -306,11 +244,9 @@ public void UpdateProjectXmlVersionElementWithDuplicatePropertyGroupsModifiesLas
306
244
[ Description ( NoMonoDescription ) ]
307
245
public void UpdateProjectXmlVersionElementWithMultipleVersionElementsLastOneIsModified ( string xml )
308
246
{
309
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , this . fileSystem ) ;
310
-
311
247
var variables = this . variableProvider . GetVariablesFor ( SemanticVersion . Parse ( "2.0.0" , "v" ) , new TestEffectiveConfiguration ( ) , false ) ;
312
248
var xmlRoot = XElement . Parse ( xml ) ;
313
- ProjectFileUpdater . UpdateProjectVersionElement ( xmlRoot , ProjectFileUpdater . AssemblyVersionElement , variables . AssemblySemVer ) ;
249
+ ProjectFileUpdater . UpdateProjectVersionElement ( xmlRoot , ProjectFileUpdater . AssemblyVersionElement , variables . AssemblySemVer ! ) ;
314
250
315
251
var expectedXml = XElement . Parse ( @"
316
252
<Project Sdk=""Microsoft.NET.Sdk"">
@@ -339,8 +275,8 @@ public void UpdateProjectFileAddsVersionToFile(string xml)
339
275
340
276
VerifyAssemblyInfoFile ( xml , fileName , AssemblyVersioningScheme . MajorMinorPatch , verify : ( fs , variables ) =>
341
277
{
342
- using var projectFileUpdater = new ProjectFileUpdater ( this . log , fs ) ;
343
- projectFileUpdater . Execute ( variables , new AssemblyInfoContext ( Path . GetTempPath ( ) , false , fileName ) ) ;
278
+ using var projFileUpdater = new ProjectFileUpdater ( this . log , fs ) ;
279
+ projFileUpdater . Execute ( variables , new AssemblyInfoContext ( Path . GetTempPath ( ) , false , fileName ) ) ;
344
280
345
281
var expectedXml = @"
346
282
<Project Sdk=""Microsoft.NET.Sdk"">
0 commit comments