Skip to content

Commit

Permalink
unit test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Viji committed Sep 29, 2024
1 parent b008177 commit 99437b8
Show file tree
Hide file tree
Showing 26 changed files with 90 additions and 70 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,6 @@ ASALocalRun/
/Build/runtime/nuget.exe
/Build/runtime/tempNuGet.config
/src/out/netcoreapp3.1
/src/.sonarlint
/src/.sonarlint
/TestFiles/MavenTestFile/ArtifactoryUploaderTestData
/TestFiles/IntegrationTestFiles/ArtifactoryUploaderTestData
1 change: 1 addition & 0 deletions src/AritfactoryUploader.UTest/ArtifactoryUploaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace AritfactoryUploader.UTest
{
[TestFixture]
public class ArtifactoryUploader
{
[SetUp]
Expand Down
2 changes: 1 addition & 1 deletion src/AritfactoryUploader.UTest/PackageUploadHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using LCT.APICommunications.Model;
using LCT.ArtifactoryUploader;
using LCT.Common.Constants;
using Newtonsoft.Json;
using NUnit.Framework;
using System.Collections.Generic;
using System.IO;
Expand All @@ -21,6 +20,7 @@

namespace AritfactoryUploader.UTest
{
[TestFixture]
public class PackageUploadHelperTest
{

Expand Down
1 change: 1 addition & 0 deletions src/AritfactoryUploader.UTest/PackageUploaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

namespace AritfactoryUploader.UTest
{
[TestFixture]
public class PackageUploaderTest
{
[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace LCT.APICommunications.UTest
{
[TestFixture]
public class DebainJfrogAPICommunicationUTest
{
[SetUp]
Expand Down
1 change: 1 addition & 0 deletions src/LCT.APICommunications.UTest/FileInfoExtensionsUTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace LCT.APICommunications.UTest
{
[TestFixture]
public class FileInfoExtensionsUTest
{
[SetUp]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace LCT.APICommunications.UTest
{
[TestFixture]
public class JfrogApicommunicationUTest
{
[SetUp]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using LCT.APICommunications.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// --------------------------------------------------------------------------------------------------------------------
// SPDX-FileCopyrightText: 2024 Siemens AG
//
// SPDX-License-Identifier: MIT
// --------------------------------------------------------------------------------------------------------------------

using LCT.APICommunications.Model;

namespace LCT.APICommunications.UTest
{
[TestFixture]
public class MavenJFrogApiCommunicationUTest
{
[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace LCT.APICommunications.UTest
{

[TestFixture]
public class NPMJfrogAPICommunicationUTest
{
[SetUp]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace LCT.APICommunications.UTest
{
[TestFixture]
public class NugetJfrogAPICommunicationUTest
{
[SetUp]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using LCT.APICommunications.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// --------------------------------------------------------------------------------------------------------------------
// SPDX-FileCopyrightText: 2024 Siemens AG
//
// SPDX-License-Identifier: MIT
// --------------------------------------------------------------------------------------------------------------------

using LCT.APICommunications.Model;

namespace LCT.APICommunications.UTest
{
[TestFixture]
public class PythonJfrogApiCommunicationUTest
{
[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace LCT.APICommunications.UTest
{
[TestFixture]
public class SW360ApicommunicationUTest
{
readonly SW360ConnectionSettings connectionSettings = new SW360ConnectionSettings();
Expand Down
1 change: 1 addition & 0 deletions src/LCT.Common.UTests/CommonHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace LCT.Common.UTest
{
[TestFixture]
public class CommonHelperTest
{

Expand Down
1 change: 1 addition & 0 deletions src/LCT.Common.UTests/ComponentEqualityComparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace LCT.Common.UTests
{
[TestFixture]
public class ComponentEqualityComparerTests
{
[SetUp]
Expand Down
1 change: 1 addition & 0 deletions src/LCT.Common.UTests/FileOperationsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace LCT.Common.UTests
{
[TestFixture]
public class FileOperationsTest
{
[SetUp]
Expand Down
1 change: 1 addition & 0 deletions src/LCT.Common.UTests/FolderActionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace LCT.Common.UTests
{
[TestFixture]
public class FolderActionTest
{

Expand Down
1 change: 0 additions & 1 deletion src/LCT.PackageIdentifier.UTest/AlpineParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using LCT.Common.Constants;
using Moq;
using System.Collections.Generic;
using Microsoft.Build.Evaluation;

namespace LCT.PackageIdentifier.UTest
{
Expand Down
97 changes: 47 additions & 50 deletions src/LCT.PackageIdentifier.UTest/BOMCreatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,73 +13,70 @@

namespace PackageIdentifier.UTest
{
public class Tests
[TestFixture]
public class BOMCreatorTest
{
[TestFixture]
public class BOMCreatorTest
[Test]
public void WriteCycloneDXBOMToJSONFile_InputCycloneDxFile_ReturnsNoneEmptyArray()
{
[Test]
public void WriteCycloneDXBOMToJSONFile_InputCycloneDxFile_ReturnsNoneEmptyArray()
{
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string outFolder = Path.GetDirectoryName(exePath);
string CCTComparisonBomTestFile = outFolder + @"\PackageIdentifierUTTestFiles\CycloneDX_Debian.cdx.json";
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string outFolder = Path.GetDirectoryName(exePath);
string CCTComparisonBomTestFile = outFolder + @"\PackageIdentifierUTTestFiles\CycloneDX_Debian.cdx.json";

string json = "";
if (File.Exists(CCTComparisonBomTestFile))
{
string json = "";
if (File.Exists(CCTComparisonBomTestFile))
{

json = File.ReadAllText(CCTComparisonBomTestFile);
json = File.ReadAllText(CCTComparisonBomTestFile);

}
dynamic array = JsonConvert.DeserializeObject(json);
Assert.IsNotNull(array);
Assert.IsNotEmpty(array);
}
dynamic array = JsonConvert.DeserializeObject(json);
Assert.IsNotNull(array);
Assert.IsNotEmpty(array);
}


[Test]
public void WriteToConfigurationFile()
{
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string outFolder = Path.GetDirectoryName(exePath);
string filepath = outFolder + @"\PackageIdentifierUTTestFiles\SW360ProjectInfo.xml";

[Test]
public void WriteToConfigurationFile()
string expectedproject_id = "42e86178b3b4fe8b8623788052002a6c";
string expectedprojectname = "CCT";
string project_id = "", project_name = "";
if (File.Exists(filepath))
{
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string outFolder = Path.GetDirectoryName(exePath);
string filepath = outFolder + @"\PackageIdentifierUTTestFiles\SW360ProjectInfo.xml";

string expectedproject_id = "42e86178b3b4fe8b8623788052002a6c";
string expectedprojectname = "CCT";
string project_id = "", project_name = "";
if (File.Exists(filepath))
XmlDocument doc = new XmlDocument();
doc.Load(filepath);
XmlNodeList nodes = doc.DocumentElement.SelectNodes("/ProjectInfo");
foreach (XmlNode node in nodes)
{

XmlDocument doc = new XmlDocument();
doc.Load(filepath);
XmlNodeList nodes = doc.DocumentElement.SelectNodes("/ProjectInfo");
foreach (XmlNode node in nodes)
{
project_id = node.SelectSingleNode("ProjectId").InnerText;
project_name = node.SelectSingleNode("ProjectName").InnerText;
}

Assert.AreEqual(expectedproject_id, project_id);
Assert.AreEqual(expectedprojectname, project_name);
project_id = node.SelectSingleNode("ProjectId").InnerText;
project_name = node.SelectSingleNode("ProjectName").InnerText;
}

Assert.AreEqual(expectedproject_id, project_id);
Assert.AreEqual(expectedprojectname, project_name);
}
}

[Test]
public void GetProjectSummaryLink_ProvidedProjectId_ReturnsSW360Url()
{
//Arrange
[Test]
public void GetProjectSummaryLink_ProvidedProjectId_ReturnsSW360Url()
{
//Arrange

BomHelper bomHelper = new BomHelper();
string url = "http:localhost:8090";
string expected = $"{url}{ApiConstant.Sw360ProjectUrlApiSuffix}12345";
//Act
string actual = bomHelper.GetProjectSummaryLink("12345", url);
BomHelper bomHelper = new BomHelper();
string url = "http:localhost:8090";
string expected = $"{url}{ApiConstant.Sw360ProjectUrlApiSuffix}12345";
//Act
string actual = bomHelper.GetProjectSummaryLink("12345", url);

//Assert
Assert.That(expected, Is.EqualTo(actual), "Checks the project url");
//Assert
Assert.That(expected, Is.EqualTo(actual), "Checks the project url");

}
}
}
}
3 changes: 1 addition & 2 deletions src/LCT.PackageIdentifier.UTest/CycloneBomProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
using LCT.Common.Constants;
using LCT.Common.Model;
using LCT.PackageIdentifier;
using NuGet.ContentModel;
using NUnit.Framework;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;

namespace PackageIdentifier.UTest
{
[TestFixture]
public class CycloneBomProcessorTests
{

Expand Down
1 change: 1 addition & 0 deletions src/LCT.PackageIdentifier.UTest/MavenParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace LCT.PackageIdentifier.UTest
{
[TestFixture]
public class MavenParserTests
{
private MavenProcessor _mavenProcessor;
Expand Down
1 change: 0 additions & 1 deletion src/LCT.PackageIdentifier.UTest/NugetParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using System.Threading.Tasks;
using System.Linq;
using LCT.Common.Constants;
using Markdig.Extensions.Yaml;

namespace PackageIdentifier.UTest
{
Expand Down
2 changes: 2 additions & 0 deletions src/LCT.PackageIdentifier/Model/NugetModel/NugetComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
// --------------------------------------------------------------------------------------------------------------------

using PackageUrl;
using System.Diagnostics.CodeAnalysis;

namespace LCT.PackageIdentifier.Model.NugetModel
{
[ExcludeFromCodeCoverage]
public class NuGetComponent : BuildInfoComponent
{
public NuGetComponent(string id, string version) : base(id, version)
Expand Down
3 changes: 2 additions & 1 deletion src/LCT.PackageIdentifier/NugetDevDependencyParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ private static void GetDirectDependencies(string filePath)
return;
}

IEnumerable<JProperty> listChilds = projectFramworks.Children().OfType<JProperty>() ?? new List<JProperty>();
IEnumerable<JProperty> listChilds = projectFramworks.Children().OfType<JProperty>();

//check has values
if (listChilds != null && listChilds.ToList()[0].HasValues)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace LCT.SW360PackageCreator.UTest
{

[TestFixture]
class AlpinePackageDownloaderTest
{
[TestCase]
Expand Down
1 change: 1 addition & 0 deletions src/LCT.SW360PackageCreator.UTest/ComponentCreatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

namespace NUnitTestProject1
{
[TestFixture]
public class ComponentCreatorTest
{
[SetUp]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Siemens AG">
// Copyright (C) Siemens AG 2023. All rights reserved.
// Copyright (C) Siemens AG 2024. All rights reserved.
// </copyright>
//<license>MIT</license>
// --------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 99437b8

Please sign in to comment.