Skip to content

Commit

Permalink
refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
ragavareddychalapala committed Jan 4, 2025
1 parent beb6769 commit b461694
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 82 deletions.
13 changes: 7 additions & 6 deletions src/AritfactoryUploader.UTest/PackageUploadHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ public async Task GetSrcRepoDetailsForPyPiOrConanPackages_WhenPypiRepoExists_Ret
Value = "Reponame"
};
List<Property> properties = new List<Property>() { repoNameProperty };
await Task.Delay(5000);
var item = new Component
{
Purl = "pypi://example-package",
Expand All @@ -421,14 +422,14 @@ public async Task GetSrcRepoDetailsForPyPiOrConanPackages_WhenPypiRepoExists_Ret
};
AqlProperty pypiNameProperty = new AqlProperty
{
key = "pypi.normalized.name",
value = "pypi component"
Key = "pypi.normalized.name",
Value = "pypi component"
};

AqlProperty pypiVersionProperty = new AqlProperty
{
key = "pypi.version",
value = "1.0.0"
Key = "pypi.version",
Value = "1.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { pypiNameProperty, pypiVersionProperty };
//GetInternalComponentDataByRepo
Expand All @@ -439,7 +440,7 @@ public async Task GetSrcRepoDetailsForPyPiOrConanPackages_WhenPypiRepoExists_Ret
Repo = "pypi-repo",
Path = "path/to/package",
Name = "pypi component-1.0.0",
properties=propertys,
Properties=propertys,
}
};
var jFrogServiceMock = new Mock<IJFrogService>();
Expand All @@ -456,7 +457,7 @@ public async Task GetSrcRepoDetailsForPyPiOrConanPackages_WhenPypiRepoExists_Ret
Assert.AreEqual("pypi-repo", result.Repo);
Assert.AreEqual("path/to/package", result.Path);
}
public async Task GetSrcRepoDetailsForPyPiOrConanPackages_WhenConanRepoExists_ReturnsArtifactoryRepoName()
public async static Task GetSrcRepoDetailsForPyPiOrConanPackages_WhenConanRepoExists_ReturnsArtifactoryRepoName()
{
// Arrange
Property reponameProperty = new Property
Expand Down
4 changes: 2 additions & 2 deletions src/ArtifactoryUploader/PackageUploadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,15 +1215,15 @@ public static async Task<List<AqlResult>> GetNpmListOfComponentsFromRepo(string[
private static AqlResult GetArtifactoryRepoName(List<AqlResult> aqlResultList, Component component)
{
string jfrogpackageName = GetFullNameOfComponent(component);
AqlResult repoName = aqlResultList.Find(x => x.properties.Any(p => p.key == "pypi.normalized.name" && p.value == jfrogpackageName) && x.properties.Any(p => p.key == "pypi.version" && p.value == component.Version));
AqlResult repoName = aqlResultList.Find(x => x.Properties.Any(p => p.Key == "pypi.normalized.name" && p.Value == jfrogpackageName) && x.Properties.Any(p => p.Key == "pypi.version" && p.Value == component.Version));

return repoName;
}

private static AqlResult GetNpmArtifactoryRepoName(List<AqlResult> aqlResultList, Component component)
{
string jfrogpackageName = GetFullNameOfComponent(component);
AqlResult repoName = aqlResultList.Find(x => x.properties.Any(p => p.key == "npm.name" && p.value == jfrogpackageName) && x.properties.Any(p => p.key == "npm.version" && p.value == component.Version));
AqlResult repoName = aqlResultList.Find(x => x.Properties.Any(p => p.Key == "npm.name" && p.Value == jfrogpackageName) && x.Properties.Any(p => p.Key == "npm.version" && p.Value == component.Version));

return repoName;
}
Expand Down
6 changes: 3 additions & 3 deletions src/LCT.APICommunications/Model/AQL/AqlResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public class AqlResult
[JsonProperty("sha256")]
public string SHA256 { get; set; }

public List<AqlProperty> properties { get; set; }
public List<AqlProperty> Properties { get; set; }

}
public class AqlProperty
{
public string key { get; set; }
public string value { get; set; }
public string Key { get; set; }
public string Value { get; set; }
}

}
90 changes: 45 additions & 45 deletions src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@ public void GetJfrogArtifactoryRepoDetials_RepoPathFound_ReturnsAqlResultWithRep
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
AqlProperty npmNameProperty = new AqlProperty
{
key = "npm.name",
value = "component"
Key = "npm.name",
Value = "component"
};

AqlProperty npmVersionProperty = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
Key = "npm.version",
Value = "1.0.0"
};
AqlProperty npmNamePropert = new AqlProperty
{
key = "npm.name",
value = "component"
Key = "npm.name",
Value = "component"
};

AqlProperty npmVersionPropert = new AqlProperty
{
key = "npm.version",
value = "2.0.0"
Key = "npm.version",
Value = "2.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { npmNameProperty, npmVersionProperty };
List<AqlProperty> property = new List<AqlProperty> { npmNamePropert, npmVersionPropert };
var aqlResultList = new List<AqlResult>
{
new AqlResult { Name = "component-1.0.0.tgz", Repo = "repo1", Path="path/to",properties=propertys },
new AqlResult { Name = "component-2.0.0.tgz", Repo = "repo2", Path="path/to",properties = property }
new AqlResult { Name = "component-1.0.0.tgz", Repo = "repo1", Path="path/to",Properties=propertys },
new AqlResult { Name = "component-2.0.0.tgz", Repo = "repo2", Path="path/to",Properties = property }
};
var bomHelperMock = new Mock<IBomHelper>();
var component = new Component { Name = "component", Version = "1.0.0" };
Expand All @@ -79,32 +79,32 @@ public void GetJfrogArtifactoryRepoDetials_RepoPathNotFound_ReturnsAqlResultWith
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
AqlProperty npmNameProperty = new AqlProperty
{
key = "npm.name",
value = "component"
Key = "npm.name",
Value = "component"
};

AqlProperty npmVersionProperty = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
Key = "npm.version",
Value = "1.0.0"
};
AqlProperty npmNamePropert = new AqlProperty
{
key = "npm.name",
value = "component"
Key = "npm.name",
Value = "component"
};

AqlProperty npmVersionPropert = new AqlProperty
{
key = "npm.version",
value = "2.0.0"
Key = "npm.version",
Value = "2.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { npmNameProperty, npmVersionProperty };
List<AqlProperty> property = new List<AqlProperty> { npmNamePropert, npmVersionPropert };
var aqlResultList = new List<AqlResult>
{
new AqlResult { Name = "component-1.0.0.tgz", Repo = "repo1",properties=propertys },
new AqlResult { Name = "component-2.0.0.tgz", Repo = "repo2",properties=property }
new AqlResult { Name = "component-1.0.0.tgz", Repo = "repo1",Properties=propertys },
new AqlResult { Name = "component-2.0.0.tgz", Repo = "repo2",Properties=property }
};
var component = new Component { Name = "component", Version = "3.0.0" };
var bomHelperMock = new Mock<IBomHelper>();
Expand Down Expand Up @@ -136,22 +136,22 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData_Succes
CommonAppSettings appSettings = new() { InternalRepoList = reooListArr };
AqlProperty npmNameProperty = new AqlProperty
{
key = "npm.name",
value = "animations"
Key = "npm.name",
Value = "animations"
};

AqlProperty npmVersionProperty = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
Key = "npm.version",
Value = "1.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { npmNameProperty, npmVersionProperty };
AqlResult aqlResult = new()
{
Name = "animations-1.0.0.tgz",
Path = "@testfolder/-/folder",
Repo = "internalrepo1",
properties = propertys
Properties = propertys
};

List<AqlResult> results = new List<AqlResult>() { aqlResult };
Expand Down Expand Up @@ -185,22 +185,22 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData2_Succe
CommonAppSettings appSettings = new() { InternalRepoList = reooListArr };
AqlProperty npmNameProperty = new AqlProperty
{
key = "npm.name",
value = "animations"
Key = "npm.name",
Value = "animations"
};

AqlProperty npmVersionProperty = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
Key = "npm.version",
Value = "1.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { npmNameProperty, npmVersionProperty };
AqlResult aqlResult = new()
{
Name = "animations-common_license-1.0.0.tgz",
Path = "@testfolder/-/folder",
Repo = "internalrepo1",
properties = propertys
Properties = propertys
};

List<AqlResult> results = new List<AqlResult>() { aqlResult };
Expand Down Expand Up @@ -236,22 +236,22 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData3_Succe
CommonAppSettings appSettings = new() { InternalRepoList = reooListArr };
AqlProperty npmNameProperty = new AqlProperty
{
key = "npm.name",
value = "animations"
Key = "npm.name",
Value = "animations"
};

AqlProperty npmVersionProperty = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
Key = "npm.version",
Value = "1.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { npmNameProperty, npmVersionProperty };
AqlResult aqlResult = new()
{
Name = "animations-common-1.0.0.tgz",
Path = "@testfolder/-/folder",
Repo = "internalrepo1",
properties = propertys
Properties = propertys
};

List<AqlResult> results = new List<AqlResult>() { aqlResult };
Expand Down Expand Up @@ -288,22 +288,22 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully()
appSettings.Npm = new Common.Model.Config() { JfrogNpmRepoList = reooListArr };
AqlProperty npmNameProperty = new AqlProperty
{
key = "npm.name",
value = "animations"
Key = "npm.name",
Value = "animations"
};

AqlProperty npmVersionProperty = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
Key = "npm.version",
Value = "1.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { npmNameProperty, npmVersionProperty };
AqlResult aqlResult = new()
{
Name = "animations-common-1.0.0.tgz",
Path = "@testfolder/-/folder",
Repo = "internalrepo1",
properties = propertys
Properties = propertys
};

List<AqlResult> results = new List<AqlResult>() { aqlResult };
Expand Down Expand Up @@ -341,22 +341,22 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData2_SuccessFully(
appSettings.Npm = new Common.Model.Config() { JfrogNpmRepoList = reooListArr };
AqlProperty npmNameProperty = new AqlProperty
{
key = "npm.name",
value = "animations"
Key = "npm.name",
Value = "animations"
};

AqlProperty npmVersionProperty = new AqlProperty
{
key = "npm.version",
value = "1.0.0"
Key = "npm.version",
Value = "1.0.0"
};
List<AqlProperty> propertys = new List<AqlProperty> { npmNameProperty, npmVersionProperty };
AqlResult aqlResult = new()
{
Name = "animations-common-1.0.0.tgz",
Path = "@testfolder/-/folder",
Repo = "internalrepo1",
properties = propertys
Properties = propertys
};

List<AqlResult> results = new List<AqlResult>() { aqlResult };
Expand Down
Loading

0 comments on commit b461694

Please sign in to comment.