Skip to content

Commit 2bae92c

Browse files
author
Aditya Narayan
committed
Refactor path construction for platform independence
Updated file path construction to use `Path.GetFullPath` and `Path.Combine` instead of string concatenation with backslashes. This change enhances the robustness and platform independence of the code. - Updated paths in `PackageUploadHelperTest.cs`, `CycloneBomProcessorTests.cs`, `DebianParserTests.cs`, `DisplayInformationTests.cs`, `MavenParserTests.cs`, `NPMParserTests.cs`, `NugetParserTests.cs`, and `ScannerTests.cs`. - Changed `ProjectName` from "test" to "Test" in `PackageUploaderTest.cs`.
1 parent 7510d2f commit 2bae92c

File tree

9 files changed

+38
-38
lines changed

9 files changed

+38
-38
lines changed

src/AritfactoryUploader.UTest/PackageUploadHelperTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void UpdateBomArtifactoryRepoUrl_GivenBomAndComponentsUploadedToArtifacto
115115
//Arrange
116116
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
117117
string outFolder = Path.GetDirectoryName(exePath);
118-
string comparisonBOMPath = outFolder + @"\ArtifactoryUTTestFiles\Test_Bom.cdx.json";
118+
string comparisonBOMPath = Path.GetFullPath(Path.Combine(outFolder, "ArtifactoryUTTestFiles", "Test_Bom.cdx.json"));
119119
Bom bom = PackageUploadHelper.GetComponentListFromComparisonBOM(comparisonBOMPath);
120120
List<ComponentsToArtifactory> components = new List<ComponentsToArtifactory>()
121121
{

src/AritfactoryUploader.UTest/PackageUploaderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public async Task UploadPackageToArtifactory_GivenAppsettings()
7474
commonAppSettings.TimeOut = 100;
7575
commonAppSettings.SW360 = new SW360()
7676
{
77-
ProjectName = "test"
77+
ProjectName = "Test"
7878
};
7979

8080
IJFrogService jFrogService = GetJfrogService(commonAppSettings);

src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void ParseCycloneDXBom_GivenBOMFilePath_ReturnsBOM()
153153
//Arrange
154154
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
155155
string outFolder = Path.GetDirectoryName(exePath);
156-
string BomTestFile = outFolder + @"\PackageIdentifierUTTestFiles\CycloneDX_Debian.cdx.json";
156+
string BomTestFile = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles", "CycloneDX_Debian.cdx.json"));
157157

158158
//Act
159159
CycloneDXBomParser cycloneBomProcessor = new CycloneDXBomParser();
@@ -170,7 +170,7 @@ public void ParseCycloneDXBom_GivenInvlidBOMFilePath_ReturnsZeroComponents()
170170
//Arrange
171171
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
172172
string outFolder = Path.GetDirectoryName(exePath);
173-
string BomTestFile = outFolder + @"\PackageIdentifierUTTestFiles\Cyclonedx1.json";
173+
string BomTestFile = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles", "Cyclonedx1.json"));
174174

175175
//Act
176176
CycloneDXBomParser cycloneBomProcessor = new CycloneDXBomParser();

src/LCT.PackageIdentifier.UTest/DebianParserTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void ParsePackageConfig_GivenAMultipleInputFilePath_ReturnsCounts()
137137
SW360 = new SW360() { IgnoreDevDependency = true },
138138
Directory = new LCT.Common.Directory(folderAction, fileOperations)
139139
{
140-
InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles"
140+
InputFolder = Path.GetFullPath(Path.Combine(OutFolder, "PackageIdentifierUTTestFiles"))
141141
}
142142
};
143143

@@ -169,7 +169,7 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsCounts()
169169
SW360 = new SW360() { IgnoreDevDependency = true },
170170
Directory = new LCT.Common.Directory(folderAction, fileOperations)
171171
{
172-
InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles"
172+
InputFolder = Path.GetFullPath(Path.Combine(OutFolder, "PackageIdentifierUTTestFiles"))
173173
}
174174
};
175175

@@ -198,7 +198,7 @@ public void ParsePackageConfig_GivenMultipleInputFiles_ReturnsCountOfDuplicates(
198198
SW360 = new SW360() { IgnoreDevDependency = true },
199199
Directory = new LCT.Common.Directory(folderAction, fileOperations)
200200
{
201-
InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles"
201+
InputFolder = Path.GetFullPath(Path.Combine(OutFolder, "PackageIdentifierUTTestFiles"))
202202
}
203203
};
204204

@@ -227,7 +227,7 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsSourceDetails()
227227
SW360 = new SW360() { IgnoreDevDependency = true },
228228
Directory = new LCT.Common.Directory(folderAction, fileOperations)
229229
{
230-
InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles"
230+
InputFolder = Path.GetFullPath(Path.Combine(OutFolder, "PackageIdentifierUTTestFiles"))
231231
}
232232
};
233233

@@ -246,7 +246,7 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTo
246246
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
247247
string OutFolder = Path.GetDirectoryName(exePath);
248248
string[] Includes = { "CycloneDX_Debian.cdx.json", "SBOMTemplate_Debian.cdx.json", "SBOM_DebianCATemplate.cdx.json" };
249-
string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles";
249+
string packagefilepath = Path.GetFullPath(Path.Combine(OutFolder, "PackageIdentifierUTTestFiles"));
250250

251251
IFolderAction folderAction = new FolderAction();
252252
IFileOperations fileOperations = new FileOperations();
@@ -276,7 +276,7 @@ public void ParsePackageConfig_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUp
276276
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
277277
string OutFolder = Path.GetDirectoryName(exePath);
278278
string[] Includes = { "CycloneDX_Debian.cdx.json", "SBOMTemplate_Debian.cdx.json" };
279-
string packagefilepath = OutFolder + @"\PackageIdentifierUTTestFiles";
279+
string packagefilepath = Path.GetFullPath(Path.Combine(OutFolder, "PackageIdentifierUTTestFiles"));
280280

281281
IFolderAction folderAction = new FolderAction();
282282
IFileOperations fileOperations = new FileOperations();

src/LCT.PackageIdentifier.UTest/DisplayInformationTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public void LogInputParameters_ShouldLogCorrectMessage_WhenBasicSBOMIsFalse()
5151

5252
Directory = new LCT.Common.Directory(folderAction, fileOperations)
5353
{
54-
InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles",
55-
OutputFolder = OutFolder + @"\PackageIdentifierUTTestFiles"
54+
InputFolder = Path.GetFullPath(Path.Combine(OutFolder, "PackageIdentifierUTTestFiles")),
55+
OutputFolder = Path.GetFullPath(Path.Combine(OutFolder, "PackageIdentifierUTTestFiles"))
5656
}
5757
};
5858
caToolInformation = new CatoolInfo
@@ -104,8 +104,8 @@ public void LogInputParameters_ShouldLogCorrectMessage_WhenBasicSBOMIsTrue()
104104
ProjectType = "NPM",
105105
Directory = new LCT.Common.Directory(folderAction, fileOperations)
106106
{
107-
InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles",
108-
OutputFolder = OutFolder + @"\PackageIdentifierUTTestFiles"
107+
InputFolder = Path.GetFullPath(Path.Combine(OutFolder, "PackageIdentifierUTTestFiles")),
108+
OutputFolder = Path.GetFullPath(Path.Combine(OutFolder, "PackageIdentifierUTTestFiles"))
109109
}
110110

111111
};
@@ -154,8 +154,8 @@ public void LogInputParameters_ShouldLogCorrectMessage_WhenJfrogIsTrue()
154154
Jfrog = new Jfrog(),
155155
Directory = new LCT.Common.Directory(folderAction, fileOperations)
156156
{
157-
InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles",
158-
OutputFolder = OutFolder + @"\PackageIdentifierUTTestFiles"
157+
InputFolder = Path.GetFullPath(Path.Combine(OutFolder, "PackageIdentifierUTTestFiles")),
158+
OutputFolder = Path.GetFullPath(Path.Combine(OutFolder, "PackageIdentifierUTTestFiles"))
159159
}
160160
};
161161
caToolInformation = new CatoolInfo

src/LCT.PackageIdentifier.UTest/MavenParserTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void ParsePackageFile_PackageLockWithDuplicateComponents_ReturnsCountOfDu
118118
//Arrange
119119
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
120120
string outFolder = Path.GetDirectoryName(exePath);
121-
string filepath = outFolder + @"\PackageIdentifierUTTestFiles";
121+
string filepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles"));
122122
string[] Includes = { "*_Maven.cdx.json" };
123123
string[] Excludes = { "lol" };
124124

@@ -406,7 +406,7 @@ public void DevDependencyIdentificationLogic_ReturnsCountOfDevDependentcomponent
406406
//Arrange
407407
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
408408
string outFolder = Path.GetDirectoryName(exePath);
409-
string filepath = outFolder + @"\PackageIdentifierUTTestFiles\MavenDevDependency\WithDev";
409+
string filepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles", "MavenDevDependency", "WithDev"));
410410
string[] Includes = { "*.cdx.json" };
411411
string[] Excludes = { "lol" };
412412

@@ -438,7 +438,7 @@ public void DevDependencyIdentificationLogic_ReturnsCountOfComponents_WithoutDev
438438
//Arrange
439439
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
440440
string outFolder = Path.GetDirectoryName(exePath);
441-
string filepath = outFolder + @"\PackageIdentifierUTTestFiles\MavenDevDependency\WithOneInputFile";
441+
string filepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles", "MavenDevDependency", "WithOneInputFile"));
442442
string[] Includes = { "*.cdx.json" };
443443
string[] Excludes = { "lol" };
444444

@@ -472,7 +472,7 @@ public void ParsePackageFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTota
472472
int expectednoofcomponents = 1;
473473
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
474474
string outFolder = Path.GetDirectoryName(exePath);
475-
string filepath = outFolder + @"\PackageIdentifierUTTestFiles";
475+
string filepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles"));
476476
string[] Includes = { "CycloneDX_Maven.cdx.json", "SBOMTemplate_Maven.cdx.json", "SBOM_MavenCATemplate.cdx.json" };
477477
string[] Excludes = { "lol" };
478478

@@ -506,7 +506,7 @@ public void ParsePackageFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUpda
506506
//Arrange
507507
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
508508
string outFolder = Path.GetDirectoryName(exePath);
509-
string filepath = outFolder + @"\PackageIdentifierUTTestFiles";
509+
string filepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles"));
510510
string[] Includes = { "CycloneDX_Maven.cdx.json" };
511511
string[] Excludes = { "lol" };
512512

src/LCT.PackageIdentifier.UTest/NPMParserTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void ParsePackageFile_PackageLockWithDuplicateComponents_ReturnsCountOfDu
2727
//Arrange
2828
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
2929
string outFolder = Path.GetDirectoryName(exePath);
30-
string filepath = outFolder + @"\PackageIdentifierUTTestFiles\TestDir";
30+
string filepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles", "TestDir"));
3131
string[] Includes = { "p*-lock.json" };
3232
string[] Excludes = { "node_modules" };
3333

@@ -61,7 +61,7 @@ public void ParsePackageFile_PackageLockWithangular16_ReturnsCountOfComponents()
6161
//Arrange
6262
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
6363
string outFolder = Path.GetDirectoryName(exePath);
64-
string filepath = outFolder + @"\PackageIdentifierUTTestFiles";
64+
string filepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles"));
6565
string[] Includes = { "p*-lock16.json" };
6666
string[] Excludes = { "node_modules" };
6767

@@ -96,7 +96,7 @@ public void ParsePackageFile_PackageLockWithoutDuplicateComponents_ReturnsCountZ
9696
//Arrange
9797
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
9898
string outFolder = Path.GetDirectoryName(exePath);
99-
string filepath = outFolder + @"\PackageIdentifierUTTestFiles\TestDir\DupDir";
99+
string filepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles", "TestDir", "DupDir"));
100100
string[] Includes = { "p*-lock.json" };
101101
string[] Excludes = { "node_modules" };
102102
BomKpiData bomKpiData = new BomKpiData();
@@ -145,7 +145,7 @@ public void ParseCycloneDXFile_GivenMultipleInputFiles_ReturnsCounts()
145145
SW360 = new SW360() { IgnoreDevDependency = true },
146146
Directory = new LCT.Common.Directory(folderAction, fileOperations)
147147
{
148-
InputFolder = outFolder + @"\PackageIdentifierUTTestFiles",
148+
InputFolder = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles")),
149149
OutputFolder = outFolder
150150
}
151151
};
@@ -167,7 +167,7 @@ public void ParseCycloneDXFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnTo
167167
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
168168
NpmProcessor npmProcessor = new NpmProcessor(cycloneDXBomParser.Object);
169169
string[] Includes = { "CycloneDX2_NPM.cdx.json", "SBOMTemplate_Npm.cdx.json", "SBOM_NpmCATemplate.cdx.json" };
170-
string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles";
170+
string packagefilepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles"));
171171

172172
IFolderAction folderAction = new FolderAction();
173173
IFileOperations fileOperations = new FileOperations();
@@ -200,7 +200,7 @@ public void ParseCycloneDXFile_GivenAInputFilePathAlongWithSBOMTemplate_ReturnUp
200200
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
201201
NpmProcessor npmProcessor = new NpmProcessor(cycloneDXBomParser.Object);
202202
string[] Includes = { "CycloneDX2_NPM.cdx.json" };
203-
string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles";
203+
string packagefilepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles"));
204204

205205
IFolderAction folderAction = new FolderAction();
206206
IFileOperations fileOperations = new FileOperations();

src/LCT.PackageIdentifier.UTest/NugetParserTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsSuccess()
400400
int expectednoofcomponents = 7;
401401
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
402402
string outFolder = Path.GetDirectoryName(exePath);
403-
string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles\packages.config";
403+
string packagefilepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles", "packages.config"));
404404

405405
IFolderAction folderAction = new FolderAction();
406406
IFileOperations fileOperations = new FileOperations();
@@ -410,7 +410,7 @@ public void ParsePackageConfig_GivenAInputFilePath_ReturnsSuccess()
410410
SW360 = new SW360(),
411411
Directory = new LCT.Common.Directory(folderAction, fileOperations)
412412
{
413-
InputFolder = outFolder + @"\PackageIdentifierUTTestFiles"
413+
InputFolder = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles"))
414414
}
415415
};
416416

@@ -435,7 +435,7 @@ public void InputFileIdentifaction_GivenARootPath_ReturnsSuccess()
435435
};
436436
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
437437
string outFolder = Path.GetDirectoryName(exePath);
438-
string folderfilepath = outFolder + @"\PackageIdentifierUTTestFiles";
438+
string folderfilepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles"));
439439

440440
//Act
441441
List<string> allFoundConfigFiles = FolderScanner.FileScanner(folderfilepath, config);
@@ -458,7 +458,7 @@ public void InputFileIdentifaction_GivenIncludeFileAsNull_ReturnsArgumentNullExc
458458
};
459459
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
460460
string outFolder = Path.GetDirectoryName(exePath);
461-
string folderfilepath = outFolder + @"\PackageIdentifierUTTestFiles";
461+
string folderfilepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles"));
462462

463463
//Act & Assert
464464
Assert.Throws(typeof(ArgumentNullException), () => FolderScanner.FileScanner(folderfilepath, config));
@@ -493,7 +493,7 @@ public void InputFileIdentifaction_GivenInvalidInputFile_ReturnsArgumentNullExce
493493
Exclude = null
494494

495495
};
496-
string folderfilepath = @"../PackageIdentifierUTTestFiles";
496+
string folderfilepath = Path.GetFullPath(Path.Combine("..", "PackageIdentifierUTTestFiles"));
497497

498498
//Act & Assert
499499
Assert.Throws(typeof(DirectoryNotFoundException), () => FolderScanner.FileScanner(folderfilepath, config));
@@ -520,7 +520,7 @@ public void Parsecsproj_GivenXMLFile_ReturnsSuccess()
520520
//Arrange
521521
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
522522
string outFolder = Path.GetDirectoryName(exePath);
523-
string csprojfilepath = outFolder + @"\PackageIdentifierUTTestFiles";
523+
string csprojfilepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles"));
524524
string[] Excludes = null;
525525
IFolderAction folderAction = new FolderAction();
526526
IFileOperations fileOperations = new FileOperations();
@@ -555,7 +555,7 @@ public void RemoveExcludedComponents_ReturnsUpdatedBom()
555555
//Arrange
556556
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
557557
string outFolder = Path.GetDirectoryName(exePath);
558-
string csprojfilepath = outFolder + @"\PackageIdentifierUTTestFiles";
558+
string csprojfilepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles"));
559559
string[] Excludes = null;
560560

561561
Bom bom = new Bom();
@@ -1055,7 +1055,7 @@ public void ParseProjectAssetFile_GivenAInputFilePath_ReturnsSuccess()
10551055
int expectednoofcomponents = 2;
10561056
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
10571057
string outFolder = Path.GetDirectoryName(exePath);
1058-
string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles";
1058+
string packagefilepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles"));
10591059

10601060
string[] Includes = { "project.assets.json" };
10611061
IFolderAction folderAction = new FolderAction();
@@ -1086,7 +1086,7 @@ public void ParseProjectAssetFile_GivenAInputFilePath_ReturnDevDependentComp()
10861086
string IsDev = "true";
10871087
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
10881088
string outFolder = Path.GetDirectoryName(exePath);
1089-
string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles";
1089+
string packagefilepath = Path.GetFullPath(Path.Combine(outFolder, "PackageIdentifierUTTestFiles"));
10901090

10911091
string[] Includes = { "project.assets.json" };
10921092

0 commit comments

Comments
 (0)