Skip to content

Commit

Permalink
test case fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Viji committed Dec 24, 2024
1 parent 490452a commit fcccec5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/LCT.Common.UTests/CommonHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace LCT.Common.UTest
[TestFixture]
public class CommonHelperTest
{

[Test]
public void WriteComponentsNotLinkedListInConsole_PassingList_ReturnSuccess()
{
Expand Down Expand Up @@ -276,8 +276,8 @@ public void RemoveExcludedComponents_WhenExcludedComponentMatches_ReturnsExclude
List<Component> result = CommonHelper.FlagExcludedComponentsAsInternal(componentList, excludedComponents, ref noOfExcludedComponents);

// Assert
Assert.AreEqual(1, result.Count);
Assert.IsFalse(result.Any(c => c.Name == "Component1" && c.Version == "1.0"));
Assert.AreEqual(3, result.Count);
Assert.IsTrue(result.Any(c => c.Name == "Component1" && c.Version == "1.0"));
Assert.IsTrue(result.Any(c => c.Name == "Component3" && c.Version == "3.0"));
Assert.AreEqual(2, noOfExcludedComponents);
}
Expand Down
7 changes: 6 additions & 1 deletion src/LCT.Common/CommonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ public static List<Component> FlagExcludedComponentsAsInternal(List<Component> C
Property property = new Property();
property.Name = Dataconstant.Cdx_IsInternal;
property.Value = "true";
if (!component.Properties.Exists(x => x.Name.Equals(property.Name)))
if (component.Properties != null
&& !component.Properties.Exists(x => x.Name.Equals(property.Name)))
{
component.Properties.Add(property);
}
else
{
component.Properties = [property];
}

ExcludedList.Add(component);
}
Expand Down
10 changes: 5 additions & 5 deletions src/LCT.PackageIdentifier.UTest/ConanParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void ParseLockFile_GivenAInputFilePath_ReturnDevDependentComp()
public void ParseLockFile_GivenAInputFilePathExcludeComponent_ReturnComponentCount()
{
//Arrange
int totalComponentsAfterExclusion = 15;
int totalComponentsAfterExclusion = 17;
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string outFolder = Path.GetDirectoryName(exePath);
string packagefilepath = outFolder + @"\PackageIdentifierUTTestFiles";
Expand All @@ -113,14 +113,14 @@ public void ParseLockFile_GivenAInputFilePathExcludeComponent_ReturnComponentCou
Bom listofcomponents = new ConanProcessor(cycloneDXBomParser.Object).ParsePackageFile(appSettings);

//Assert
Assert.That(totalComponentsAfterExclusion, Is.EqualTo(listofcomponents.Components.Count), "Checks if the excluded components have been removed");
Assert.That(totalComponentsAfterExclusion, Is.EqualTo(listofcomponents.Components.Count), "Checks if the excluded components have not been removed");
}

[TestCase]
public void IsDevDependent_GivenListOfDevComponents_ReturnsSuccess()
{
//Arrange
var conanPackage = new ConanPackage() {Id = "10"};
var conanPackage = new ConanPackage() { Id = "10" };
var buildNodeIds = new List<string> { "10", "11", "12" };
var noOfDevDependent = 0;
//Act
Expand All @@ -135,13 +135,13 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData_Succes
{
// Arrange
Component component = new Component()
{
{
Name = "securitycommunicationmanager",
Description = string.Empty,
Version = "2.6.5",
Purl = "pkg:conan/[email protected]"
};

var components = new List<Component>() { component };
ComponentIdentification componentIdentification = new() { comparisonBOMData = components };
string[] repoList = { "internalrepo1", "internalrepo2" };
Expand Down

0 comments on commit fcccec5

Please sign in to comment.