-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
GetPublishItemsOutputGroupOutputsTests.cs
68 lines (58 loc) · 3.82 KB
/
GetPublishItemsOutputGroupOutputsTests.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
// 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 Xunit;
namespace Microsoft.NET.Build.Tasks.UnitTests
{
public class GetPublishItemsOutputGroupOutputsTests
{
private readonly MockTaskItem _apphost
= new(@"C:\work\temp\WindowsDesktopSdkTest_without_ProjectSdk_set\obj\Debug\net5.0\apphost.exe",
new Dictionary<string, string>
{
{"RelativePath", "WindowsDesktopSdkTest_without_ProjectSdk_set.exe"},
{"IsKeyOutput", "True"},
{"CopyToPublishDirectory", "Always"},
{"TargetPath", "WindowsDesktopSdkTest_without_ProjectSdk_set.exe"},
});
private readonly MockTaskItem _dll =
new(@"obj\Debug\net5.0\WindowsDesktopSdkTest_without_ProjectSdk_set.dll",
new Dictionary<string, string>
{
{"RelativePath", "WindowsDesktopSdkTest_without_ProjectSdk_set.dll"},
{"CopyToPublishDirectory", "Always"},
});
// The logic is cross platform but the test path examples are all in Windows
[WindowsOnlyFact]
public void It_can_expand_OutputPath()
{
var task = new GetPublishItemsOutputGroupOutputs
{
PublishDir = @"bin\Debug\net5.0\publish\",
ResolvedFileToPublish = new[]
{
_apphost, _dll, _dll
}
};
task.Execute().Should().BeTrue();
task.PublishItemsOutputGroupOutputs.Length.Should().Be(3);
// mock itemgroup does not support well-known metadata "FullPath". So no assertion on that
// https://github.com/dotnet/msbuild/blob/46b723ba9ee9f4297d0c8ccbb6dc52e4bd8ea438/src/Shared/Modifiers.cs#L53-L67
task.PublishItemsOutputGroupOutputs[0].GetMetadata("RelativePath").Should().Be("WindowsDesktopSdkTest_without_ProjectSdk_set.exe");
task.PublishItemsOutputGroupOutputs[0].GetMetadata("OutputGroup").Should().Be("PublishItemsOutputGroup");
task.PublishItemsOutputGroupOutputs[0].GetMetadata("IsKeyOutput").Should().Be("True");
task.PublishItemsOutputGroupOutputs[0].GetMetadata("OutputPath").Should().Be(@"bin\Debug\net5.0\publish\WindowsDesktopSdkTest_without_ProjectSdk_set.exe");
task.PublishItemsOutputGroupOutputs[0].GetMetadata("CopyToPublishDirectory").Should().Be("Always", "should keep all existing metadata");
task.PublishItemsOutputGroupOutputs[0].GetMetadata("TargetPath").Should().Be("WindowsDesktopSdkTest_without_ProjectSdk_set.exe");
task.PublishItemsOutputGroupOutputs[1].GetMetadata("RelativePath").Should().Be("WindowsDesktopSdkTest_without_ProjectSdk_set.dll");
task.PublishItemsOutputGroupOutputs[1].GetMetadata("OutputGroup").Should().Be("PublishItemsOutputGroup");
task.PublishItemsOutputGroupOutputs[1].GetMetadata("CopyToPublishDirectory").Should().Be("Always");
task.PublishItemsOutputGroupOutputs[1].GetMetadata("TargetPath").Should().Be(@"WindowsDesktopSdkTest_without_ProjectSdk_set.dll");
// duplicated item should have the same info without error
task.PublishItemsOutputGroupOutputs[2].GetMetadata("RelativePath").Should().Be("WindowsDesktopSdkTest_without_ProjectSdk_set.dll");
task.PublishItemsOutputGroupOutputs[2].GetMetadata("OutputGroup").Should().Be("PublishItemsOutputGroup");
task.PublishItemsOutputGroupOutputs[2].GetMetadata("CopyToPublishDirectory").Should().Be("Always");
task.PublishItemsOutputGroupOutputs[2].GetMetadata("TargetPath").Should().Be(@"WindowsDesktopSdkTest_without_ProjectSdk_set.dll");
}
}
}