1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System . Text . RegularExpressions ;
4
5
using Microsoft . DotNet . Cli . Utils ;
6
+ using Newtonsoft . Json . Linq ;
5
7
6
8
namespace Microsoft . DotNet . Cli . New . IntegrationTests
7
9
{
@@ -58,12 +60,13 @@ public Task CanDisplayDetails_RemotePackage_OtherFeedWithVersion()
58
60
return Verify ( commandResult . StdOut ) ;
59
61
}
60
62
61
- #pragma warning disable xUnit1004 // Test methods should not be skipped
62
- [ Fact ( Skip = "https://github.com/dotnet/sdk/issues/42260" ) ]
63
- #pragma warning restore xUnit1004 // Test methods should not be skipped
64
- public Task CanDisplayDetails_RemotePackage_OtherFeedNoVersion ( )
63
+ [ Fact ]
64
+ public async Task CanDisplayDetails_RemotePackage_OtherFeedNoVersion ( )
65
65
{
66
- CommandResult commandResult = new DotnetNewCommand ( _log , "details" , "Microsoft.Azure.WebJobs.ItemTemplates" )
66
+ string packageName = "Microsoft.Azure.WebJobs.ItemTemplates" ;
67
+ string latestVersion = await GetLatestVersion ( packageName ) ;
68
+
69
+ CommandResult commandResult = new DotnetNewCommand ( _log , "details" , packageName )
67
70
. WithCustomHive ( CreateTemporaryFolder ( folderName : "Home" ) )
68
71
. WithWorkingDirectory ( CreateTemporaryFolder ( ) )
69
72
. Execute ( ) ;
@@ -72,7 +75,9 @@ public Task CanDisplayDetails_RemotePackage_OtherFeedNoVersion()
72
75
. Should ( )
73
76
. Pass ( ) ;
74
77
75
- return Verify ( commandResult . StdOut ) ;
78
+ ExtractVersion ( commandResult . StdOut )
79
+ . Should ( )
80
+ . Be ( latestVersion ) ;
76
81
}
77
82
78
83
[ Fact ]
@@ -127,21 +132,22 @@ public Task CanDisplayDetails_InstalledPackage_NuGetFeed()
127
132
return Verify ( commandResult . StdOut ) ;
128
133
}
129
134
130
- #pragma warning disable xUnit1004 // Test methods should not be skipped
131
- [ Fact ( Skip = "https://github.com/dotnet/sdk/issues/42260" ) ]
132
- #pragma warning restore xUnit1004 // Test methods should not be skipped
133
- public Task CanDisplayDetails_InstalledPackage_OtherFeed ( )
135
+ [ Fact ]
136
+ public async Task CanDisplayDetails_InstalledPackage_OtherFeed ( )
134
137
{
138
+ string packageName = "Microsoft.Azure.WebJobs.ItemTemplates" ;
139
+ string latestVersion = await GetLatestVersion ( packageName ) ;
140
+
135
141
string home = CreateTemporaryFolder ( folderName : "Home" ) ;
136
- new DotnetNewCommand ( _log , "install" , "Microsoft.Azure.WebJobs.ItemTemplates" )
142
+ new DotnetNewCommand ( _log , "install" , packageName )
137
143
. WithoutBuiltInTemplates ( ) . WithCustomHive ( home )
138
144
. WithWorkingDirectory ( CreateTemporaryFolder ( ) )
139
145
. Execute ( )
140
146
. Should ( )
141
147
. ExitWith ( 0 )
142
148
. And . NotHaveStdErr ( ) ;
143
149
144
- CommandResult commandResult = new DotnetNewCommand ( _log , "details" , "Microsoft.Azure.WebJobs.ItemTemplates" )
150
+ CommandResult commandResult = new DotnetNewCommand ( _log , "details" , packageName )
145
151
. WithCustomHive ( home ) . WithoutBuiltInTemplates ( )
146
152
. WithWorkingDirectory ( CreateTemporaryFolder ( ) )
147
153
. Execute ( ) ;
@@ -150,7 +156,9 @@ public Task CanDisplayDetails_InstalledPackage_OtherFeed()
150
156
. Should ( )
151
157
. Pass ( ) ;
152
158
153
- return Verify ( commandResult . StdOut ) ;
159
+ ExtractVersion ( commandResult . StdOut )
160
+ . Should ( )
161
+ . Be ( latestVersion ) ;
154
162
}
155
163
156
164
[ Fact ]
@@ -177,5 +185,32 @@ public Task CanDisplayDetails_InstalledPackage_FolderInstallation()
177
185
return Verify ( commandResult . StdOut )
178
186
. AddScrubber ( output => output . ScrubAndReplace ( basicFSharp , "%TEMPLATE FOLDER%" ) ) ;
179
187
}
188
+
189
+ private async Task < string > GetLatestVersion ( string packageName )
190
+ {
191
+ using ( HttpClient client = new HttpClient ( ) )
192
+ {
193
+ string json = await client . GetStringAsync ( $ "https://api.nuget.org/v3-flatcontainer/{ packageName . ToLowerInvariant ( ) } /index.json") ;
194
+ JObject obj = JObject . Parse ( json ) ;
195
+
196
+ var versions = obj [ "versions" ] ? . ToObject < List < string > > ( ) ;
197
+ if ( versions == null || versions . Count == 0 )
198
+ {
199
+ throw new Exception ( "No versions found." ) ;
200
+ }
201
+
202
+ return versions . Last ( ) ;
203
+ }
204
+ }
205
+
206
+ private string ExtractVersion ( string stdOut )
207
+ {
208
+ var match = Regex . Match ( stdOut , @"Package version:\s*(\S+)" ) ;
209
+ if ( match . Success )
210
+ {
211
+ return match . Groups [ 1 ] . Value ;
212
+ }
213
+ throw new Exception ( "Version not found in the output." ) ;
214
+ }
180
215
}
181
216
}
0 commit comments