Skip to content

Commit 11881ce

Browse files
author
Aditya Narayan
committed
Refactor file path construction for robustness
Updated file path construction to use `Path.GetFullPath` and `Path.Combine` instead of string concatenation. This change affects the `Setup` and test methods in `ComponentCreatorInitialAlpine.cs`, `PackageIdentifierBasicSBOMAlpine.cs`, and `PackageIdentifierInitialAlpine.cs`. These updates enhance code maintainability and cross-platform compatibility.
1 parent 414c59a commit 11881ce

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/SW360IntegrationTest/Alpine/ComponentCreatorInitialAlpine.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public void Setup()
2929
{
3030
testParameters = new TestParamAlpine();
3131
OutFolder = TestHelper.OutFolder;
32-
CCTComparisonBomTestFile = OutFolder + @"..\..\..\src\SW360IntegrationTest\PackageCreatorTestFiles\Alpine\CCTComparisonBOMAlpineInitial.json";
32+
CCTComparisonBomTestFile = Path.GetFullPath(Path.Combine(OutFolder, "..", "..", "..", "src", "SW360IntegrationTest", "PackageCreatorTestFiles", "Alpine", "CCTComparisonBOMAlpineInitial.json"));
3333

3434
if (!TestHelper.BOMCreated)
3535
{
3636
OutFolder = TestHelper.OutFolder;
37-
string packagejsonPath = OutFolder + @"\..\..\TestFiles\IntegrationTestFiles\SystemTest1stIterationData\Alpine";
38-
string bomPath = OutFolder + @"\..\BOMs";
37+
string packagejsonPath = Path.GetFullPath(Path.Combine(OutFolder, "..", "..", "TestFiles", "IntegrationTestFiles", "SystemTest1stIterationData", "Alpine"));
38+
string bomPath = Path.GetFullPath(Path.Combine(OutFolder, "..", "BOMs"));
3939
TestHelper.RunBOMCreatorExe(new string[]{
4040
TestConstant.PackageFilePath, packagejsonPath,
4141
TestConstant.BomFolderPath, bomPath,
@@ -55,7 +55,7 @@ public void Setup()
5555
[Test, Order(1)]
5656
public void ComponentCreatorExe_ProvidedBOMFilePath_ReturnsSuccess()
5757
{
58-
string bomPath = OutFolder + $"\\..\\BOMs";
58+
string bomPath = Path.GetFullPath(Path.Combine(OutFolder, "..", "BOMs"));
5959
// Assert
6060
// Check exit is normal
6161
Assert.AreEqual(0, TestHelper.RunComponentCreatorExe(new string[] {
@@ -82,7 +82,7 @@ public void TestComparisionBOMUpdation()
8282
expected.Read(CCTComparisonBomTestFile);
8383

8484
// Actual
85-
string generatedBOM = OutFolder + $"\\..\\BOMs\\{testParameters.SW360ProjectName}_Bom.cdx.json";
85+
string generatedBOM = Path.GetFullPath(Path.Combine(OutFolder, "..", "BOMs", $"{testParameters.SW360ProjectName}_Bom.cdx.json"));
8686
if (File.Exists(generatedBOM))
8787
{
8888

src/SW360IntegrationTest/Alpine/PackageIdentifierBasicSBOMAlpine.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ public void Setup()
1717
{
1818
OutFolder = TestHelper.OutFolder;
1919

20-
CCTLocalBomTestFile = OutFolder + @"..\..\..\src\SW360IntegrationTest\PackageIdentifierTestFiles\Alpine\CCTLocalBOMAlpineInitial.json";
20+
CCTLocalBomTestFile = Path.GetFullPath(Path.Combine(OutFolder, "..", "..", "..", "src", "SW360IntegrationTest", "PackageIdentifierTestFiles", "Alpine", "CCTLocalBOMAlpineInitial.json"));
2121

22-
if (!Directory.Exists(OutFolder + @"\..\BOMs"))
22+
if (!Directory.Exists(Path.Combine(OutFolder, "..", "BOMs")))
2323
{
24-
Directory.CreateDirectory(OutFolder + @"\..\BOMs");
24+
Directory.CreateDirectory(Path.Combine(OutFolder, "..", "BOMs"));
2525
}
2626
testParameters = new TestParamAlpine();
2727
}
2828

2929
[Test, Order(1)]
3030
public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess()
3131
{
32-
string packagejsonPath = OutFolder + @"\..\..\TestFiles\IntegrationTestFiles\SystemTest1stIterationData\Alpine";
33-
string bomPath = OutFolder + @"\..\BOMs";
32+
string packagejsonPath = Path.GetFullPath(Path.Combine(OutFolder, "..", "..", "TestFiles", "IntegrationTestFiles", "SystemTest1stIterationData", "Alpine"));
33+
string bomPath = Path.GetFullPath(Path.Combine(OutFolder, "..", "BOMs"));
3434
string appsettingsFilePath = @"BasicSBOMAppsettingsTest.json";
3535

3636
// Test BOM Creator ran with exit code 0
@@ -53,7 +53,7 @@ public void LocalBOMCreation_AfterSuccessfulExeRun_ReturnsSuccess()
5353
expected.Read(CCTLocalBomTestFile);
5454

5555
// Actual
56-
string generatedBOM = OutFolder + $"\\..\\BOMs\\ContinuousClearing_Bom.cdx.json";
56+
string generatedBOM = Path.GetFullPath(Path.Combine(OutFolder, "..", "BOMs", "ContinuousClearing_Bom.cdx.json"));
5757
if (File.Exists(generatedBOM))
5858
{
5959
fileExist = true;

src/SW360IntegrationTest/Alpine/PackageIdentifierInitialAlpine.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,21 @@ public void Setup()
2626
{
2727
OutFolder = TestHelper.OutFolder;
2828

29-
CCTLocalBomTestFile = OutFolder + @"..\..\..\src\SW360IntegrationTest\PackageIdentifierTestFiles\Alpine\CCTLocalBOMAlpineInitial.json";
29+
CCTLocalBomTestFile = Path.GetFullPath(Path.Combine(OutFolder, "..", "..", "..", "src", "SW360IntegrationTest", "PackageIdentifierTestFiles", "Alpine", "CCTLocalBOMAlpineInitial.json"));
3030

31-
if (!Directory.Exists(OutFolder + @"\..\BOMs"))
31+
if (!Directory.Exists(Path.GetFullPath(Path.Combine(OutFolder, "..", "BOMs"))))
3232
{
33-
Directory.CreateDirectory(OutFolder + @"\..\BOMs");
33+
Directory.CreateDirectory(Path.GetFullPath(Path.Combine(OutFolder, "..", "BOMs")));
3434
}
3535
testParameters = new TestParamAlpine();
3636
}
3737

3838
[Test, Order(1)]
3939
public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess()
4040
{
41-
string packagejsonPath = OutFolder + @"\..\..\TestFiles\IntegrationTestFiles\SystemTest1stIterationData\Alpine";
42-
string bomPath = OutFolder + @"\..\BOMs";
41+
string packagejsonPath = Path.GetFullPath(Path.Combine(OutFolder, "..", "..", "TestFiles", "IntegrationTestFiles", "SystemTest1stIterationData", "Alpine"));
42+
string bomPath = Path.GetFullPath(Path.Combine(OutFolder, "..", "BOMs"));
43+
4344

4445
// Test BOM Creator ran with exit code 0
4546
Assert.AreEqual(0, TestHelper.RunBOMCreatorExe(new string[]{
@@ -70,7 +71,7 @@ public void LocalBOMCreation_AfterSuccessfulExeRun_ReturnsSuccess()
7071
expected.Read(CCTLocalBomTestFile);
7172

7273
// Actual
73-
string generatedBOM = OutFolder + $"\\..\\BOMs\\{testParameters.SW360ProjectName}_Bom.cdx.json";
74+
string generatedBOM = Path.GetFullPath(Path.Combine(OutFolder, "..", "BOMs", $"{testParameters.SW360ProjectName}_Bom.cdx.json"));
7475
if (File.Exists(generatedBOM))
7576
{
7677
fileExist = true;

0 commit comments

Comments
 (0)