Skip to content

Commit

Permalink
chore: test for CycloneDX#911
Browse files Browse the repository at this point in the history
Signed-off-by: Jesper Olsson <[email protected]>
  • Loading branch information
jesperolsson-se authored and Jesper Olsson committed Oct 25, 2024
1 parent 3d71d1f commit 6f3d960
Show file tree
Hide file tree
Showing 7 changed files with 3,868 additions and 0 deletions.
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

0 comments on commit 6f3d960

Please sign in to comment.