Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Commit

Permalink
(GH-14) Adding tests
Browse files Browse the repository at this point in the history
- To cover the functionality of the get_domain_from_host method
  • Loading branch information
gep13 committed Dec 1, 2015
1 parent e070513 commit 3c75581
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Compile Include="..\SolutionVersion.cs">
<Link>Properties\SolutionVersion.cs</Link>
</Compile>
<Compile Include="infrastructure.app\IconUrlNotSameDomainAsProjectUrlDomainorRawGitGuidelineSpecs.cs" />
<Compile Include="infrastructure\events\context\FakeMessage.cs" />
<Compile Include="infrastructure\events\context\FakeSubscriber.cs" />
<Compile Include="infrastructure\events\EventSubscriptionManagerSpecs.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace chocolatey.package.validator.tests.infrastructure.app
{
using chocolatey.package.validator.infrastructure.app.rules;
using Should;

public abstract class IconUrlNotSameDomainAsProjectUrlDomainorRawGitGuidelineSpecsBase : TinySpec
{
protected IconUrlNotSameDomainAsProjectUrlDomainOrRawGitGuideline iconGuideline;

public override void Context()
{
iconGuideline = new IconUrlNotSameDomainAsProjectUrlDomainOrRawGitGuideline();
}
}

public class when_extracting_domain_from_host : IconUrlNotSameDomainAsProjectUrlDomainorRawGitGuidelineSpecsBase
{
private string result;

public override void Because()
{
result = iconGuideline.get_domain_from_host("www.test.com");
}

[Fact]
public void should_return_domain()
{
Context();

result.ShouldEqual("test.com");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public class IconUrlNotSameDomainAsProjectUrlDomainOrRawGitGuideline : BasePacka
{
public override string ValidationFailureMessage { get { return "The package IconUrl should ideally come from the same domain name as the Project Url, or hosted on the RawGit CDN. **NOTE:** For further information on how to setup your icon with a RawGit CDN URL, please visit this [article](https://github.com/chocolatey/choco/wiki/CreatePackages#package-icon-guidelines)."; } }

public string get_domain_from_host(string host)
{
// Use Regular Expression to extract the Domain Name, from the Uri Host
// Taken from example shown here http://stackoverflow.com/a/17091145/671491
var match = Regex.Match(host, "([^.]+\\.[^.]{1,3}(\\.[^.]{1,3})?)$");
return match.Groups[1].Success ? match.Groups[1].Value : string.Empty;
}

protected override PackageValidationOutput is_valid(IPackage package)
{
if (package.IconUrl == null) return true;
Expand All @@ -37,13 +45,5 @@ protected override PackageValidationOutput is_valid(IPackage package)

return iconUrlDomain == projectUrlDomain || iconUrlDomain == "rawgit.com";
}

private string get_domain_from_host(string host)
{
// Use Regular Expression to extract the Domain Name, from the Uri Host
// Taken from example shown here http://stackoverflow.com/a/17091145/671491
var match = Regex.Match(host, "([^.]+\\.[^.]{1,3}(\\.[^.]{1,3})?)$");
return match.Groups[1].Success ? match.Groups[1].Value : string.Empty;
}
}
}

0 comments on commit 3c75581

Please sign in to comment.