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

Commit 3c75581

Browse files
committed
(GH-14) Adding tests
- To cover the functionality of the get_domain_from_host method
1 parent e070513 commit 3c75581

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

‎src/chocolatey.package.validator.tests/chocolatey.package.validator.tests.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<Compile Include="..\SolutionVersion.cs">
7979
<Link>Properties\SolutionVersion.cs</Link>
8080
</Compile>
81+
<Compile Include="infrastructure.app\IconUrlNotSameDomainAsProjectUrlDomainorRawGitGuidelineSpecs.cs" />
8182
<Compile Include="infrastructure\events\context\FakeMessage.cs" />
8283
<Compile Include="infrastructure\events\context\FakeSubscriber.cs" />
8384
<Compile Include="infrastructure\events\EventSubscriptionManagerSpecs.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace chocolatey.package.validator.tests.infrastructure.app
2+
{
3+
using chocolatey.package.validator.infrastructure.app.rules;
4+
using Should;
5+
6+
public abstract class IconUrlNotSameDomainAsProjectUrlDomainorRawGitGuidelineSpecsBase : TinySpec
7+
{
8+
protected IconUrlNotSameDomainAsProjectUrlDomainOrRawGitGuideline iconGuideline;
9+
10+
public override void Context()
11+
{
12+
iconGuideline = new IconUrlNotSameDomainAsProjectUrlDomainOrRawGitGuideline();
13+
}
14+
}
15+
16+
public class when_extracting_domain_from_host : IconUrlNotSameDomainAsProjectUrlDomainorRawGitGuidelineSpecsBase
17+
{
18+
private string result;
19+
20+
public override void Because()
21+
{
22+
result = iconGuideline.get_domain_from_host("www.test.com");
23+
}
24+
25+
[Fact]
26+
public void should_return_domain()
27+
{
28+
Context();
29+
30+
result.ShouldEqual("test.com");
31+
}
32+
}
33+
}

‎src/chocolatey.package.validator/infrastructure.app/rules/IconUrlNotSameDomainAsProjectUrlDomainOrRawGitGuideline.cs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ public class IconUrlNotSameDomainAsProjectUrlDomainOrRawGitGuideline : BasePacka
2323
{
2424
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)."; } }
2525

26+
public string get_domain_from_host(string host)
27+
{
28+
// Use Regular Expression to extract the Domain Name, from the Uri Host
29+
// Taken from example shown here http://stackoverflow.com/a/17091145/671491
30+
var match = Regex.Match(host, "([^.]+\\.[^.]{1,3}(\\.[^.]{1,3})?)$");
31+
return match.Groups[1].Success ? match.Groups[1].Value : string.Empty;
32+
}
33+
2634
protected override PackageValidationOutput is_valid(IPackage package)
2735
{
2836
if (package.IconUrl == null) return true;
@@ -37,13 +45,5 @@ protected override PackageValidationOutput is_valid(IPackage package)
3745

3846
return iconUrlDomain == projectUrlDomain || iconUrlDomain == "rawgit.com";
3947
}
40-
41-
private string get_domain_from_host(string host)
42-
{
43-
// Use Regular Expression to extract the Domain Name, from the Uri Host
44-
// Taken from example shown here http://stackoverflow.com/a/17091145/671491
45-
var match = Regex.Match(host, "([^.]+\\.[^.]{1,3}(\\.[^.]{1,3})?)$");
46-
return match.Groups[1].Success ? match.Groups[1].Value : string.Empty;
47-
}
4848
}
4949
}

0 commit comments

Comments
 (0)