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

chore: test for #911 #912

Open
wants to merge 1 commit into
base: master
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
15 changes: 15 additions & 0 deletions CycloneDX.Tests/CycloneDX.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@
<None Update="Resources\metadata\cycloneDX-metadata-template.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="FunctionalTests\Issue911-depsOnSeveralTargetFrameworks\project1csproj.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="FunctionalTests\Issue911-depsOnSeveralTargetFrameworks\project2csproj.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="FunctionalTests\Issue911-depsOnSeveralTargetFrameworks\solution1sln.text">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="FunctionalTests\Issue911-depsOnSeveralTargetFrameworks\project1assets.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="FunctionalTests\Issue911-depsOnSeveralTargetFrameworks\project2assets.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions.TestingHelpers;
using System.Threading.Tasks;
using CycloneDX.Models;
using Xunit;

namespace CycloneDX.Tests.FunctionalTests
{
/// <summary>
/// Some dependencies reference different dependency versions based on the project's target framework.
/// For example, [email protected] references [email protected] when targeting net6.0
/// but references [email protected] when targeting net8.0
///
/// This test ensures that the generated SBOM lists both versions as children.
///
/// Given a dependency, D1, which may
/// a solution file, S1.
/// and S1 contains two project files, P1 and P2
/// and P1 targets net6.0
/// and P1 references [email protected]
/// and P2 targets net8.0
/// and P2 references [email protected]
/// When scanning S1
/// Then the dependencies of
/// [email protected] should be a child of [email protected]
/// and [email protected] should be a child of [email protected]
/// </summary>
public class DepsOnSeveralTargetFrameworks
{
private MockFileData Source(string file)
{
return new MockFileData(File.ReadAllText(
Path.Combine("FunctionalTests", "Issue911-depsOnSeveralTargetFrameworks", file)));
}

private MockFileSystem getMockFS()
{
return new MockFileSystem(new Dictionary<string, MockFileData>
{
{
MockUnixSupport.Path("c:/ProjectPath/sln.sln"), Source("solution1sln.text")
},{
MockUnixSupport.Path("c:/ProjectPath/project1/Project1.csproj"), Source("project1csproj.xml")
},{
MockUnixSupport.Path("c:/ProjectPath/project1/obj/project.assets.json"), Source("project1assets.json")
},{
MockUnixSupport.Path("c:/ProjectPath/project2/Project2.csproj"), Source("project2csproj.xml")
},{
MockUnixSupport.Path("c:/ProjectPath/project2/obj/project.assets.json"), Source("project2assets.json")
}
});
}

[Fact (Skip = "#911 is not yet corrected")]
public async Task NoExceptionHappens()
{
var options = new RunOptions
{
scanProjectReferences = true,
SolutionOrProjectFile = MockUnixSupport.Path("c:/ProjectPath/sln.sln")
};

var bom = await FunctionalTestHelper.Test(options, getMockFS());
FunctionalTestHelper.AssertHasDependencyWithChild(
bom,
"pkg:nuget/[email protected]",
"pkg:nuget/[email protected]");
FunctionalTestHelper.AssertHasDependencyWithChild(
bom,
"pkg:nuget/[email protected]",
"pkg:nuget/[email protected]");
}
}
}
Loading