This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from github/shana/121-url-conversion-should-n…
…ever-throw ToRepositoryUrl should never throw, it's a conversion helper
- Loading branch information
Showing
5 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using GitHub.Services; | ||
using LibGit2Sharp; | ||
using NSubstitute; | ||
using Xunit; | ||
using System.Linq; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
public class GitServiceTests : TestBaseClass | ||
{ | ||
[Theory] | ||
[InlineData("asdf", null)] | ||
[InlineData("", null)] | ||
[InlineData(null, null)] | ||
[InlineData("file:///C:/dev/exp/foo", "file:///C:/dev/exp/foo")] | ||
[InlineData("http://example.com/", "http://example.com/")] | ||
[InlineData("http://[email protected]/foo/bar", "http://example.com/foo/bar")] | ||
[InlineData("https://github.com/github/Windows", "https://github.com/github/Windows")] | ||
[InlineData("https://github.com/github/Windows.git", "https://github.com/github/Windows")] | ||
[InlineData("https://[email protected]/github/Windows.git", "https://github.com/github/Windows")] | ||
[InlineData("http://example.com:4000/github/Windows", "http://example.com:4000/github/Windows")] | ||
[InlineData("[email protected]:github/Windows.git", "https://192.168.1.2/github/Windows")] | ||
[InlineData("[email protected]:org/repo.git", "https://example.com/org/repo")] | ||
[InlineData("ssh://[email protected]:443/shana/cef", "https://github.com/shana/cef")] | ||
[InlineData("ssh://[email protected]:23/haacked/encourage", "https://example.com:23/haacked/encourage")] | ||
public void GetUriShouldNotThrow(string url, string expected) | ||
{ | ||
var origin = Substitute.For<Remote>(); | ||
origin.Url.Returns(url); | ||
var repository = Substitute.For<IRepository>(); | ||
repository.Network.Remotes["origin"].Returns(origin); | ||
|
||
var gitservice = new GitService(); | ||
Assert.Equal(expected, gitservice.GetUri(repository)?.ToString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,6 +177,27 @@ public void ConvertsToWebUrl(string uriString, string expected) | |
{ | ||
Assert.Equal(new Uri(expected), new UriString(uriString).ToRepositoryUrl()); | ||
} | ||
|
||
[Theory] | ||
[InlineData("asdf", null)] | ||
[InlineData("", null)] | ||
[InlineData("file:///C:/dev/exp/foo", "file:///C:/dev/exp/foo")] | ||
[InlineData("http://example.com/", "http://example.com/")] | ||
[InlineData("http://[email protected]/foo/bar", "http://example.com/foo/bar")] | ||
[InlineData("https://github.com/github/Windows", "https://github.com/github/Windows")] | ||
[InlineData("https://github.com/github/Windows.git", "https://github.com/github/Windows")] | ||
[InlineData("https://[email protected]/github/Windows.git", "https://github.com/github/Windows")] | ||
[InlineData("http://example.com:4000/github/Windows", "http://example.com:4000/github/Windows")] | ||
[InlineData("[email protected]:github/Windows.git", "https://192.168.1.2/github/Windows")] | ||
[InlineData("[email protected]:org/repo.git", "https://example.com/org/repo")] | ||
[InlineData("ssh://[email protected]:443/shana/cef", "https://github.com/shana/cef")] | ||
[InlineData("ssh://[email protected]:23/haacked/encourage", "https://example.com:23/haacked/encourage")] | ||
public void ShouldNeverThrow(string url, string expected) | ||
{ | ||
Uri uri; | ||
Uri.TryCreate(expected, UriKind.Absolute, out uri); | ||
Assert.Equal(uri, new UriString(url).ToRepositoryUrl()); | ||
} | ||
} | ||
|
||
public class TheAdditionOperator | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters