Skip to content

Commit

Permalink
Add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coderpatros committed Nov 22, 2020
1 parent 58b43dd commit 4f6a769
Show file tree
Hide file tree
Showing 11 changed files with 9,090 additions and 1 deletion.
14 changes: 14 additions & 0 deletions cyclonedx-cli.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cyclonedx", "cyclonedx\cyclonedx.csproj", "{14FDEC6A-9E00-4CDD-ACD5-EDD7CA4C3741}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cyclonedx.tests", "cyclonedx.tests\cyclonedx.tests.csproj", "{ECBAD4BF-D6CC-440D-BA01-98E164B54A12}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,6 +38,18 @@ Global
{14FDEC6A-9E00-4CDD-ACD5-EDD7CA4C3741}.Release|x64.Build.0 = Release|Any CPU
{14FDEC6A-9E00-4CDD-ACD5-EDD7CA4C3741}.Release|x86.ActiveCfg = Release|Any CPU
{14FDEC6A-9E00-4CDD-ACD5-EDD7CA4C3741}.Release|x86.Build.0 = Release|Any CPU
{ECBAD4BF-D6CC-440D-BA01-98E164B54A12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ECBAD4BF-D6CC-440D-BA01-98E164B54A12}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECBAD4BF-D6CC-440D-BA01-98E164B54A12}.Debug|x64.ActiveCfg = Debug|Any CPU
{ECBAD4BF-D6CC-440D-BA01-98E164B54A12}.Debug|x64.Build.0 = Debug|Any CPU
{ECBAD4BF-D6CC-440D-BA01-98E164B54A12}.Debug|x86.ActiveCfg = Debug|Any CPU
{ECBAD4BF-D6CC-440D-BA01-98E164B54A12}.Debug|x86.Build.0 = Debug|Any CPU
{ECBAD4BF-D6CC-440D-BA01-98E164B54A12}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECBAD4BF-D6CC-440D-BA01-98E164B54A12}.Release|Any CPU.Build.0 = Release|Any CPU
{ECBAD4BF-D6CC-440D-BA01-98E164B54A12}.Release|x64.ActiveCfg = Release|Any CPU
{ECBAD4BF-D6CC-440D-BA01-98E164B54A12}.Release|x64.Build.0 = Release|Any CPU
{ECBAD4BF-D6CC-440D-BA01-98E164B54A12}.Release|x86.ActiveCfg = Release|Any CPU
{ECBAD4BF-D6CC-440D-BA01-98E164B54A12}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
85 changes: 85 additions & 0 deletions cyclonedx.tests/ConvertTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Xunit;
using Snapshooter;
using Snapshooter.Xunit;
using CycloneDX.CLI;

namespace CycloneDX.CLI.Tests
{
public class ConvertTests
{
[Fact]
public async Task CanConvertFromXmlToJson()
{
using (var tempDirectory = new TempDirectory())
{
var outputFilename = Path.Combine(tempDirectory.DirectoryPath, "bom.json");
var exitCode = await Program.Convert(
Path.Combine("Resources", "bom-1.2.xml"),
outputFilename,
Models.InputFormat.autodetect,
Commands.ConvertOutputFormat.autodetect);

Assert.Equal(0, exitCode);
var bom = File.ReadAllText(outputFilename);
Snapshot.Match(bom);
}
}

[Fact]
public async Task CanConvertFromJsonToXml()
{
using (var tempDirectory = new TempDirectory())
{
var outputFilename = Path.Combine(tempDirectory.DirectoryPath, "bom.xml");
var exitCode = await Program.Convert(
Path.Combine("Resources", "bom-1.2.json"),
outputFilename,
Models.InputFormat.autodetect,
Commands.ConvertOutputFormat.autodetect);

Assert.Equal(0, exitCode);
var bom = File.ReadAllText(outputFilename);
Snapshot.Match(bom);
}
}

[Fact]
public async Task CanConvertToSpdxTag_v2_1()
{
using (var tempDirectory = new TempDirectory())
{
var outputFilename = Path.Combine(tempDirectory.DirectoryPath, "bom.txt");
var exitCode = await Program.Convert(
Path.Combine("Resources", "bom-1.2.xml"),
outputFilename,
Models.InputFormat.autodetect,
Commands.ConvertOutputFormat.spdxtag_v2_1);

Assert.Equal(0, exitCode);
var bom = File.ReadAllText(outputFilename);
Snapshot.Match(bom);
}
}

[Fact]
public async Task CanConvertToSpdxTag_v2_2()
{
using (var tempDirectory = new TempDirectory())
{
var outputFilename = Path.Combine(tempDirectory.DirectoryPath, "bom.txt");
var exitCode = await Program.Convert(
Path.Combine("Resources", "bom-1.2.xml"),
outputFilename,
Models.InputFormat.autodetect,
Commands.ConvertOutputFormat.spdxtag_v2_2);

Assert.Equal(0, exitCode);
var bom = File.ReadAllText(outputFilename);
Snapshot.Match(bom);
}
}
}
}
Loading

0 comments on commit 4f6a769

Please sign in to comment.