Skip to content

Commit 5d05078

Browse files
Updated as per review comments and fix test cases
1 parent 15ffb9d commit 5d05078

File tree

5 files changed

+211
-59
lines changed

5 files changed

+211
-59
lines changed

src/AritfactoryUploader.UTest/PackageUploadHelperTest.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,18 @@ public async Task GetSrcRepoDetailsForPyPiOrConanPackages_WhenPypiRepoExists_Ret
419419
Name = "pypi component",
420420
Version = "1.0.0"
421421
};
422+
AqlProperty property1 = new AqlProperty
423+
{
424+
key = "pypi.normalized.name",
425+
value = "pypi component"
426+
};
422427

428+
AqlProperty property2 = new AqlProperty
429+
{
430+
key = "pypi.version",
431+
value = "1.0.0"
432+
};
433+
List<AqlProperty> propertys = new List<AqlProperty> { property1, property2 };
423434
//GetInternalComponentDataByRepo
424435
var aqlResultList = new List<AqlResult>
425436
{
@@ -428,10 +439,11 @@ public async Task GetSrcRepoDetailsForPyPiOrConanPackages_WhenPypiRepoExists_Ret
428439
Repo = "pypi-repo",
429440
Path = "path/to/package",
430441
Name = "pypi component-1.0.0",
442+
properties=propertys,
431443
}
432444
};
433445
var jFrogServiceMock = new Mock<IJFrogService>();
434-
jFrogServiceMock.Setup(x => x.GetInternalComponentDataByRepo(It.IsAny<string>())).ReturnsAsync(aqlResultList);
446+
jFrogServiceMock.Setup(x => x.GetPypiComponentDataByRepo(It.IsAny<string>())).ReturnsAsync(aqlResultList);
435447
PackageUploadHelper.jFrogService = jFrogServiceMock.Object;
436448

437449
// Act

src/LCT.PackageIdentifier.UTest/NpmProcessorUTest.cs

Lines changed: 127 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,38 @@ public void GetJfrogArtifactoryRepoDetials_RepoPathFound_ReturnsAqlResultWithRep
2727
{
2828
// Arrange
2929
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
30+
AqlProperty property1 = new AqlProperty
31+
{
32+
key = "npm.name",
33+
value = "component"
34+
};
35+
36+
AqlProperty property2 = new AqlProperty
37+
{
38+
key = "npm.version",
39+
value = "1.0.0"
40+
};
41+
AqlProperty prop1 = new AqlProperty
42+
{
43+
key = "npm.name",
44+
value = "component"
45+
};
46+
47+
AqlProperty prop2 = new AqlProperty
48+
{
49+
key = "npm.version",
50+
value = "2.0.0"
51+
};
52+
List<AqlProperty> propertys = new List<AqlProperty> { property1, property2 };
53+
List<AqlProperty> property = new List<AqlProperty> { prop1, prop2 };
3054
var aqlResultList = new List<AqlResult>
3155
{
32-
new AqlResult { Name = "component-1.0.0.tgz", Repo = "repo1", Path="path/to" },
33-
new AqlResult { Name = "component-2.0.0.tgz", Repo = "repo2", Path="path/to" }
56+
new AqlResult { Name = "component-1.0.0.tgz", Repo = "repo1", Path="path/to",properties=propertys },
57+
new AqlResult { Name = "component-2.0.0.tgz", Repo = "repo2", Path="path/to",properties = property }
3458
};
35-
var component = new Component { Name = "component", Version = "1.0.0" };
3659
var bomHelperMock = new Mock<IBomHelper>();
60+
var component = new Component { Name = "component", Version = "1.0.0" };
61+
bomHelperMock.Setup(b => b.GetFullNameOfComponent(component)).Returns("component");
3762
var expectedRepoPath = "repo1/path/to/component-1.0.0.tgz";
3863

3964
var npmProcessor = new NpmProcessor(cycloneDXBomParser.Object);
@@ -52,13 +77,38 @@ public void GetJfrogArtifactoryRepoDetials_RepoPathNotFound_ReturnsAqlResultWith
5277
{
5378
// Arrange
5479
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
80+
AqlProperty property1 = new AqlProperty
81+
{
82+
key = "npm.name",
83+
value = "component"
84+
};
85+
86+
AqlProperty property2 = new AqlProperty
87+
{
88+
key = "npm.version",
89+
value = "1.0.0"
90+
};
91+
AqlProperty prop1 = new AqlProperty
92+
{
93+
key = "npm.name",
94+
value = "component"
95+
};
96+
97+
AqlProperty prop2 = new AqlProperty
98+
{
99+
key = "npm.version",
100+
value = "2.0.0"
101+
};
102+
List<AqlProperty> propertys = new List<AqlProperty> { property1, property2 };
103+
List<AqlProperty> property = new List<AqlProperty> { prop1, prop2 };
55104
var aqlResultList = new List<AqlResult>
56105
{
57-
new AqlResult { Name = "component-1.0.0.tgz", Repo = "repo1" },
58-
new AqlResult { Name = "component-2.0.0.tgz", Repo = "repo2" }
106+
new AqlResult { Name = "component-1.0.0.tgz", Repo = "repo1",properties=propertys },
107+
new AqlResult { Name = "component-2.0.0.tgz", Repo = "repo2",properties=property }
59108
};
60109
var component = new Component { Name = "component", Version = "3.0.0" };
61110
var bomHelperMock = new Mock<IBomHelper>();
111+
bomHelperMock.Setup(b => b.GetFullNameOfComponent(component)).Returns("component");
62112

63113
var npmProcessor = new NpmProcessor(cycloneDXBomParser.Object);
64114

@@ -84,18 +134,30 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData_Succes
84134
ComponentIdentification component = new() { comparisonBOMData = components };
85135
string[] reooListArr = { "internalrepo1", "internalrepo2" };
86136
CommonAppSettings appSettings = new() { InternalRepoList = reooListArr };
137+
AqlProperty prop1 = new AqlProperty
138+
{
139+
key = "npm.name",
140+
value = "animations"
141+
};
87142

143+
AqlProperty prop2 = new AqlProperty
144+
{
145+
key = "npm.version",
146+
value = "1.0.0"
147+
};
148+
List<AqlProperty> propertys = new List<AqlProperty> { prop1, prop2 };
88149
AqlResult aqlResult = new()
89150
{
90151
Name = "animations-1.0.0.tgz",
91152
Path = "@testfolder/-/folder",
92-
Repo = "internalrepo1"
153+
Repo = "internalrepo1",
154+
properties = propertys
93155
};
94156

95157
List<AqlResult> results = new List<AqlResult>() { aqlResult };
96158
Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
97159
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
98-
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
160+
mockBomHelper.Setup(m => m.GetNpmListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
99161
.ReturnsAsync(results);
100162
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations");
101163
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
@@ -121,18 +183,30 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData2_Succe
121183
ComponentIdentification component = new() { comparisonBOMData = components };
122184
string[] reooListArr = { "internalrepo1", "internalrepo2" };
123185
CommonAppSettings appSettings = new() { InternalRepoList = reooListArr };
186+
AqlProperty prop1 = new AqlProperty
187+
{
188+
key = "npm.name",
189+
value = "animations"
190+
};
124191

192+
AqlProperty prop2 = new AqlProperty
193+
{
194+
key = "npm.version",
195+
value = "1.0.0"
196+
};
197+
List<AqlProperty> propertys = new List<AqlProperty> { prop1, prop2 };
125198
AqlResult aqlResult = new()
126199
{
127200
Name = "animations-common_license-1.0.0.tgz",
128201
Path = "@testfolder/-/folder",
129-
Repo = "internalrepo1"
202+
Repo = "internalrepo1",
203+
properties = propertys
130204
};
131205

132206
List<AqlResult> results = new List<AqlResult>() { aqlResult };
133207
Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
134208
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
135-
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
209+
mockBomHelper.Setup(m => m.GetNpmListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
136210
.ReturnsAsync(results);
137211
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations");
138212
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
@@ -160,18 +234,30 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData3_Succe
160234
ComponentIdentification componentIdentification = new() { comparisonBOMData = components };
161235
string[] reooListArr = { "internalrepo1", "internalrepo1" };
162236
CommonAppSettings appSettings = new() { InternalRepoList = reooListArr };
237+
AqlProperty prop1 = new AqlProperty
238+
{
239+
key = "npm.name",
240+
value = "animations"
241+
};
163242

243+
AqlProperty prop2 = new AqlProperty
244+
{
245+
key = "npm.version",
246+
value = "1.0.0"
247+
};
248+
List<AqlProperty> propertys = new List<AqlProperty> { prop1, prop2 };
164249
AqlResult aqlResult = new()
165250
{
166251
Name = "animations-common-1.0.0.tgz",
167252
Path = "@testfolder/-/folder",
168-
Repo = "internalrepo1"
253+
Repo = "internalrepo1",
254+
properties = propertys
169255
};
170256

171257
List<AqlResult> results = new List<AqlResult>() { aqlResult };
172258
Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
173259
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
174-
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
260+
mockBomHelper.Setup(m => m.GetNpmListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
175261
.ReturnsAsync(results);
176262
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations/common");
177263
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
@@ -200,18 +286,31 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully()
200286
string[] reooListArr = { "internalrepo1", "internalrepo1" };
201287
CommonAppSettings appSettings = new();
202288
appSettings.Npm = new Common.Model.Config() { JfrogNpmRepoList = reooListArr };
289+
AqlProperty prop1 = new AqlProperty
290+
{
291+
key = "npm.name",
292+
value = "animations"
293+
};
294+
295+
AqlProperty prop2 = new AqlProperty
296+
{
297+
key = "npm.version",
298+
value = "1.0.0"
299+
};
300+
List<AqlProperty> propertys = new List<AqlProperty> { prop1, prop2 };
203301
AqlResult aqlResult = new()
204302
{
205303
Name = "animations-common-1.0.0.tgz",
206304
Path = "@testfolder/-/folder",
207-
Repo = "internalrepo1"
305+
Repo = "internalrepo1",
306+
properties = propertys
208307
};
209308

210309
List<AqlResult> results = new List<AqlResult>() { aqlResult };
211310

212311
Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
213312
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
214-
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
313+
mockBomHelper.Setup(m => m.GetNpmListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
215314
.ReturnsAsync(results);
216315
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations/common");
217316
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();
@@ -240,18 +339,31 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData2_SuccessFully(
240339
string[] reooListArr = { "internalrepo1", "internalrepo2" };
241340
CommonAppSettings appSettings = new();
242341
appSettings.Npm = new Common.Model.Config() { JfrogNpmRepoList = reooListArr };
342+
AqlProperty prop1 = new AqlProperty
343+
{
344+
key = "npm.name",
345+
value = "animations"
346+
};
347+
348+
AqlProperty prop2 = new AqlProperty
349+
{
350+
key = "npm.version",
351+
value = "1.0.0"
352+
};
353+
List<AqlProperty> propertys = new List<AqlProperty> { prop1, prop2 };
243354
AqlResult aqlResult = new()
244355
{
245356
Name = "animations-common-1.0.0.tgz",
246357
Path = "@testfolder/-/folder",
247-
Repo = "internalrepo1"
358+
Repo = "internalrepo1",
359+
properties = propertys
248360
};
249361

250362
List<AqlResult> results = new List<AqlResult>() { aqlResult };
251363

252364
Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
253365
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
254-
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
366+
mockBomHelper.Setup(m => m.GetNpmListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
255367
.ReturnsAsync(results);
256368
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations");
257369
Mock<ICycloneDXBomParser> cycloneDXBomParser = new Mock<ICycloneDXBomParser>();

0 commit comments

Comments
 (0)