|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.IO; |
| 3 | +using FluentAssertions; |
| 4 | +using Microsoft.NET.TestFramework; |
| 5 | +using Microsoft.NET.TestFramework.Assertions; |
| 6 | +using Microsoft.NET.TestFramework.Commands; |
| 7 | +using Microsoft.NET.TestFramework.ProjectConstruction; |
| 8 | +using Xunit; |
| 9 | +using Xunit.Abstractions; |
| 10 | + |
| 11 | +namespace Microsoft.NET.Publish.Tests |
| 12 | +{ |
| 13 | + public class NetCorePublishItemsOutputGroupTests : SdkTest |
| 14 | + { |
| 15 | + public NetCorePublishItemsOutputGroupTests(ITestOutputHelper log) : base(log) |
| 16 | + { |
| 17 | + } |
| 18 | + |
| 19 | + private static List<string> FrameworkAssemblies = new List<string>() |
| 20 | + { |
| 21 | + "api-ms-win-core-console-l1-1-0.dll", |
| 22 | + "System.Runtime.dll", |
| 23 | + "WindowsBase.dll", |
| 24 | + }; |
| 25 | + |
| 26 | + [CoreMSBuildOnlyFact] |
| 27 | + public void GroupPopulatedWithRid() |
| 28 | + { |
| 29 | + var testProject = this.SetupProject(); |
| 30 | + var testAsset = _testAssetsManager.CreateTestProject(testProject); |
| 31 | + |
| 32 | + var restoreCommand = new RestoreCommand(Log, testAsset.Path, testProject.Name); |
| 33 | + restoreCommand |
| 34 | + .Execute() |
| 35 | + .Should() |
| 36 | + .Pass(); |
| 37 | + |
| 38 | + var buildCommand = new BuildCommand(Log, testAsset.Path, testProject.Name); |
| 39 | + buildCommand |
| 40 | + .Execute("/p:RuntimeIdentifier=win-x86", "/t:NetCorePublishItemsOutputGroup") |
| 41 | + .Should() |
| 42 | + .Pass(); |
| 43 | + |
| 44 | + var testOutputDir = Path.Combine(testAsset.Path, testProject.Name, "TestOutput"); |
| 45 | + Log.WriteLine("Contents of NetCorePublishItemsOutputGroup dumped to '{0}'.", testOutputDir); |
| 46 | + |
| 47 | + // Check for the existence of a few specific files that should be in the directory where the |
| 48 | + // contents of NetCorePublishItemsOutputGroup were dumped to make sure it's getting populated. |
| 49 | + Assert.True(File.Exists(Path.Combine(testOutputDir, $"{testProject.Name}.exe")), $"Assembly {testProject.Name}.exe is present in the output group."); |
| 50 | + foreach (var assem in FrameworkAssemblies) |
| 51 | + { |
| 52 | + Assert.True(File.Exists(Path.Combine(testOutputDir, assem)), $"Assembly {assem} is present in the output group."); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + [CoreMSBuildOnlyFact] |
| 57 | + public void GroupNotPopulatedWithoutRid() |
| 58 | + { |
| 59 | + var testProject = this.SetupProject(); |
| 60 | + var testAsset = _testAssetsManager.CreateTestProject(testProject); |
| 61 | + |
| 62 | + var restoreCommand = new RestoreCommand(Log, testAsset.Path, testProject.Name); |
| 63 | + restoreCommand |
| 64 | + .Execute() |
| 65 | + .Should() |
| 66 | + .Pass(); |
| 67 | + |
| 68 | + var buildCommand = new BuildCommand(Log, testAsset.Path, testProject.Name); |
| 69 | + buildCommand |
| 70 | + .Execute("/t:NetCorePublishItemsOutputGroup") |
| 71 | + .Should() |
| 72 | + .Pass(); |
| 73 | + |
| 74 | + var testOutputDir = Path.Combine(testAsset.Path, testProject.Name, "TestOutput"); |
| 75 | + Log.WriteLine("Contents of NetCorePublishItemsOutputGroup dumped to '{0}'.", testOutputDir); |
| 76 | + |
| 77 | + // Since no RID was specified the output group should only contain framework dependent output |
| 78 | + Assert.True(File.Exists(Path.Combine(testOutputDir, $"{testProject.Name}.exe")), $"Assembly {testProject.Name}.exe is present in the output group."); |
| 79 | + foreach (var assem in FrameworkAssemblies) |
| 80 | + { |
| 81 | + Assert.False(File.Exists(Path.Combine(testOutputDir, assem)), $"Assembly {assem} is not present in the output group."); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + private TestProject SetupProject() |
| 86 | + { |
| 87 | + var testProject = new TestProject() |
| 88 | + { |
| 89 | + Name = "TestPublishOutputGroup", |
| 90 | + TargetFrameworks = "netcoreapp3.0", |
| 91 | + IsSdkProject = true, |
| 92 | + IsExe = true |
| 93 | + }; |
| 94 | + |
| 95 | + testProject.AdditionalProperties["RuntimeIdentifiers"] = "win-x86"; |
| 96 | + |
| 97 | + // Use a test-specific packages folder |
| 98 | + testProject.AdditionalProperties["RestorePackagesPath"] = @"$(MSBuildProjectDirectory)\..\pkg"; |
| 99 | + |
| 100 | + // Add a target that will dump the contents of the NetCorePublishItemsOutputGroup to |
| 101 | + // a test directory after building. |
| 102 | + testProject.CopyFilesTargets.Add(new CopyFilesTarget( |
| 103 | + "CopyNetCorePublishItemsOutputGroup", |
| 104 | + "NetCorePublishItemsOutputGroup", |
| 105 | + "@(NetCorePublishItemsOutputGroupOutputs)", |
| 106 | + "$(MSBuildProjectDirectory)\\TestOutput")); |
| 107 | + |
| 108 | + return testProject; |
| 109 | + } |
| 110 | + } |
| 111 | +} |
0 commit comments