@@ -295,5 +295,110 @@ public async Task GetPackageInfo_ResultsWith_InvalidOperationException()
295295 // Assert
296296 Assert . Null ( actual ) ;
297297 }
298+ [ Test ]
299+ public async Task GetNpmComponentDataByRepo_GetsRepoInfo_Successfully ( )
300+ {
301+ // Arrange
302+ AqlResult aqlResult = new AqlResult ( )
303+ {
304+ Name = "example-package-1.0.0.tgz" ,
305+ Path = "@testfolder/-/folder" ,
306+ Repo = "npm-repo"
307+ } ;
308+
309+ IList < AqlResult > results = new List < AqlResult > { aqlResult } ;
310+
311+ AqlResponse aqlResponse = new AqlResponse { Results = results } ;
312+
313+ var aqlResponseSerialized = JsonConvert . SerializeObject ( aqlResponse ) ;
314+ var content = new StringContent ( aqlResponseSerialized , Encoding . UTF8 , "application/json" ) ;
315+ HttpResponseMessage httpResponseMessage = new HttpResponseMessage ( HttpStatusCode . OK )
316+ {
317+ Content = content
318+ } ;
319+
320+ Mock < IJfrogAqlApiCommunicationFacade > mockJfrogApiComFacade = new Mock < IJfrogAqlApiCommunicationFacade > ( ) ;
321+ mockJfrogApiComFacade
322+ . Setup ( x => x . GetNpmComponentDataByRepo ( It . IsAny < string > ( ) ) )
323+ . ReturnsAsync ( httpResponseMessage ) ;
324+
325+ // Act
326+ IJFrogService jFrogService = new JFrogService ( mockJfrogApiComFacade . Object ) ;
327+ IList < AqlResult > actual = await jFrogService . GetNpmComponentDataByRepo ( "npm-repo" ) ;
328+
329+ // Assert
330+ Assert . That ( actual . Count , Is . GreaterThan ( 0 ) ) ;
331+ Assert . That ( actual [ 0 ] . Name , Is . EqualTo ( "example-package-1.0.0.tgz" ) ) ;
332+ }
333+
334+ [ Test ]
335+ public async Task GetNpmComponentDataByRepo_ResultsWith_NoContent ( )
336+ {
337+ // Arrange
338+ HttpResponseMessage httpResponseMessage = new HttpResponseMessage ( HttpStatusCode . NoContent ) ;
339+
340+ Mock < IJfrogAqlApiCommunicationFacade > mockJfrogApiComFacade = new Mock < IJfrogAqlApiCommunicationFacade > ( ) ;
341+ mockJfrogApiComFacade
342+ . Setup ( x => x . GetNpmComponentDataByRepo ( It . IsAny < string > ( ) ) )
343+ . ReturnsAsync ( httpResponseMessage ) ;
344+
345+ // Act
346+ IJFrogService jFrogService = new JFrogService ( mockJfrogApiComFacade . Object ) ;
347+ IList < AqlResult > actual = await jFrogService . GetNpmComponentDataByRepo ( "npm-repo" ) ;
348+
349+ // Assert
350+ Assert . That ( actual . Count , Is . EqualTo ( 0 ) ) ;
351+ }
352+
353+ [ Test ]
354+ public async Task GetNpmComponentDataByRepo_ResultsWith_HttpRequestException ( )
355+ {
356+ // Arrange
357+ Mock < IJfrogAqlApiCommunicationFacade > mockJfrogApiComFacade = new Mock < IJfrogAqlApiCommunicationFacade > ( ) ;
358+ mockJfrogApiComFacade
359+ . Setup ( x => x . GetNpmComponentDataByRepo ( It . IsAny < string > ( ) ) )
360+ . Throws < HttpRequestException > ( ) ;
361+
362+ // Act
363+ IJFrogService jFrogService = new JFrogService ( mockJfrogApiComFacade . Object ) ;
364+ IList < AqlResult > actual = await jFrogService . GetNpmComponentDataByRepo ( "npm-repo" ) ;
365+
366+ // Assert
367+ Assert . That ( actual . Count , Is . EqualTo ( 0 ) ) ;
368+ }
369+
370+ [ Test ]
371+ public async Task GetNpmComponentDataByRepo_ResultsWith_InvalidOperationException ( )
372+ {
373+ // Arrange
374+ Mock < IJfrogAqlApiCommunicationFacade > mockJfrogApiComFacade = new Mock < IJfrogAqlApiCommunicationFacade > ( ) ;
375+ mockJfrogApiComFacade
376+ . Setup ( x => x . GetNpmComponentDataByRepo ( It . IsAny < string > ( ) ) )
377+ . Throws < InvalidOperationException > ( ) ;
378+
379+ // Act
380+ IJFrogService jFrogService = new JFrogService ( mockJfrogApiComFacade . Object ) ;
381+ IList < AqlResult > actual = await jFrogService . GetNpmComponentDataByRepo ( "npm-repo" ) ;
382+
383+ // Assert
384+ Assert . That ( actual . Count , Is . EqualTo ( 0 ) ) ;
385+ }
386+
387+ [ Test ]
388+ public async Task GetNpmComponentDataByRepo_ResultsWith_TaskCanceledException ( )
389+ {
390+ // Arrange
391+ Mock < IJfrogAqlApiCommunicationFacade > mockJfrogApiComFacade = new Mock < IJfrogAqlApiCommunicationFacade > ( ) ;
392+ mockJfrogApiComFacade
393+ . Setup ( x => x . GetNpmComponentDataByRepo ( It . IsAny < string > ( ) ) )
394+ . Throws < TaskCanceledException > ( ) ;
395+
396+ // Act
397+ IJFrogService jFrogService = new JFrogService ( mockJfrogApiComFacade . Object ) ;
398+ IList < AqlResult > actual = await jFrogService . GetNpmComponentDataByRepo ( "npm-repo" ) ;
399+
400+ // Assert
401+ Assert . That ( actual . Count , Is . EqualTo ( 0 ) ) ;
402+ }
298403 }
299404}
0 commit comments