|
9 | 9 | using Microsoft.NET.TestFramework.Commands;
|
10 | 10 | using Xunit;
|
11 | 11 | using Xunit.Abstractions;
|
| 12 | +using System.Linq; |
| 13 | +using System.Diagnostics; |
| 14 | +using System.Xml.Linq; |
| 15 | +using NuGet.Packaging; |
| 16 | +using System; |
12 | 17 |
|
13 | 18 | namespace Microsoft.NET.Sdk.Razor.Tests
|
14 | 19 | {
|
@@ -194,6 +199,121 @@ public void BuildProjectWithReferences_GeneratesJsonManifestAndCopiesItToOutputF
|
194 | 199 | intermediateOutputPath);
|
195 | 200 | }
|
196 | 201 |
|
| 202 | + [Fact] |
| 203 | + public void BuildProjectWithReferences_WorksWithStaticWebAssetsV1ClassLibraries() |
| 204 | + { |
| 205 | + var testAsset = "RazorAppWithPackageAndP2PReference"; |
| 206 | + ProjectDirectory = CreateAspNetSdkTestAsset(testAsset) |
| 207 | + .WithProjectChanges((project, document) => |
| 208 | + { |
| 209 | + if (Path.GetFileName(project) == "AnotherClassLib.csproj") |
| 210 | + { |
| 211 | + document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.1"); |
| 212 | + document.Descendants("FrameworkReference").Single().Remove(); |
| 213 | + document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0")); |
| 214 | + } |
| 215 | + if (Path.GetFileName(project) == "ClassLibrary.csproj") |
| 216 | + { |
| 217 | + document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.0"); |
| 218 | + document.Descendants("FrameworkReference").Single().Remove(); |
| 219 | + document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0")); |
| 220 | + } |
| 221 | + }); |
| 222 | + |
| 223 | + // We are deleting Views and Components because we are only interested in the static web assets behavior for this test |
| 224 | + // and this makes it easier to validate the test. |
| 225 | + Directory.Delete(Path.Combine(ProjectDirectory.TestRoot, "AnotherClassLib", "Views"), recursive: true); |
| 226 | + Directory.Delete(Path.Combine(ProjectDirectory.TestRoot, "ClassLibrary", "Views"), recursive: true); |
| 227 | + Directory.Delete(Path.Combine(ProjectDirectory.TestRoot, "ClassLibrary", "Components"), recursive: true); |
| 228 | + |
| 229 | + var build = new BuildCommand(ProjectDirectory, "AppWithPackageAndP2PReference"); |
| 230 | + build.WithWorkingDirectory(ProjectDirectory.TestRoot); |
| 231 | + build.Execute("/bl").Should().Pass(); |
| 232 | + |
| 233 | + var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); |
| 234 | + var outputPath = build.GetOutputDirectory(DefaultTfm, "Debug").ToString(); |
| 235 | + |
| 236 | + // GenerateStaticWebAssetsManifest should generate the manifest file. |
| 237 | + var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json"); |
| 238 | + new FileInfo(path).Should().Exist(); |
| 239 | + AssertManifest( |
| 240 | + StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), |
| 241 | + LoadBuildManifest()); |
| 242 | + |
| 243 | + // GenerateStaticWebAssetsManifest should copy the file to the output folder. |
| 244 | + var finalPath = Path.Combine(outputPath, "AppWithPackageAndP2PReference.staticwebassets.json"); |
| 245 | + new FileInfo(finalPath).Should().Exist(); |
| 246 | + AssertManifest( |
| 247 | + StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), |
| 248 | + LoadBuildManifest()); |
| 249 | + |
| 250 | + AssertBuildAssets( |
| 251 | + StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)), |
| 252 | + outputPath, |
| 253 | + intermediateOutputPath); |
| 254 | + } |
| 255 | + |
| 256 | + [Fact] |
| 257 | + public void PublishProjectWithReferences_WorksWithStaticWebAssetsV1ClassLibraries() |
| 258 | + { |
| 259 | + var testAsset = "RazorAppWithPackageAndP2PReference"; |
| 260 | + ProjectDirectory = CreateAspNetSdkTestAsset(testAsset) |
| 261 | + .WithProjectChanges((project, document) => |
| 262 | + { |
| 263 | + if (Path.GetFileName(project) == "AnotherClassLib.csproj") |
| 264 | + { |
| 265 | + document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.1"); |
| 266 | + document.Descendants("FrameworkReference").Single().Remove(); |
| 267 | + document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0")); |
| 268 | + } |
| 269 | + if (Path.GetFileName(project) == "ClassLibrary.csproj") |
| 270 | + { |
| 271 | + document.Descendants("TargetFramework").Single().ReplaceNodes("netstandard2.0"); |
| 272 | + document.Descendants("FrameworkReference").Single().Remove(); |
| 273 | + document.Descendants("PropertyGroup").First().Add(new XElement("RazorLangVersion", "3.0")); |
| 274 | + } |
| 275 | + }); |
| 276 | + |
| 277 | + // We are deleting Views and Components because we are only interested in the static web assets behavior for this test |
| 278 | + // and this makes it easier to validate the test. |
| 279 | + Directory.Delete(Path.Combine(ProjectDirectory.TestRoot, "AnotherClassLib", "Views"), recursive: true); |
| 280 | + Directory.Delete(Path.Combine(ProjectDirectory.TestRoot, "ClassLibrary", "Views"), recursive: true); |
| 281 | + Directory.Delete(Path.Combine(ProjectDirectory.TestRoot, "ClassLibrary", "Components"), recursive: true); |
| 282 | + |
| 283 | + var restore = new RestoreCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference")); |
| 284 | + restore.Execute().Should().Pass(); |
| 285 | + |
| 286 | + var publish = new PublishCommand(Log, Path.Combine(ProjectDirectory.TestRoot, "AppWithPackageAndP2PReference")); |
| 287 | + publish.WithWorkingDirectory(ProjectDirectory.Path); |
| 288 | + publish.Execute("/bl").Should().Pass(); |
| 289 | + |
| 290 | + var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString(); |
| 291 | + var publishPath = publish.GetOutputDirectory(DefaultTfm, "Debug").ToString(); |
| 292 | + |
| 293 | + // GenerateStaticWebAssetsManifest should generate the manifest file. |
| 294 | + var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json"); |
| 295 | + new FileInfo(path).Should().Exist(); |
| 296 | + AssertManifest( |
| 297 | + StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)), |
| 298 | + LoadBuildManifest()); |
| 299 | + |
| 300 | + // GenerateStaticWebAssetsManifest should copy the file to the output folder. |
| 301 | + var finalPath = Path.Combine(publishPath, "AppWithPackageAndP2PReference.staticwebassets.json"); |
| 302 | + new FileInfo(finalPath).Should().NotExist(); |
| 303 | + |
| 304 | + // GenerateStaticWebAssetsPublishManifest should generate the publish manifest file. |
| 305 | + var intermediatePublishManifestPath = Path.Combine(intermediateOutputPath, "StaticWebAssets.publish.json"); |
| 306 | + new FileInfo(path).Should().Exist(); |
| 307 | + AssertManifest( |
| 308 | + StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath)), |
| 309 | + LoadPublishManifest()); |
| 310 | + |
| 311 | + AssertPublishAssets( |
| 312 | + StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(intermediatePublishManifestPath)), |
| 313 | + publishPath, |
| 314 | + intermediateOutputPath); |
| 315 | + } |
| 316 | + |
197 | 317 | // Build no dependencies
|
198 | 318 | [Fact]
|
199 | 319 | public void BuildProjectWithReferences_NoDependencies_GeneratesJsonManifestAndCopiesItToOutputFolder()
|
|
0 commit comments