Skip to content

Commit 7fbc44b

Browse files
authored
chore: run tests in parallel (#348)
* chore: run tests in parallel
1 parent bf7a559 commit 7fbc44b

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
1+
using System.Collections.Generic;
2+
13
public class PackageReference
24
{
5+
private static readonly List<PackageReference> _allDependencies = new();
6+
37
public string Name { get; }
48
public string Version { get; }
59
public string Path { get; }
610

7-
public PackageReference(string name, string version, string path) => (Name, Version, Path) = (name, version, path);
811

9-
public static PackageReference FluentAssertions_6_12_0 { get; } = FluentAssertions("6.12.0");
12+
private PackageReference(string name, string version, string path)
13+
{
14+
Name = name;
15+
Version = version;
16+
Path = path;
1017

18+
_allDependencies.Add(this);
19+
}
20+
21+
public static PackageReference FluentAssertions_6_12_0 { get; } = new("FluentAssertions", "6.12.0", "lib/netstandard2.0/");
1122
public static PackageReference MSTestTestFramework_3_1_1 { get; } = new("MSTest.TestFramework", "3.1.1", "lib/netstandard2.0/");
1223
public static PackageReference XunitAssert_2_5_1 { get; } = new("xunit.assert", "2.5.1", "lib/netstandard1.1/");
1324
public static PackageReference Nunit_3_14_0 { get; } = new("NUnit", "3.14.0", "lib/netstandard2.0/");
1425
public static PackageReference Nunit_4_0_1 { get; } = new("NUnit", "4.0.1", "lib/net6.0/");
1526

16-
public static PackageReference FluentAssertions(string version) => new("FluentAssertions", version, "lib/netstandard2.0/");
27+
internal static PackageReference NETStandard2_0 = new("NETStandard.Library", "2.0.3", "build/netstandard2.0/ref/");
28+
internal static PackageReference NETStandard2_1 = new("NETStandard.Library.Ref", "2.1.0", "ref/netstandard2.1/ref/");
29+
internal static PackageReference DotNet6 = new("Microsoft.NETCore.App.Ref", "6.0.25", "ref/net6.0/");
30+
internal static PackageReference DotNet7 = new("Microsoft.NETCore.App.Ref", "7.0.14", "ref/net7.0/");
31+
internal static PackageReference DotNet8 = new("Microsoft.NETCore.App.Ref", "8.0.0", "ref/net8.0/");
32+
33+
internal static IEnumerable<PackageReference> AllDependencies => _allDependencies;
1734
}

src/FluentAssertions.Analyzers.TestUtils/SolutionExtensions.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.IO.Compression;
4+
using System.Linq;
45
using System.Net.Http;
56
using System.Threading.Tasks;
67
using Microsoft.CodeAnalysis;
@@ -11,10 +12,11 @@ public static class SolutionExtensions
1112
?? (OperatingSystem.IsWindows() ? Environment.ExpandEnvironmentVariables("%userprofile%\\.nuget\\packages") : "~/.nuget/packages");
1213

1314
private static readonly HttpClient HttpClient = new HttpClient();
15+
private static readonly Task SetupPackages = Task.WhenAll(PackageReference.AllDependencies.Select(p => DownloadPackageAsync(p.Name, p.Version)));
1416

1517
public static Solution AddPackageReference(this Solution solution, ProjectId projectId, PackageReference package)
1618
{
17-
DownloadPackageAsync(package.Name, package.Version).GetAwaiter().GetResult();
19+
SetupPackages.GetAwaiter().GetResult();
1820

1921
var packagePath = Path.Combine(NugetPackagesPath, package.Name, package.Version, package.Path);
2022
foreach (var dll in Directory.GetFiles(packagePath, "*.dll"))
@@ -29,11 +31,11 @@ public static Solution AddTargetFrameworkReference(this Solution solution, Proje
2931
{
3032
return targetFramework switch
3133
{
32-
TargetFramework.NetStandard2_0 => solution.AddPackageReference(projectId, new("NETStandard.Library", "2.0.3", "build/netstandard2.0/ref/")),
33-
TargetFramework.NetStandard2_1 => solution.AddPackageReference(projectId, new("NETStandard.Library.Ref", "2.1.0", "ref/netstandard2.1/ref/")),
34-
TargetFramework.Net6_0 => solution.AddPackageReference(projectId, new("Microsoft.NETCore.App.Ref", "6.0.25", "ref/net6.0/")),
35-
TargetFramework.Net7_0 => solution.AddPackageReference(projectId, new("Microsoft.NETCore.App.Ref", "7.0.14", "ref/net7.0/")),
36-
TargetFramework.Net8_0 => solution.AddPackageReference(projectId, new("Microsoft.NETCore.App.Ref", "8.0.0", "ref/net8.0/")),
34+
TargetFramework.NetStandard2_0 => solution.AddPackageReference(projectId, PackageReference.NETStandard2_0),
35+
TargetFramework.NetStandard2_1 => solution.AddPackageReference(projectId, PackageReference.NETStandard2_1),
36+
TargetFramework.Net6_0 => solution.AddPackageReference(projectId, PackageReference.DotNet6),
37+
TargetFramework.Net7_0 => solution.AddPackageReference(projectId, PackageReference.DotNet7),
38+
TargetFramework.Net8_0 => solution.AddPackageReference(projectId, PackageReference.DotNet8),
3739
_ => throw new ArgumentOutOfRangeException(nameof(targetFramework), targetFramework, "Unknown target framework"),
3840
};
3941
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
3+
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]

0 commit comments

Comments
 (0)