forked from andrewdavey/cassette
/
ExternalScriptBundle.cs
119 lines (103 loc) · 3.85 KB
/
ExternalScriptBundle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using System.IO;
using Cassette.BundleProcessing;
using Cassette.Configuration;
using Moq;
using Should;
using Xunit;
namespace Cassette.Scripts
{
public class ExternalScriptBundle_Tests
{
const string Url = "http://test.com/asset.js";
[Fact]
public void WhenCreateWithUrl_ThenExternalUrlPropertyIsAssigned()
{
var bundle = new ExternalScriptBundle(Url);
bundle.ExternalUrl.ShouldEqual(Url);
}
[Fact]
public void WhenCreateWithUrl_ThenPathEqualsUrl()
{
var bundle = new ExternalScriptBundle(Url);
bundle.Path.ShouldEqual(Url);
}
[Fact]
public void WhenCreateWithUrlAndPath_ThenUrlIsAssigned()
{
var bundle = new ExternalScriptBundle(Url, "~/test");
bundle.ExternalUrl.ShouldEqual(Url);
}
[Fact]
public void WhenCreateWithUrlAndPath_ThenPathIsAssigned()
{
var bundle = new ExternalScriptBundle(Url, "~/test");
bundle.Path.ShouldEqual("~/test");
}
[Fact]
public void WhenCreateWithUrlAndPath_ThenPathConvertedToApplicationAbsoluteFormat()
{
var bundle = new ExternalScriptBundle(Url, "test");
bundle.Path.ShouldEqual("~/test");
}
[Fact]
public void WhenCreateWithUrlAndPathAndFallbackCondition_ThenFallbackConditionAssigned()
{
var bundle = new ExternalScriptBundle(Url, "test", "!window.test");
bundle.FallbackCondition.ShouldEqual("!window.test");
}
[Fact]
public void ProcessCallsProcessor()
{
var bundle = new ExternalScriptBundle(Url);
var processor = new Mock<IBundleProcessor<ScriptBundle>>();
var settings = new CassetteSettings("");
bundle.Processor = processor.Object;
bundle.Process(settings);
processor.Verify(p => p.Process(bundle, settings));
}
[Fact]
public void GivenBundleHasName_ContainsPathOfThatNameReturnsTrue()
{
var bundle = new ExternalScriptBundle(Url, "~/path");
bundle.ContainsPath("~/path").ShouldBeTrue();
}
[Fact]
public void GivenBundleHasPathAndUrl_WhenContainsPathUrl_ThenReturnTrue()
{
var bundle = new ExternalScriptBundle(Url, "path");
bundle.ContainsPath(Url).ShouldBeTrue();
}
[Fact]
public void UrlRequired()
{
Assert.Throws<ArgumentNullException>(delegate
{
new ExternalScriptBundle(null);
});
Assert.Throws<ArgumentException>(delegate
{
new ExternalScriptBundle("");
});
Assert.Throws<ArgumentException>(delegate
{
new ExternalScriptBundle(" ");
});
}
[Fact]
public void GivenBundleIsProcessed_WhenRender_ThenExternalRendererUsed()
{
var bundle = new ExternalScriptBundle(Url, "~/test", "condition") { Processor = new ScriptPipeline() };
var asset = new Mock<IAsset>();
asset.SetupGet(a => a.SourceFile.FullPath).Returns("~/test/asset.js");
asset.Setup(a => a.OpenStream()).Returns(Stream.Null);
bundle.Assets.Add(asset.Object);
var urlGenerator = new Mock<IUrlGenerator>();
urlGenerator.Setup(g => g.CreateBundleUrl(bundle)).Returns("/");
var settings = new CassetteSettings("") { UrlGenerator = urlGenerator.Object };
bundle.Process(settings);
var html = bundle.Render();
html.ShouldContain("condition");
}
}
}