Skip to content

Commit c58f4e9

Browse files
authored
Reenable TemplateEngine tests (#42267)
2 parents a3754dc + 88d8f07 commit c58f4e9

3 files changed

+48
-63
lines changed

test/dotnet-new.Tests/Approvals/DotnetNewDetailsTest.CanDisplayDetails_InstalledPackage_OtherFeed.verified.txt

Lines changed: 0 additions & 41 deletions
This file was deleted.

test/dotnet-new.Tests/Approvals/DotnetNewDetailsTest.CanDisplayDetails_RemotePackage_OtherFeedNoVersion.verified.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/dotnet-new.Tests/DotnetNewDetailsTest.Approval.cs

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Text.RegularExpressions;
45
using Microsoft.DotNet.Cli.Utils;
6+
using Newtonsoft.Json.Linq;
57

68
namespace Microsoft.DotNet.Cli.New.IntegrationTests
79
{
@@ -58,12 +60,13 @@ public Task CanDisplayDetails_RemotePackage_OtherFeedWithVersion()
5860
return Verify(commandResult.StdOut);
5961
}
6062

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()
6565
{
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)
6770
.WithCustomHive(CreateTemporaryFolder(folderName: "Home"))
6871
.WithWorkingDirectory(CreateTemporaryFolder())
6972
.Execute();
@@ -72,7 +75,9 @@ public Task CanDisplayDetails_RemotePackage_OtherFeedNoVersion()
7275
.Should()
7376
.Pass();
7477

75-
return Verify(commandResult.StdOut);
78+
ExtractVersion(commandResult.StdOut)
79+
.Should()
80+
.Be(latestVersion);
7681
}
7782

7883
[Fact]
@@ -127,21 +132,22 @@ public Task CanDisplayDetails_InstalledPackage_NuGetFeed()
127132
return Verify(commandResult.StdOut);
128133
}
129134

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()
134137
{
138+
string packageName = "Microsoft.Azure.WebJobs.ItemTemplates";
139+
string latestVersion = await GetLatestVersion(packageName);
140+
135141
string home = CreateTemporaryFolder(folderName: "Home");
136-
new DotnetNewCommand(_log, "install", "Microsoft.Azure.WebJobs.ItemTemplates")
142+
new DotnetNewCommand(_log, "install", packageName)
137143
.WithoutBuiltInTemplates().WithCustomHive(home)
138144
.WithWorkingDirectory(CreateTemporaryFolder())
139145
.Execute()
140146
.Should()
141147
.ExitWith(0)
142148
.And.NotHaveStdErr();
143149

144-
CommandResult commandResult = new DotnetNewCommand(_log, "details", "Microsoft.Azure.WebJobs.ItemTemplates")
150+
CommandResult commandResult = new DotnetNewCommand(_log, "details", packageName)
145151
.WithCustomHive(home).WithoutBuiltInTemplates()
146152
.WithWorkingDirectory(CreateTemporaryFolder())
147153
.Execute();
@@ -150,7 +156,9 @@ public Task CanDisplayDetails_InstalledPackage_OtherFeed()
150156
.Should()
151157
.Pass();
152158

153-
return Verify(commandResult.StdOut);
159+
ExtractVersion(commandResult.StdOut)
160+
.Should()
161+
.Be(latestVersion);
154162
}
155163

156164
[Fact]
@@ -177,5 +185,32 @@ public Task CanDisplayDetails_InstalledPackage_FolderInstallation()
177185
return Verify(commandResult.StdOut)
178186
.AddScrubber(output => output.ScrubAndReplace(basicFSharp, "%TEMPLATE FOLDER%"));
179187
}
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+
}
180215
}
181216
}

0 commit comments

Comments
 (0)