44using System ;
55using System . Collections . Generic ;
66using System . IO ;
7+ using System . Threading ;
8+ using System . Threading . Tasks ;
79using Microsoft . VisualStudio . TestTools . UnitTesting ;
810using Microsoft . Web . LibraryManager . Cache ;
911using Microsoft . Web . LibraryManager . Contracts ;
@@ -17,6 +19,7 @@ public class BaseProviderTest
1719 {
1820 private IHostInteraction _hostInteraction ;
1921 private ILibrary _library ;
22+ private readonly Mocks . LibraryCatalog _catalog ;
2023
2124 public BaseProviderTest ( )
2225 {
@@ -39,10 +42,12 @@ public BaseProviderTest()
3942 } ,
4043 } ;
4144
45+ _catalog = new Mocks . LibraryCatalog ( )
46+ . AddLibrary ( _library ) ;
4247 }
4348
4449 [ TestMethod ]
45- public void GenerateGoalState_NoFileMapping_SpecifyFilesAtLibraryLevel ( )
50+ public async Task GenerateGoalState_NoFileMapping_SpecifyFilesAtLibraryLevel ( )
4651 {
4752 ILibraryInstallationState installState = new LibraryInstallationState
4853 {
@@ -52,20 +57,25 @@ public void GenerateGoalState_NoFileMapping_SpecifyFilesAtLibraryLevel()
5257 DestinationPath = "lib/test" ,
5358 Files = [ "folder/*.txt" ] ,
5459 } ;
55- BaseProvider provider = new TestProvider ( _hostInteraction , cacheService : null ) ;
60+ BaseProvider provider = new TestProvider ( _hostInteraction , cacheService : null )
61+ {
62+ Catalog = _catalog ,
63+ } ;
5664 string expectedDestinationFile1 = FileHelpers . NormalizePath ( Path . Combine ( provider . HostInteraction . WorkingDirectory , "lib/test/folder/file3.txt" ) ) ;
5765 string expectedSourceFile1 = FileHelpers . NormalizePath ( Path . Combine ( provider . HostInteraction . CacheDirectory , "TestProvider/test/1.0/folder/file3.txt" ) ) ;
5866
59- LibraryInstallationGoalState goalState = provider . GenerateGoalState ( installState , _library ) ;
67+ OperationResult < LibraryInstallationGoalState > getGoalState = await provider . GetInstallationGoalStateAsync ( installState , CancellationToken . None ) ;
6068
69+ Assert . IsTrue ( getGoalState . Success ) ;
70+ LibraryInstallationGoalState goalState = getGoalState . Result ;
6171 Assert . IsNotNull ( goalState ) ;
6272 Assert . AreEqual ( 1 , goalState . InstalledFiles . Count ) ;
6373 Assert . IsTrue ( goalState . InstalledFiles . TryGetValue ( expectedDestinationFile1 , out string file1 ) ) ;
6474 Assert . AreEqual ( expectedSourceFile1 , file1 ) ;
6575 }
6676
6777 [ TestMethod ]
68- public void GenerateGoalState_NoFileMapping_NoFilesAtLibraryLevel ( )
78+ public async Task GenerateGoalState_NoFileMapping_NoFilesAtLibraryLevel ( )
6979 {
7080 ILibraryInstallationState installState = new LibraryInstallationState
7181 {
@@ -74,15 +84,21 @@ public void GenerateGoalState_NoFileMapping_NoFilesAtLibraryLevel()
7484 ProviderId = "TestProvider" ,
7585 DestinationPath = "lib/test" ,
7686 } ;
77- BaseProvider provider = new TestProvider ( _hostInteraction , cacheService : null ) ;
87+ BaseProvider provider = new TestProvider ( _hostInteraction , cacheService : null )
88+ {
89+ Catalog = _catalog ,
90+ } ;
7891 string expectedDestinationFile1 = FileHelpers . NormalizePath ( Path . Combine ( provider . HostInteraction . WorkingDirectory , "lib/test/file1.txt" ) ) ;
7992 string expectedSourceFile1 = FileHelpers . NormalizePath ( Path . Combine ( provider . HostInteraction . CacheDirectory , "TestProvider/test/1.0/file1.txt" ) ) ;
8093 string expectedDestinationFile2 = FileHelpers . NormalizePath ( Path . Combine ( provider . HostInteraction . WorkingDirectory , "lib/test/file2.txt" ) ) ;
8194 string expectedSourceFile2 = FileHelpers . NormalizePath ( Path . Combine ( provider . HostInteraction . CacheDirectory , "TestProvider/test/1.0/file2.txt" ) ) ;
8295 string expectedDestinationFile3 = FileHelpers . NormalizePath ( Path . Combine ( provider . HostInteraction . WorkingDirectory , "lib/test/folder/file3.txt" ) ) ;
8396 string expectedSourceFile3 = FileHelpers . NormalizePath ( Path . Combine ( provider . HostInteraction . CacheDirectory , "TestProvider/test/1.0/folder/file3.txt" ) ) ;
8497
85- LibraryInstallationGoalState goalState = provider . GenerateGoalState ( installState , _library ) ;
98+ OperationResult < LibraryInstallationGoalState > getGoalState = await provider . GetInstallationGoalStateAsync ( installState , CancellationToken . None ) ;
99+
100+ Assert . IsTrue ( getGoalState . Success ) ;
101+ LibraryInstallationGoalState goalState = getGoalState . Result ;
86102
87103 Assert . IsNotNull ( goalState ) ;
88104 Assert . AreEqual ( 3 , goalState . InstalledFiles . Count ) ;
@@ -105,10 +121,9 @@ public TestProvider(IHostInteraction hostInteraction, CacheService cacheService)
105121
106122 public override string LibraryIdHintText => Text . CdnjsLibraryIdHintText ;
107123
108- public override ILibraryCatalog GetCatalog ( )
109- {
110- throw new NotImplementedException ( ) ;
111- }
124+ public ILibraryCatalog Catalog { get ; set ; }
125+
126+ public override ILibraryCatalog GetCatalog ( ) => Catalog ;
112127
113128 public override string GetSuggestedDestination ( ILibrary library )
114129 {
0 commit comments