Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests for CLI and Build task #790

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
58 changes: 44 additions & 14 deletions LibraryManager.sln
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "schema", "schema", "{4B7669
src\schema\libman.json = src\schema\libman.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "libman.IntegrationTest", "test\libman.IntegrationTest\libman.IntegrationTest.csproj", "{BE84C694-91F1-C170-7366-7B86EBC9B033}"
EndProject
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -72,18 +76,6 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Debug|x64.ActiveCfg = Debug|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Debug|x64.Build.0 = Debug|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Debug|x86.ActiveCfg = Debug|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Debug|x86.Build.0 = Debug|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Release|Any CPU.Build.0 = Release|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Release|x64.ActiveCfg = Release|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Release|x64.Build.0 = Release|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Release|x86.ActiveCfg = Release|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Release|x86.Build.0 = Release|Any CPU
{EDA2179C-D952-449F-9A3D-8B3A152D6E5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDA2179C-D952-449F-9A3D-8B3A152D6E5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDA2179C-D952-449F-9A3D-8B3A152D6E5A}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -96,6 +88,18 @@ Global
{EDA2179C-D952-449F-9A3D-8B3A152D6E5A}.Release|x64.Build.0 = Release|Any CPU
{EDA2179C-D952-449F-9A3D-8B3A152D6E5A}.Release|x86.ActiveCfg = Release|Any CPU
{EDA2179C-D952-449F-9A3D-8B3A152D6E5A}.Release|x86.Build.0 = Release|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Debug|x64.ActiveCfg = Debug|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Debug|x64.Build.0 = Debug|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Debug|x86.ActiveCfg = Debug|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Debug|x86.Build.0 = Debug|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Release|Any CPU.Build.0 = Release|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Release|x64.ActiveCfg = Release|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Release|x64.Build.0 = Release|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Release|x86.ActiveCfg = Release|Any CPU
{707356DD-96B9-49F6-AF2A-9D23B857A1E2}.Release|x86.Build.0 = Release|Any CPU
{08C91CC3-4057-4D76-8B9A-B6A0557B64EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08C91CC3-4057-4D76-8B9A-B6A0557B64EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08C91CC3-4057-4D76-8B9A-B6A0557B64EB}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -216,13 +220,37 @@ Global
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Release|x64.Build.0 = Release|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Release|x86.ActiveCfg = Release|Any CPU
{514120AD-8F89-476A-8AB3-F582E6CA8697}.Release|x86.Build.0 = Release|Any CPU
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Debug|x64.ActiveCfg = Debug|Any CPU
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Debug|x64.Build.0 = Debug|Any CPU
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Debug|x86.ActiveCfg = Debug|Any CPU
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Debug|x86.Build.0 = Debug|Any CPU
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Release|Any CPU.Build.0 = Release|Any CPU
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Release|x64.ActiveCfg = Release|Any CPU
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Release|x64.Build.0 = Release|Any CPU
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Release|x86.ActiveCfg = Release|Any CPU
{BE84C694-91F1-C170-7366-7B86EBC9B033}.Release|x86.Build.0 = Release|Any CPU
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Debug|x64.ActiveCfg = Debug|Any CPU
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Debug|x64.Build.0 = Debug|Any CPU
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Debug|x86.ActiveCfg = Debug|Any CPU
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Debug|x86.Build.0 = Debug|Any CPU
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Release|Any CPU.Build.0 = Release|Any CPU
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Release|x64.ActiveCfg = Release|Any CPU
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Release|x64.Build.0 = Release|Any CPU
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Release|x86.ActiveCfg = Release|Any CPU
{EC152F12-CB03-4405-D8AE-EE7FC6E32666}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{707356DD-96B9-49F6-AF2A-9D23B857A1E2} = {A72570B1-99EF-4BDD-B629-321CD56C9F7F}
{EDA2179C-D952-449F-9A3D-8B3A152D6E5A} = {A72570B1-99EF-4BDD-B629-321CD56C9F7F}
{707356DD-96B9-49F6-AF2A-9D23B857A1E2} = {A72570B1-99EF-4BDD-B629-321CD56C9F7F}
{08C91CC3-4057-4D76-8B9A-B6A0557B64EB} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
{FF466454-426B-4AD7-8B00-D50011BE716F} = {A72570B1-99EF-4BDD-B629-321CD56C9F7F}
{18F82568-446D-4729-B65E-EB9DF21C3636} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
Expand All @@ -232,8 +260,10 @@ Global
{AD605AA7-6E43-47F1-A096-1ACDF67BF1DB} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
{E9BE3307-5F07-4757-BB06-3460813D7B9D} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
{00EE7B7F-EDA3-49E6-AA38-118C15B58CDB} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
{4B76692E-EF61-499F-900F-752FFC08D6E9} = {A72570B1-99EF-4BDD-B629-321CD56C9F7F}
{514120AD-8F89-476A-8AB3-F582E6CA8697} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
{4B76692E-EF61-499F-900F-752FFC08D6E9} = {A72570B1-99EF-4BDD-B629-321CD56C9F7F}
{BE84C694-91F1-C170-7366-7B86EBC9B033} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
{EC152F12-CB03-4405-D8AE-EE7FC6E32666} = {FFCD12F4-5CE2-4CC2-A2C4-EACC8F387D7A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {720C6A7F-67F7-4D00-881F-D3CDEA7ABE69}
Expand Down
97 changes: 97 additions & 0 deletions test/LibraryManager.Build.IntegrationTest/BuildTestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Web.LibraryManager.Build.IntegrationTest;

[TestClass]
[DeploymentItem(@"TestPackages", "TestPackages")]
[DeploymentItem(@"TestSolution", "TestSolution")]
public class BuildTestBase
{
private const string BuildPackageName = "Microsoft.Web.LibraryManager.Build";
private const string ManifestFileName = "libman.json";
private const string TestProjectFolderName = "Libman.Build.TestApp";
private readonly string PackagesFolderPath = Path.Combine(Environment.CurrentDirectory, "TestPackages");
protected string TestProjectDirectory { get; private set; } = "";

[TestInitialize]
public async Task TestInitialize()
{
// test solution should be deployed with every test?
TestProjectDirectory = Path.Combine(Path.GetFullPath("TestSolution"), TestProjectFolderName);

// create an empty nuget.config with only our package source
await AddPackageReferenceAsync();
}

[TestCleanup]
public void TestCleanup()
{
if (Directory.Exists(TestProjectDirectory))
{
Directory.Delete(TestProjectDirectory, true);
}
}

protected async Task RunDotnetCommandLineAsync(string arguments, string? workingDirectory)
{
var processStartInfo = new ProcessStartInfo("dotnet", arguments)
{
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
WorkingDirectory = workingDirectory,
};

using (var process = Process.Start(processStartInfo))
{
await process.WaitForExitAsync();
if (process.ExitCode != 0)
{
string output = await process.StandardError.ReadToEndAsync() + await process.StandardOutput.ReadToEndAsync();
throw new InvalidOperationException($"CLI tool execution failed with arguments: {arguments}.\r\nOutput: {output}");
}
}
}

private async Task AddPackageReferenceAsync()
{
await RunDotnetCommandLineAsync($"nuget add source \"{PackagesFolderPath}\"", TestProjectDirectory);

await RunDotnetCommandLineAsync($"add package {BuildPackageName} --version {GetBuildPackageVersion()}", TestProjectDirectory);
}

private static string GetBuildPackageVersion()
{
return Directory.GetFiles("TestPackages", $"{BuildPackageName}.*.nupkg")
.Select(Path.GetFileNameWithoutExtension)
.Select(name => name.Substring(BuildPackageName.Length + 1))
.OrderByDescending(version => version)
.First();
}

protected async Task CreateManifestFileAsync(string content)
{
string manifestFilePath = Path.Combine(TestProjectDirectory, ManifestFileName);
await Task.Run(() => File.WriteAllText(manifestFilePath, content));
}

protected void AssertFileExists(string relativeFilePath)
{
string filePath = Path.Combine(TestProjectDirectory, relativeFilePath);
Assert.IsTrue(File.Exists(filePath), $"Expected file '{filePath}' does not exist.");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(NetCoreTFM)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
</ItemGroup>

<ItemGroup>
<!-- set build dependency so the nupkg is built for tests to consume -->
<ProjectReference Include="..\..\src\LibraryManager.Build\Microsoft.Web.LibraryManager.Build.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

<ItemGroup>
<Compile Remove="TestSolution\**\*" />
<None Remove="TestSolution\**\*" />
<Content Remove="TestSolution\**\*" />
</ItemGroup>
<ItemGroup>
<Content Include="TestSolution\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<!-- Copy the nupkgs needed to run CLI and Build package integration tests -->
<Target Name="CopyNupkgFiles" AfterTargets="Build" DependsOnTargets="GetBuildVersion">
<PropertyGroup>

</PropertyGroup>
<ItemGroup>
<BuildNupkg Include="..\..\artifacts\$(Configuration)\Microsoft.Web.LibraryManager.Build.$(PackageVersion).nupkg" />
</ItemGroup>
<Copy SourceFiles="@(BuildNupkg)" DestinationFolder="$(OutputPath)\TestPackages" />
</Target>

</Project>
45 changes: 45 additions & 0 deletions test/LibraryManager.Build.IntegrationTest/RestoreTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Web.LibraryManager.Build.IntegrationTest;

[TestClass]
public class RestoreTests : BuildTestBase
{
[TestMethod]
public async Task Restore_LibraryWithFileMapping_NamedFiles()
{
string manifest = """
{
"version": "3.0",
"defaultProvider": "jsdelivr",
"libraries": [
{
"library": "[email protected]",
"destination": "wwwroot/lib/jquery",
"fileMappings": [
{
"files": [
"dist/jquery.min.js",
"dist/jquery.min.map"
]
}
]
}
]
}
""";
await CreateManifestFileAsync(manifest);

await RunDotnetCommandLineAsync("build", TestProjectDirectory);

AssertFileExists("wwwroot/lib/jquery/dist/jquery.min.js");
AssertFileExists("wwwroot/lib/jquery/dist/jquery.min.map");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
<PropertyGroup>


</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
<Target Name="CustomAfterBuildTarget" AfterTargets="Build">
<Message Text="Hello from CustomAfterBuildTarget" Importance="high" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
<PropertyGroup>


</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libman.Build.TestApp", "Libman.Build.TestApp\Libman.Build.TestApp.csproj", "{DB512B50-3DA7-4082-99E4-99C0ED151545}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DB512B50-3DA7-4082-99E4-99C0ED151545}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB512B50-3DA7-4082-99E4-99C0ED151545}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB512B50-3DA7-4082-99E4-99C0ED151545}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB512B50-3DA7-4082-99E4-99C0ED151545}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:13287",
"sslPort": 44380
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5264",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7009;http://localhost:5264",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Loading