forked from tomchavakis/nuget-license
-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ReferencedPackagesReaderIntegrationTest.cs
78 lines (62 loc) · 3.05 KB
/
ReferencedPackagesReaderIntegrationTest.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
69
70
71
72
73
74
75
76
77
78
using NuGetUtility.ReferencedPackagesReader;
using NuGetUtility.Wrapper.MsBuildWrapper;
using NuGetUtility.Wrapper.NuGetWrapper.ProjectModel;
using NuGetUtility.Wrapper.NuGetWrapper.Packaging.Core;
namespace NuGetUtility.Test.ReferencedPackagesReader
{
[TestFixture]
public class ReferencedPackagesReaderIntegrationTest
{
[SetUp]
public void SetUp()
{
_uut = new ReferencedPackageReader(new MsBuildAbstraction(), new LockFileFactory());
}
private ReferencedPackageReader? _uut;
[Test]
public void GetInstalledPackagesShould_ReturnPackagesForActualProjectCorrectly()
{
string path = Path.GetFullPath("../../../../targets/PackageReferenceProject/PackageReferenceProject.csproj");
IEnumerable<PackageIdentity> result = _uut!.GetInstalledPackages(path, false);
Assert.That(result.Count, Is.EqualTo(1));
}
[Test]
public void GetInstalledPackagesShould_ReturnTransitivePackages()
{
string path = Path.GetFullPath(
"../../../../targets/ProjectWithTransitiveReferences/ProjectWithTransitiveReferences.csproj");
IEnumerable<PackageIdentity> result = _uut!.GetInstalledPackages(path, true);
Assert.That(result.Count, Is.EqualTo(1));
}
[Test]
public void GetInstalledPackagesShould_ReturnTransitiveNuget()
{
string path = Path.GetFullPath(
"../../../../targets/ProjectWithTransitiveNuget/ProjectWithTransitiveNuget.csproj");
PackageIdentity[] result = _uut!.GetInstalledPackages(path, true).ToArray();
Assert.That(result.Count, Is.EqualTo(3));
string[] titles = result.Select(metadata => metadata.Id).ToArray();
Assert.That(titles.Contains("NSubstitute"), Is.True);
Assert.That(titles.Contains("Castle.Core"), Is.True);
Assert.That(titles.Contains("System.Diagnostics.EventLog"), Is.True);
}
[Test]
public void GetInstalledPackagesShould_ReturnEmptyEnumerableForProjectsWithoutPackages()
{
string path = Path.GetFullPath(
"../../../../targets/ProjectWithoutNugetReferences/ProjectWithoutNugetReferences.csproj");
IEnumerable<PackageIdentity> result = _uut!.GetInstalledPackages(path, false);
Assert.That(result.Count, Is.EqualTo(0));
}
[Test]
[Platform(Include = "Win")]
public void GetInstalledPackagesShould_ThrowMsBuildAbstractionException_If_ProjectUsesPackagesConfig()
{
string path = Path.GetFullPath("../../../../targets/PackagesConfigProject/PackagesConfigProject.csproj");
MsBuildAbstractionException? exception = Assert.Throws<MsBuildAbstractionException>(() => _uut!.GetInstalledPackages(path, false));
Assert.AreEqual(
$"Invalid project structure detected. Currently only PackageReference projects are supported (Project: {path})",
exception?.Message);
}
}
}