Skip to content

Commit

Permalink
Add missing changes from master
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnormark committed Aug 3, 2016
1 parent b6b7e88 commit a6a4138
Show file tree
Hide file tree
Showing 4 changed files with 436 additions and 360 deletions.
34 changes: 28 additions & 6 deletions PreMailer.Net/PreMailer.Net.Core.Tests/LinkTagCssSourceTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Moq;
using AngleSharp.Parser.Html;
using Moq;
using PreMailer.Net.Downloaders;
using PreMailer.Net.Sources;
using System;
using AngleSharp.Parser.Html;
using Xunit;

namespace PreMailer.Net.Tests
{

public class LinkTagCssSourceTests
{
private readonly Mock<IWebDownloader> _webDownloader = new Mock<IWebDownloader>();
Expand All @@ -22,7 +22,7 @@ public void ImplementsInterface()
{
LinkTagCssSource sut = CreateSUT();

ICssSource sut2 = sut as ICssSource;
ICssSource sut2 = sut as ICssSource;

Assert.True(sut2 != null);
}
Expand All @@ -38,6 +38,17 @@ public void GetCSS_CallsWebDownloader_WithSpecifiedDomain()
_webDownloader.Verify(w => w.DownloadString(It.Is<Uri>(u => u.Scheme == "http" && u.Host == "a.co")));
}

[Fact]
public void GetCSS_CallsWebDownloader_WithSpecifiedBundle()
{
string path = "/Content/css?v=7V7TZzP9Wo7LiH9_q-r5mRBdC_N0lA_YJpRL_1V424E1";

LinkTagCssSource sut = CreateSUT(path: path, link: "<link href=\"{0}\" rel=\"stylesheet\"/>");
sut.GetCss();

_webDownloader.Verify(w => w.DownloadString(It.Is<Uri>(u => u.PathAndQuery == path)));
}

[Fact]
public void GetCSS_CallsWebDownloader_WithSpecifiedPath()
{
Expand All @@ -60,9 +71,20 @@ public void GetCSS_AbsoluteUrlInHref_CallsWebDownloader_WithSpecifiedPath()
_webDownloader.Verify(w => w.DownloadString(new Uri(path)));
}

private LinkTagCssSource CreateSUT(string baseUrl = "http://a.com", string path = "a.css")
[Fact]
public void GetCSS_DoesNotCallWebDownloader_WhenSchemeNotSupported()
{
string path = "chrome-extension://fcdjadjbdihbaodagojiomdljhjhjfho/css/atd.css";

LinkTagCssSource sut = CreateSUT(path: path);
sut.GetCss();

_webDownloader.Verify(w => w.DownloadString(new Uri(path)), Times.Never);
}

private LinkTagCssSource CreateSUT(string baseUrl = "http://a.com", string path = "a.css", string link = "<link href=\"{0}\" />")
{
var node = new HtmlParser().Parse(String.Format("<link href=\"{0}\" />", path));
var node = new HtmlParser().Parse(String.Format(link, path));
var sut = new LinkTagCssSource(node.Head.FirstElementChild, new Uri(baseUrl));

return sut;
Expand Down
Loading

0 comments on commit a6a4138

Please sign in to comment.