Skip to content

Commit

Permalink
Add projects only option tests (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkolev92 authored Sep 12, 2023
1 parent 555fe1b commit a7cbfd8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Common/Common.Test/Common.Test/PackageDependencyGraphTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,30 @@ public async Task FromAssetsFile_WithProjectReferenceWithAPackageId_ParsesGraphC
ValidateBidirectionalEdges(nephewNode.Item1, nugetVersioning, VersionRange.Parse("6.3.0"));
}

[Fact]
public async Task FromAssetsFile_WithProjectsOnlyOption_IncludesProjectsOnly()
{
var assetsFileText = TestHelpers.GetResource("Common.Test.compiler.resources.nuget.common.assets.json", GetType());

var assetsFile = new LockFileFormat().Parse(assetsFileText, Path.GetTempPath());
var dependencyGraphSpec = new DependencyGraphSpec();
dependencyGraphSpec.AddProject(assetsFile.PackageSpec);
var graphs = await PackageDependencyGraph.GenerateAllDependencyGraphsFromAssetsFileAsync(assetsFile, dependencyGraphSpec, projectsOnly: true, new(), CancellationToken.None);
graphs.Should().HaveCount(2);

var graph = graphs.First().Value;
graph.Node.Identity.Id.Should().Be("NuGet.Common");
graph.Node.ParentNodes.Should().HaveCount(0);
graph.Node.ChildNodes.Should().HaveCount(1);

// Ensure NuGet.Common => NuGet.Frameworks
(Node<DependencyNodeIdentity, VersionRange>, VersionRange) nugetFrameworks = graph.Node.ChildNodes[0];
nugetFrameworks.Item1.Identity.Should().Be(new DependencyNodeIdentity("NuGet.Frameworks", new NuGetVersion(6, 4, 0, "preview.3.32767"), DependencyType.Project));
nugetFrameworks.Item1.ParentNodes.Should().HaveCount(1);
nugetFrameworks.Item1.ChildNodes.Should().HaveCount(0);
ValidateBidirectionalEdges(graph.Node, nugetFrameworks, VersionRange.Parse("6.4.0-preview.3.32767"));
}

private async Task<PackageDependencyGraph> GetOnlyDependencyGraphAsync(string resourceName)
{
var assetsFileText = TestHelpers.GetResource(resourceName, GetType());
Expand Down

0 comments on commit a7cbfd8

Please sign in to comment.