Skip to content

Commit 066a149

Browse files
committed
Add a new project with E2E tests for the MSBuild package
Like the CLI integration test project, this project consumes the nupkg from the .Build package. It installs the package in a test project, and then can perform test scenarios. For now a single test is included.
1 parent 535d468 commit 066a149

14 files changed

+321
-0
lines changed

Diff for: LibraryManager.sln

+15
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Web.LibraryManage
6464
EndProject
6565
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "libman.IntegrationTest", "test\libman.IntegrationTest\libman.IntegrationTest.csproj", "{BE84C694-91F1-C170-7366-7B86EBC9B033}"
6666
EndProject
67+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Web.LibraryManager.Build.IntegrationTest", "test\LibraryManager.Build.IntegrationTest\Microsoft.Web.LibraryManager.Build.IntegrationTest.csproj", "{EC152F12-CB03-4405-D8AE-EE7FC6E32666}"
68+
EndProject
6769
Global
6870
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6971
Debug|Any CPU = Debug|Any CPU
@@ -230,6 +232,18 @@ Global
230232
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Release|x64.Build.0 = Release|Any CPU
231233
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Release|x86.ActiveCfg = Release|Any CPU
232234
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Release|x86.Build.0 = Release|Any CPU
235+
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
236+
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Debug|Any CPU.Build.0 = Debug|Any CPU
237+
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Debug|x64.ActiveCfg = Debug|Any CPU
238+
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Debug|x64.Build.0 = Debug|Any CPU
239+
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Debug|x86.ActiveCfg = Debug|Any CPU
240+
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Debug|x86.Build.0 = Debug|Any CPU
241+
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Release|Any CPU.ActiveCfg = Release|Any CPU
242+
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Release|Any CPU.Build.0 = Release|Any CPU
243+
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Release|x64.ActiveCfg = Release|Any CPU
244+
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Release|x64.Build.0 = Release|Any CPU
245+
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Release|x86.ActiveCfg = Release|Any CPU
246+
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Release|x86.Build.0 = Release|Any CPU
233247
EndGlobalSection
234248
GlobalSection(SolutionProperties) = preSolution
235249
HideSolutionNode = FALSE
@@ -249,6 +263,7 @@ Global
249263
{E199195A-7EE8-9273-37B1-3726BCEAB87A} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
250264
{C8979E80-F4D3-3F21-D966-1B317CA64C23} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
251265
{BE84C694-91F1-C170-7366-7B86EBC9B033} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
266+
{EC152F12-CB03-4405-D8AE-EE7FC6E32666} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
252267
EndGlobalSection
253268
GlobalSection(ExtensibilityGlobals) = postSolution
254269
SolutionGuid = {720C6A7F-67F7-4D00-881F-D3CDEA7ABE69}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable enable
5+
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Diagnostics;
9+
using System.IO;
10+
using System.Linq;
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
14+
namespace Microsoft.Web.LibraryManager.Build.IntegrationTest;
15+
16+
[TestClass]
17+
[DeploymentItem(@"TestPackages", "TestPackages")]
18+
[DeploymentItem(@"TestSolution", "TestSolution")]
19+
public class BuildTestBase
20+
{
21+
private const string BuildPackageName = "Microsoft.Web.LibraryManager.Build";
22+
private const string ManifestFileName = "libman.json";
23+
private const string TestProjectFolderName = "Libman.Build.TestApp";
24+
private readonly string PackagesFolderPath = Path.Combine(Environment.CurrentDirectory, "TestPackages");
25+
protected string TestProjectDirectory { get; private set; } = "";
26+
27+
[TestInitialize]
28+
public async Task TestInitialize()
29+
{
30+
// test solution should be deployed with every test?
31+
TestProjectDirectory = Path.Combine(Path.GetFullPath("TestSolution"), TestProjectFolderName);
32+
33+
// create an empty nuget.config with only our package source
34+
await AddPackageReferenceAsync();
35+
}
36+
37+
[TestCleanup]
38+
public void TestCleanup()
39+
{
40+
if (Directory.Exists(TestProjectDirectory))
41+
{
42+
Directory.Delete(TestProjectDirectory, true);
43+
}
44+
}
45+
46+
protected async Task RunDotnetCommandLineAsync(string arguments, string? workingDirectory)
47+
{
48+
var processStartInfo = new ProcessStartInfo("dotnet", arguments)
49+
{
50+
RedirectStandardInput = true,
51+
RedirectStandardOutput = true,
52+
RedirectStandardError = true,
53+
UseShellExecute = false,
54+
CreateNoWindow = true,
55+
WorkingDirectory = workingDirectory,
56+
};
57+
58+
using (var process = Process.Start(processStartInfo))
59+
{
60+
await process.WaitForExitAsync();
61+
if (process.ExitCode != 0)
62+
{
63+
string output = await process.StandardError.ReadToEndAsync() + await process.StandardOutput.ReadToEndAsync();
64+
throw new InvalidOperationException($"CLI tool execution failed with arguments: {arguments}.\r\nOutput: {output}");
65+
}
66+
}
67+
}
68+
69+
private async Task AddPackageReferenceAsync()
70+
{
71+
await RunDotnetCommandLineAsync($"nuget add source \"{PackagesFolderPath}\"", TestProjectDirectory);
72+
73+
await RunDotnetCommandLineAsync($"add package {BuildPackageName} --version {GetBuildPackageVersion()}", TestProjectDirectory);
74+
}
75+
76+
private static string GetBuildPackageVersion()
77+
{
78+
return Directory.GetFiles("TestPackages", $"{BuildPackageName}.*.nupkg")
79+
.Select(Path.GetFileNameWithoutExtension)
80+
.Select(name => name.Substring(BuildPackageName.Length + 1))
81+
.OrderByDescending(version => version)
82+
.First();
83+
}
84+
85+
protected async Task CreateManifestFileAsync(string content)
86+
{
87+
string manifestFilePath = Path.Combine(TestProjectDirectory, ManifestFileName);
88+
await Task.Run(() => File.WriteAllText(manifestFilePath, content));
89+
}
90+
91+
protected void AssertFileExists(string relativeFilePath)
92+
{
93+
string filePath = Path.Combine(TestProjectDirectory, relativeFilePath);
94+
Assert.IsTrue(File.Exists(filePath), $"Expected file '{filePath}' does not exist.");
95+
}
96+
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>$(NetCoreTFM)</TargetFramework>
4+
</PropertyGroup>
5+
6+
<ItemGroup>
7+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
8+
<PackageReference Include="Moq" />
9+
<PackageReference Include="MSTest.TestAdapter" />
10+
<PackageReference Include="MSTest.TestFramework" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<!-- set build dependency so the nupkg is built for tests to consume -->
15+
<ProjectReference Include="..\..\src\LibraryManager.Build\Microsoft.Web.LibraryManager.Build.csproj" ReferenceOutputAssembly="false" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<Compile Remove="TestSolution\**\*" />
24+
<None Remove="TestSolution\**\*" />
25+
<Content Remove="TestSolution\**\*" />
26+
</ItemGroup>
27+
<ItemGroup>
28+
<Content Include="TestSolution\**\*">
29+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
30+
</Content>
31+
</ItemGroup>
32+
33+
<!-- Copy the nupkgs needed to run CLI and Build package integration tests -->
34+
<Target Name="CopyNupkgFiles" AfterTargets="Build" DependsOnTargets="GetBuildVersion">
35+
<PropertyGroup>
36+
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<BuildNupkg Include="..\..\artifacts\$(Configuration)\Microsoft.Web.LibraryManager.Build.$(PackageVersion).nupkg" />
40+
</ItemGroup>
41+
<Copy SourceFiles="@(BuildNupkg)" DestinationFolder="$(OutputPath)\TestPackages" />
42+
</Target>
43+
44+
</Project>
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Microsoft.Web.LibraryManager.Build.IntegrationTest;
11+
12+
[TestClass]
13+
public class RestoreTests : BuildTestBase
14+
{
15+
[TestMethod]
16+
public async Task Restore_LibraryWithFileMapping_NamedFiles()
17+
{
18+
string manifest = """
19+
{
20+
"version": "3.0",
21+
"defaultProvider": "jsdelivr",
22+
"libraries": [
23+
{
24+
"library": "[email protected]",
25+
"destination": "wwwroot/lib/jquery",
26+
"fileMappings": [
27+
{
28+
"files": [
29+
"dist/jquery.min.js",
30+
"dist/jquery.min.map"
31+
]
32+
}
33+
]
34+
}
35+
]
36+
}
37+
""";
38+
await CreateManifestFileAsync(manifest);
39+
40+
await RunDotnetCommandLineAsync("build", TestProjectDirectory);
41+
42+
AssertFileExists("wwwroot/lib/jquery/dist/jquery.min.js");
43+
AssertFileExists("wwwroot/lib/jquery/dist/jquery.min.map");
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project>
2+
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
3+
<PropertyGroup>
4+
5+
6+
</PropertyGroup>
7+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
3+
<Target Name="CustomAfterBuildTarget" AfterTargets="Build">
4+
<Message Text="Hello from CustomAfterBuildTarget" Importance="high" />
5+
</Target>
6+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project>
2+
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
3+
<PropertyGroup>
4+
5+
6+
</PropertyGroup>
7+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libman.Build.TestApp", "Libman.Build.TestApp\Libman.Build.TestApp.csproj", "{DB512B50-3DA7-4082-99E4-99C0ED151545}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(SolutionProperties) = preSolution
14+
HideSolutionNode = FALSE
15+
EndGlobalSection
16+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
17+
{DB512B50-3DA7-4082-99E4-99C0ED151545}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{DB512B50-3DA7-4082-99E4-99C0ED151545}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{DB512B50-3DA7-4082-99E4-99C0ED151545}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{DB512B50-3DA7-4082-99E4-99C0ED151545}.Release|Any CPU.Build.0 = Release|Any CPU
21+
EndGlobalSection
22+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
var app = builder.Build();
3+
4+
app.MapGet("/", () => "Hello World!");
5+
6+
app.Run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:13287",
8+
"sslPort": 44380
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"applicationUrl": "http://localhost:5264",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"dotnetRunMessages": true,
24+
"launchBrowser": true,
25+
"applicationUrl": "https://localhost:7009;http://localhost:5264",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
},
30+
"IIS Express": {
31+
"commandName": "IISExpress",
32+
"launchBrowser": true,
33+
"environmentVariables": {
34+
"ASPNETCORE_ENVIRONMENT": "Development"
35+
}
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
5+
<clear />
6+
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
7+
</packageSources>
8+
</configuration>

0 commit comments

Comments
 (0)