This repository has been archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
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 #67 from marcind/customUrl
(#37) Add CustomRawUrlProvider to enable arbitrary content URLs
- Loading branch information
Showing
7 changed files
with
142 additions
and
1 deletion.
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,82 @@ | ||
namespace GitLink.Tests.Providers | ||
{ | ||
using GitLink.Providers; | ||
using NUnit.Framework; | ||
|
||
public class CustomRawUrlProviderFacts | ||
{ | ||
[TestFixture] | ||
public class TheInitialization | ||
{ | ||
[TestCase("http://example.com/repo", true)] | ||
[TestCase("https://example.com/repo", true)] | ||
[TestCase("https://example.com/repo/", true)] | ||
[TestCase("gopher://example.com/repo", false)] | ||
public void CorrectlyValidatesForUrls(string url, bool expectedValue) | ||
{ | ||
var provider = new CustomRawUrlProvider(); | ||
var valid = provider.Initialize(url); | ||
|
||
Assert.AreEqual(expectedValue, valid); | ||
} | ||
} | ||
|
||
[TestFixture] | ||
public class TheGitHubProviderProperties | ||
{ | ||
[TestCase] | ||
public void ReturnsNullCompany() | ||
{ | ||
var provider = new CustomRawUrlProvider(); | ||
provider.Initialize("http://example.com/repo"); | ||
|
||
Assert.IsNull(provider.CompanyName); | ||
} | ||
|
||
[TestCase] | ||
public void ReturnsNullCompanyUrl() | ||
{ | ||
var provider = new CustomRawUrlProvider(); | ||
provider.Initialize("http://example.com/repo"); | ||
|
||
Assert.IsNull(provider.CompanyUrl); | ||
} | ||
|
||
[TestCase] | ||
public void ReturnsNullProject() | ||
{ | ||
var provider = new CustomRawUrlProvider(); | ||
provider.Initialize("http://example.com/repo"); | ||
|
||
Assert.IsNull(provider.ProjectName); | ||
} | ||
|
||
[TestCase] | ||
public void ReturnsNullProjectUrl() | ||
{ | ||
var provider = new CustomRawUrlProvider(); | ||
provider.Initialize("http://example.com/repo"); | ||
|
||
Assert.IsNull(provider.ProjectUrl); | ||
} | ||
|
||
[TestCase] | ||
public void ReturnsValidRawGitUrl() | ||
{ | ||
var provider = new CustomRawUrlProvider(); | ||
provider.Initialize("http://example.com/repo"); | ||
|
||
Assert.AreEqual("http://example.com/repo", provider.RawGitUrl); | ||
} | ||
|
||
[TestCase] | ||
public void ReturnsValidRawGitUrlWithNoTrailingSlash() | ||
{ | ||
var provider = new CustomRawUrlProvider(); | ||
provider.Initialize("http://example.com/repo/"); | ||
|
||
Assert.AreEqual("http://example.com/repo", provider.RawGitUrl); | ||
} | ||
} | ||
} | ||
} |
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,42 @@ | ||
namespace GitLink.Providers | ||
{ | ||
using System; | ||
using System.Text.RegularExpressions; | ||
using GitTools.Git; | ||
|
||
public sealed class CustomRawUrlProvider : ProviderBase | ||
{ | ||
private readonly Regex _regex = new Regex(@"https?://.+"); | ||
|
||
private string _rawUrl; | ||
|
||
public CustomRawUrlProvider() | ||
: base(new GitPreparer()) | ||
{ | ||
} | ||
|
||
public override string RawGitUrl | ||
{ | ||
get | ||
{ | ||
return _rawUrl; | ||
} | ||
} | ||
|
||
public override bool Initialize(string url) | ||
{ | ||
if (string.IsNullOrEmpty(url) || !_regex.IsMatch(url)) | ||
{ | ||
return false; | ||
} | ||
|
||
_rawUrl = url; | ||
if (_rawUrl.EndsWith("/", StringComparison.Ordinal)) | ||
{ | ||
_rawUrl = _rawUrl.TrimEnd('/'); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
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