Skip to content

Commit 3457453

Browse files
Copilotpremun
andcommitted
Add unit tests for PR URL conversion
Co-authored-by: premun <[email protected]>
1 parent 1d0d274 commit 3457453

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Reflection;
5+
using AwesomeAssertions;
6+
using ProductConstructionService.Api.Api.v2020_02_20.Controllers;
7+
8+
namespace ProductConstructionService.Api.Tests;
9+
10+
[TestFixture]
11+
public class PullRequestUrlConversionTests
12+
{
13+
[TestCase("https://api.github.com/repos/dotnet/dotnet/pulls/3205", "https://github.com/dotnet/dotnet/pull/3205")]
14+
[TestCase("https://api.github.com/repos/dotnet/runtime/pulls/12345", "https://github.com/dotnet/runtime/pull/12345")]
15+
[TestCase("https://api.github.com/repos/microsoft/CsWinRT/pulls/999", "https://github.com/microsoft/CsWinRT/pull/999")]
16+
public void TurnApiUrlToWebsite_ConvertsGitHubApiUrlsToWebUrls(string apiUrl, string expectedWebUrl)
17+
{
18+
// Use reflection to call the private static method TurnApiUrlToWebsite
19+
var method = typeof(PullRequestController).GetMethod("TurnApiUrlToWebsite", BindingFlags.NonPublic | BindingFlags.Static);
20+
method.Should().NotBeNull("TurnApiUrlToWebsite method should exist");
21+
22+
var result = method!.Invoke(null, [apiUrl, null, null]) as string;
23+
result.Should().Be(expectedWebUrl);
24+
}
25+
26+
[TestCase("https://dev.azure.com/dnceng/7ea9116e-9fac-403d-b258-b31fcf1bb293/_apis/git/repositories/test-repo-guid/pullRequests/123",
27+
"https://dev.azure.com/dnceng/internal/_git/test-repo-guid/pullrequest/123")]
28+
public void TurnApiUrlToWebsite_ConvertsAzureDevOpsApiUrlsToWebUrls(string apiUrl, string expectedWebUrl)
29+
{
30+
// Use reflection to call the private static method TurnApiUrlToWebsite
31+
var method = typeof(PullRequestController).GetMethod("TurnApiUrlToWebsite", BindingFlags.NonPublic | BindingFlags.Static);
32+
method.Should().NotBeNull("TurnApiUrlToWebsite method should exist");
33+
34+
var result = method!.Invoke(null, [apiUrl, null, null]) as string;
35+
result.Should().Be(expectedWebUrl);
36+
}
37+
38+
[TestCase("https://github.com/dotnet/dotnet/pull/3205")]
39+
[TestCase("https://dev.azure.com/dnceng/internal/_git/dotnet-wpf/pullrequest/123")]
40+
[TestCase("not-a-url")]
41+
public void TurnApiUrlToWebsite_ReturnsOriginalUrlWhenNotApiUrl(string url)
42+
{
43+
// Use reflection to call the private static method TurnApiUrlToWebsite
44+
var method = typeof(PullRequestController).GetMethod("TurnApiUrlToWebsite", BindingFlags.NonPublic | BindingFlags.Static);
45+
method.Should().NotBeNull("TurnApiUrlToWebsite method should exist");
46+
47+
var result = method!.Invoke(null, [url, null, null]) as string;
48+
result.Should().Be(url);
49+
}
50+
}

0 commit comments

Comments
 (0)