Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.Arcade.Test.Common;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
using Xunit;

namespace Microsoft.DotNet.Build.Tasks.Workloads.Tests
Expand All @@ -14,6 +16,8 @@ public class GenerateVisualStudioWorkloadTests
{
public string IntermediateBaseOutputPath = Path.Combine(AppContext.BaseDirectory, "obj");

public string TestAssetsPath = Path.Combine(AppContext.BaseDirectory, "testassets");

public string TestIntermediateBaseOutputPath => Path.Combine(IntermediateBaseOutputPath, Path.GetFileNameWithoutExtension(Path.GetTempFileName()));

[Fact]
Expand All @@ -27,15 +31,17 @@ public void ItGeneratesASwixProjectFromAWorkloadManifest()
{
new TaskItem(workloadManifest)
},

ComponentVersion = "6.5.38766",
ComponentVersions = new TaskItem[]
{
new TaskItem("microsoft-net-sdk-blazorwebassembly-aot", new Dictionary<string, string> { { "Version", "6.5.38766" } }),
},
GenerateMsis = false,
IntermediateBaseOutputPath = TestIntermediateBaseOutputPath,
WixToolsetPath = "",
BuildEngine = new MockBuildEngine()
};

buildTask.Execute();
Assert.True(buildTask.Execute());
string outputPath = Path.GetDirectoryName(buildTask.SwixProjects[0].GetMetadata("FullPath"));
string componentSwr = File.ReadAllText(Path.Combine(outputPath, "component.swr"));

Expand All @@ -60,14 +66,17 @@ public void ItCanShortenPackageIds()
{
new TaskItem("Microsoft.NET.Runtime", new Dictionary<string, string> { {"Replacement", "MSFT"} })
},
ComponentVersion = "6.5.38766",
ComponentVersions = new TaskItem[]
{
new TaskItem("microsoft-net-sdk-blazorwebassembly-aot", new Dictionary<string, string> { { "Version", "6.5.38766" } }),
},
GenerateMsis = false,
IntermediateBaseOutputPath = TestIntermediateBaseOutputPath,
WixToolsetPath = "",
BuildEngine = new MockBuildEngine()
};

buildTask.Execute();
Assert.True(buildTask.Execute());
string outputPath = Path.GetDirectoryName(buildTask.SwixProjects[0].GetMetadata("FullPath"));
string componentSwr = File.ReadAllText(Path.Combine(outputPath, "component.swr"));

Expand Down Expand Up @@ -96,7 +105,7 @@ public void ItGeneratesASwixProjectFromAWorkloadManifestPackage()
BuildEngine = new MockBuildEngine()
};

buildTask.Execute();
Assert.True(buildTask.Execute());
string outputPath = Path.GetDirectoryName(buildTask.SwixProjects[0].GetMetadata("FullPath"));
string componentSwr = File.ReadAllText(Path.Combine(outputPath, "component.swr"));

Expand All @@ -106,5 +115,56 @@ public void ItGeneratesASwixProjectFromAWorkloadManifestPackage()
Assert.Contains("vs.dependency id=Microsoft.NET.Runtime.MonoAOTCompiler.Task.6.0.0-preview.4.21201.1", componentSwr);
Assert.Contains("vs.dependency id=Microsoft.NET.Runtime.Emscripten.Python.6.0.0-preview.4.21205.1", componentSwr);
}

[Fact]
public void ItSkipsAbstractManifests()
{
var buildTask = new GenerateVisualStudioWorkload()
{
WorkloadManifests = new TaskItem[]
{
new TaskItem(Path.Combine(TestAssetsPath, "BlazorWorkloadManifest.json"))
},
GenerateMsis = false,
IntermediateBaseOutputPath = TestIntermediateBaseOutputPath,
WixToolsetPath = "",
BuildEngine = new MockBuildEngine()
};

Assert.True(buildTask.Execute());
string outputPath = Path.GetDirectoryName(buildTask.SwixProjects[0].GetMetadata("FullPath"));
string componentSwr = File.ReadAllText(Path.Combine(outputPath, "component.swr"));
Assert.Single(buildTask.SwixProjects);
Assert.Contains(@"package name=microsoft.net.sdk.blazorwebassembly.aot
version=6.0.0.0", componentSwr);
}

[Fact]
public void ItReportsMissingPacks()
{
var buildTask = new GenerateVisualStudioWorkload()
{
WorkloadManifests = new TaskItem[]
{
new TaskItem(Path.Combine(TestAssetsPath, "BlazorWorkloadManifest.json"))
},
GenerateMsis = true,
IntermediateBaseOutputPath = TestIntermediateBaseOutputPath,
WixToolsetPath = "",
PackagesPath = Path.Combine(TestAssetsPath, "packages"),
BuildEngine = new MockBuildEngine()
};

// The task will fail to generate VS components because we have no generated MSI packages.
// The package feeds are volatile until we actually release and the execution time for the unit tests would spike
Assert.False(buildTask.Execute());
ITaskItem missingPack = buildTask.MissingPacks.Where(mp => string.Equals(mp.ItemSpec, "Microsoft.NET.Runtime.MonoAOTCompiler.Task")).FirstOrDefault();

// This package would be required by the workload, but would be missing
Assert.Equal(Path.Combine(TestAssetsPath, "packages", "Microsoft.NET.Runtime.MonoAOTCompiler.Task.6.0.0-preview.5.21262.5.nupkg"), missingPack.GetMetadata("SourcePackage"));

// This package should not show as missing because it has the wrong platform and belongs to an abstract workload
Assert.DoesNotContain("Microsoft.NETCore.App.Runtime.AOT.osx-x64.Cross.ios-arm", buildTask.MissingPacks.Select(p => p.ItemSpec));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void ItAssignsDefaultValues()
{
WorkloadManifest manifest = Create("WorkloadManifest.json");
WorkloadDefinition definition = manifest.Workloads.FirstOrDefault().Value;
VisualStudioComponent component = VisualStudioComponent.Create(null, manifest, definition, "1.2.3.4", NoItems, NoItems, NoItems);
VisualStudioComponent component = VisualStudioComponent.Create(null, manifest, definition, NoItems, NoItems, NoItems, NoItems);

string swixProjDirectory = RandomPath;
Directory.CreateDirectory(swixProjDirectory);
Expand Down Expand Up @@ -51,7 +51,7 @@ public void ItCanOverrideDefaultValues()
})
};

VisualStudioComponent component = VisualStudioComponent.Create(null, manifest, definition, "1.2.3.4", NoItems, resources, NoItems);
VisualStudioComponent component = VisualStudioComponent.Create(null, manifest, definition, NoItems, NoItems, resources, NoItems);

string swixProjDirectory = RandomPath;
Directory.CreateDirectory(swixProjDirectory);
Expand All @@ -69,7 +69,7 @@ public void ItCreatesSafeComponentIds()
{
WorkloadManifest manifest = Create("WorkloadManifest.json");
WorkloadDefinition definition = manifest.Workloads.FirstOrDefault().Value;
VisualStudioComponent component = VisualStudioComponent.Create(null, manifest, definition, "1.2.3.4", NoItems, NoItems, NoItems);
VisualStudioComponent component = VisualStudioComponent.Create(null, manifest, definition, NoItems, NoItems, NoItems, NoItems);

string swixProjDirectory = RandomPath;
Directory.CreateDirectory(swixProjDirectory);
Expand Down
Loading