diff --git a/src/LCT.Common.UTests/CommonHelperTest.cs b/src/LCT.Common.UTests/CommonHelperTest.cs index 2df2dca0..5d37ff3b 100644 --- a/src/LCT.Common.UTests/CommonHelperTest.cs +++ b/src/LCT.Common.UTests/CommonHelperTest.cs @@ -16,7 +16,7 @@ namespace LCT.Common.UTest [TestFixture] public class CommonHelperTest { - + [Test] public void WriteComponentsNotLinkedListInConsole_PassingList_ReturnSuccess() { @@ -276,8 +276,8 @@ public void RemoveExcludedComponents_WhenExcludedComponentMatches_ReturnsExclude List 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); } diff --git a/src/LCT.Common/CommonHelper.cs b/src/LCT.Common/CommonHelper.cs index 9987546f..8a5615a2 100644 --- a/src/LCT.Common/CommonHelper.cs +++ b/src/LCT.Common/CommonHelper.cs @@ -60,10 +60,15 @@ public static List FlagExcludedComponentsAsInternal(List 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); } diff --git a/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs b/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs index 5f747fcb..1e73d791 100644 --- a/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs +++ b/src/LCT.PackageIdentifier.UTest/ConanParserTests.cs @@ -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"; @@ -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 { "10", "11", "12" }; var noOfDevDependent = 0; //Act @@ -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/securitycommunicationmanager@2.6.5" }; - + var components = new List() { component }; ComponentIdentification componentIdentification = new() { comparisonBOMData = components }; string[] repoList = { "internalrepo1", "internalrepo2" };