本文整理汇总了C#中SquishIt.Tests.Stubs.StubFileWriterFactory类的典型用法代码示例。如果您正苦于以下问题:C# StubFileWriterFactory类的具体用法?C# StubFileWriterFactory怎么用?C# StubFileWriterFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StubFileWriterFactory类属于SquishIt.Tests.Stubs命名空间,在下文中一共展示了StubFileWriterFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanBundleDirectoryContentsInDebug
public void CanBundleDirectoryContentsInDebug()
{
var path = Guid.NewGuid().ToString();
var file1 = TestUtilities.PreparePath(Environment.CurrentDirectory + "\\" + path + "\\file1.js");
var file2 = TestUtilities.PreparePath(Environment.CurrentDirectory + "\\" + path + "\\file2.js");
using(new ResolverFactoryScope(typeof(FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 })))
{
var frf = new StubFileReaderFactory();
frf.SetContentsForFile(file1, javaScript2.Replace("sum", "replace"));
frf.SetContentsForFile(file2, javaScript);
var writerFactory = new StubFileWriterFactory();
var tag = new JavaScriptBundleFactory()
.WithDebuggingEnabled(true)
.WithFileReaderFactory(frf)
.WithFileWriterFactory(writerFactory)
.WithHasher(new StubHasher("hashy"))
.Create()
.Add(path)
.Render("~/output.js");
var expectedTag = string.Format("<script type=\"text/javascript\" src=\"{0}/file1.js\"></script>\n<script type=\"text/javascript\" src=\"{0}/file2.js\"></script>\n", path);
Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
}
}
示例2: CanBundleJavascriptInDebug
public void CanBundleJavascriptInDebug(Type preprocessorType)
{
var preprocessor = Activator.CreateInstance(preprocessorType) as IPreprocessor;
const string template = "<h1>{{message}}</h1>";
var templateFileName = "test.hogan.html";
var resolver = StubResolver.ForFile(TestUtilities.PrepareRelativePath(templateFileName));
var readerFactory = new StubFileReaderFactory();
readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(templateFileName), template);
var writerFactory = new StubFileWriterFactory();
string tag;
using(new ResolverFactoryScope(typeof(FileSystemResolver).FullName, resolver))
{
tag = javaScriptBundleFactory
.WithFileReaderFactory(readerFactory)
.WithFileWriterFactory(writerFactory)
.WithDebuggingEnabled(true)
.Create()
.WithPreprocessor(preprocessor)
.Add("~/" + templateFileName)
.Render("~/template.js");
}
var sb = new StringBuilder();
sb.AppendLine(@"var JST = JST || {};");
sb.AppendLine(@"JST['test'] = new Hogan.Template(function(c,p,i){var _=this;_.b(i=i||"""");_.b(""<h1>"");_.b(_.v(_.f(""message"",c,p,0)));_.b(""</h1>"");return _.fl();;},""" + template + "\",Hogan,{});");
var compiled = sb.ToString();
Assert.AreEqual(1, writerFactory.Files.Count);
var expectedTag = "<script type=\"text/javascript\" src=\"test.hogan.html.squishit.debug.js\"></script>\n";
Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
Assert.AreEqual(compiled, writerFactory.Files[TestUtilities.PrepareRelativePath("test.hogan.html.squishit.debug.js")]);
}
示例3: CanBundleArbitraryContentsInRelease
public void CanBundleArbitraryContentsInRelease()
{
var js2Format = "{0}{1}";
var subtract = "function sub(a,b){return a-b}";
var divide = "function div(a,b){return a/b}";
var writerFactory = new StubFileWriterFactory();
var tag = new JavaScriptBundleFactory()
.WithDebuggingEnabled(false)
.WithFileWriterFactory(writerFactory)
.WithHasher(new StubHasher("hashy"))
.Create()
.AddString(javaScript)
.AddString(js2Format, new[] { subtract, divide })
.Render("~/output.js");
var expectedTag = "<script type=\"text/javascript\" src=\"output.js?r=hashy\"></script>";
Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
var minifiedScript = "function product(n,t){return n*t}function sum(n,t){return n+t};function sub(n,t){return n-t}function div(n,t){return n/t};";
Assert.AreEqual(minifiedScript, writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.js")]);
}
示例4: CanBundleArbitraryContentsInRelease
public void CanBundleArbitraryContentsInRelease()
{
var css2Format = "{0}{1}";
var hrColor = "hr {color:sienna;}";
var p = "p {margin-left:20px;}";
var writerFactory = new StubFileWriterFactory();
var tag = new CSSBundleFactory()
.WithDebuggingEnabled(false)
.WithFileWriterFactory(writerFactory)
.WithHasher(new StubHasher("hashy"))
.Create()
.AddString(css)
.AddString(css2Format, new[] { hrColor, p })
.Render("~/output.css");
var expectedTag = "<link rel=\"stylesheet\" type=\"text/css\" href=\"output.css?r=hashy\" />";
Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
var minifiedScript = "li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}hr{color:#a0522d}p{margin-left:20px}";
Assert.AreEqual(minifiedScript, writerFactory.Files[TestUtilities.PrepareRelativePath("output.css")]);
}
示例5: CanBundleJavaScriptWithMinifiedDirectories
public void CanBundleJavaScriptWithMinifiedDirectories()
{
var path = Guid.NewGuid().ToString();
var path2 = Guid.NewGuid().ToString();
var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.js");
var file2 = TestUtilities.PrepareRelativePath(path2 + "\\file2.js");
var resolver = new Mock<IResolver>(MockBehavior.Strict);
resolver.Setup(r => r.IsDirectory(It.IsAny<string>())).Returns(true);
resolver.Setup(r =>
r.ResolveFolder(TestUtilities.PrepareRelativePath(path), It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<string>>()))
.Returns(new[] { file1 });
resolver.Setup(r =>
r.ResolveFolder(TestUtilities.PrepareRelativePath(path2), It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<string>>()))
.Returns(new[] { file2 });
using(new ResolverFactoryScope(typeof(FileSystemResolver).FullName, resolver.Object))
{
var frf = new StubFileReaderFactory();
frf.SetContentsForFile(file1, javaScript);
frf.SetContentsForFile(file2, javaScriptPreMinified);
var writerFactory = new StubFileWriterFactory();
var tag = javaScriptBundleFactory
.WithDebuggingEnabled(false)
.WithFileReaderFactory(frf)
.WithFileWriterFactory(writerFactory)
.Create()
.AddDirectory(path)
.AddMinifiedDirectory(path2)
.Render("~/output.js");
Assert.AreEqual("<script type=\"text/javascript\" src=\"output.js?r=hash\"></script>", tag);
var content = writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.js")];
Assert.True(content.StartsWith(minifiedJavaScript));
Assert.True(content.EndsWith(javaScriptPreMinified + ";"));
}
}
示例6: CanBundleDirectoryContentsInRelease_Ignores_Duplicates
public void CanBundleDirectoryContentsInRelease_Ignores_Duplicates()
{
var path = Guid.NewGuid().ToString();
var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.js");
var file2 = TestUtilities.PrepareRelativePath(path + "\\file2.js");
using(new ResolverFactoryScope(typeof(FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 })))
{
var frf = new StubFileReaderFactory();
frf.SetContentsForFile(file1, javaScript2.Replace("sum", "replace"));
frf.SetContentsForFile(file2, javaScript);
var writerFactory = new StubFileWriterFactory();
var tag = new JavaScriptBundleFactory()
.WithDebuggingEnabled(false)
.WithFileReaderFactory(frf)
.WithFileWriterFactory(writerFactory)
.WithHasher(new StubHasher("hashy"))
.Create()
.Add(path)
.Add(file1)
.Render("~/output.js");
var expectedTag = "<script type=\"text/javascript\" src=\"output.js?r=hashy\"></script>";
Assert.AreEqual(expectedTag, tag);
var combined = "function replace(n,t){return n+t};function product(n,t){return n*t}function sum(n,t){return n+t};";
Assert.AreEqual(combined, writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.js")]);
}
}
示例7: CanBundleDirectoryContentsInDebug_Writes_And_Ignores_Preprocessed_Debug_Files
public void CanBundleDirectoryContentsInDebug_Writes_And_Ignores_Preprocessed_Debug_Files()
{
var path = Guid.NewGuid().ToString();
var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.script.js");
var file2 = TestUtilities.PrepareRelativePath(path + "\\file1.script.js.squishit.debug.js");
var content = "some stuffs";
var preprocessor = new StubScriptPreprocessor();
using(new ScriptPreprocessorScope<StubScriptPreprocessor>(preprocessor))
using(new ResolverFactoryScope(typeof(FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 })))
{
var frf = new StubFileReaderFactory();
frf.SetContentsForFile(file1, content);
var writerFactory = new StubFileWriterFactory();
var tag = new JavaScriptBundleFactory()
.WithDebuggingEnabled(true)
.WithFileReaderFactory(frf)
.WithFileWriterFactory(writerFactory)
.WithHasher(new StubHasher("hashy"))
.Create()
.Add(path)
.Render("~/output.js");
var expectedTag = string.Format("<script type=\"text/javascript\" src=\"{0}/file1.script.js.squishit.debug.js\"></script>\n", path);
Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
Assert.AreEqual(content, preprocessor.CalledWith);
Assert.AreEqual(1, writerFactory.Files.Count);
Assert.AreEqual("scripty", writerFactory.Files[file1 + ".squishit.debug.js"]);
}
}
示例8: CanBundleJavascriptInRelease
public void CanBundleJavascriptInRelease()
{
const string template = "<h1>{{message}}</h1>";
var templateFileName = "test.hogan.html";
var resolver = StubResolver.ForFile(TestUtilities.PrepareRelativePath(templateFileName));
var readerFactory = new StubFileReaderFactory();
readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(templateFileName), template);
var writerFactory = new StubFileWriterFactory();
string tag;
using(new ResolverFactoryScope(typeof(FileSystemResolver).FullName, resolver))
{
tag = javaScriptBundleFactory
.WithFileReaderFactory(readerFactory)
.WithFileWriterFactory(writerFactory)
.WithDebuggingEnabled(false)
.Create()
.WithPreprocessor(new HoganPreprocessor())
.Add("~/" + templateFileName)
.Render("~/template.js");
}
//are minifier's optimizations here OK?
var compiled =
@"var JST=JST||{};JST.test=new Hogan.Template(function(n,t,i){var r=this;return r.b(i=i||""""),r.b(""<h1>""),r.b(r.v(r.f(""message"",n,t,0))),r.b(""</h1>""),r.fl()})";
Assert.AreEqual(1, writerFactory.Files.Count);
var expectedTag = "<script type=\"text/javascript\" src=\"template.js?r=hash\"></script>";
Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
var actual = writerFactory.Files[TestUtilities.PrepareRelativePath("template.js")];
Assert.AreEqual(compiled, actual);
}
示例9: CanBundleJavascriptInReleaseWithArbitraryHogan
public void CanBundleJavascriptInReleaseWithArbitraryHogan()
{
const string template = "<h1>{{message}}</h1>";
var writerFactory = new StubFileWriterFactory();
string tag;
tag = javaScriptBundleFactory
.WithFileWriterFactory(writerFactory)
.WithDebuggingEnabled(false)
.Create()
.WithPreprocessor(new HoganPreprocessor())
.AddString(template, ".hogan.html")
.Render("~/template.js");
//are minifier's optimizations here OK?
var compiled = @"var JST=JST||{};JST.dummy=new Hogan.Template(";
Assert.AreEqual(1, writerFactory.Files.Count);
var expectedTag = "<script type=\"text/javascript\" src=\"template.js?r=hash\"></script>";
Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
var actual = writerFactory.Files[TestUtilities.PrepareRelativePath("template.js")];
Assert.IsTrue(actual.StartsWith(compiled));
}
示例10: CanBundleDirectoryContentsInRelease_Ignores_Duplicates
public void CanBundleDirectoryContentsInRelease_Ignores_Duplicates()
{
var path = Guid.NewGuid().ToString();
var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.css");
var file2 = TestUtilities.PrepareRelativePath(path + "\\file2.css");
using(new ResolverFactoryScope(typeof(FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 })))
{
var frf = new StubFileReaderFactory();
frf.SetContentsForFile(file1, css2);
frf.SetContentsForFile(file2, css);
var writerFactory = new StubFileWriterFactory();
var tag = cssBundleFactory.WithDebuggingEnabled(false)
.WithFileReaderFactory(frf)
.WithFileWriterFactory(writerFactory)
.Create()
.Add(path)
.Add(file1)
.Render("~/output.css");
var expectedTag = "<link rel=\"stylesheet\" type=\"text/css\" href=\"output.css?r=hash\" />";
Assert.AreEqual(expectedTag, tag);
var combined = "li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}li{margin-bottom:.1em;margin-left:0;margin-top:.1em}th{font-weight:normal;vertical-align:bottom}.FloatRight{float:right}.FloatLeft{float:left}";
Assert.AreEqual(combined, writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.css")]);
}
}
示例11: CanBundleDirectoryContentsInDebug_Ignores_Duplicates
public void CanBundleDirectoryContentsInDebug_Ignores_Duplicates()
{
var path = Guid.NewGuid().ToString();
var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.css");
var file2 = TestUtilities.PrepareRelativePath(path + "\\file2.css");
using(new ResolverFactoryScope(typeof(FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 })))
{
var frf = new StubFileReaderFactory();
frf.SetContentsForFile(file1, css2);
frf.SetContentsForFile(file2, css);
var writerFactory = new StubFileWriterFactory();
var tag = cssBundleFactory.WithDebuggingEnabled(true)
.WithFileReaderFactory(frf)
.WithFileWriterFactory(writerFactory)
.Create()
.Add(path)
.Render("~/output.css");
var expectedTag = string.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}/file1.css\" />\n<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}/file2.css\" />\n", path);
Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
}
}
示例12: CanBundleCssWithMinifiedDirectories
public void CanBundleCssWithMinifiedDirectories()
{
var path = Guid.NewGuid().ToString();
var path2 = Guid.NewGuid().ToString();
var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.css");
var file2 = TestUtilities.PrepareRelativePath(path2 + "\\file2.css");
var resolver = new Mock<IResolver>(MockBehavior.Strict);
resolver.Setup(r => r.IsDirectory(It.IsAny<string>())).Returns(true);
resolver.Setup(r =>
r.ResolveFolder(TestUtilities.PrepareRelativePath(path), It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<string>>()))
.Returns(new[] { file1 });
resolver.Setup(r =>
r.ResolveFolder(TestUtilities.PrepareRelativePath(path2), It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<string>>()))
.Returns(new[] { file2 });
using(new ResolverFactoryScope(typeof(FileSystemResolver).FullName, resolver.Object))
{
var frf = new StubFileReaderFactory();
frf.SetContentsForFile(file1, css2);
frf.SetContentsForFile(file2, css);
var writerFactory = new StubFileWriterFactory();
var tag = cssBundleFactory.WithDebuggingEnabled(false)
.WithFileReaderFactory(frf)
.WithFileWriterFactory(writerFactory)
.WithHasher(new StubHasher("hashy"))
.Create()
.AddDirectory(path)
.AddMinifiedDirectory(path2)
.Render("~/output.css");
Assert.AreEqual("<link rel=\"stylesheet\" type=\"text/css\" href=\"output.css?r=hashy\" />", tag);
var content = writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.css")];
Assert.True(content.StartsWith(minifiedCss2));
Assert.True(content.EndsWith(css));
}
}
示例13: CanMaintainOrderBetweenArbitraryAndFileAssetsInDebug
public void CanMaintainOrderBetweenArbitraryAndFileAssetsInDebug()
{
var file1 = "somefile.css";
var file2 = "anotherfile.css";
var arbitraryCss = ".someClass { color:red }";
var readerFactory = new StubFileReaderFactory();
readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(file1), css);
readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(file2), css2);
var writerFactory = new StubFileWriterFactory();
var tag = new CssBundleFactory()
.WithFileReaderFactory(readerFactory)
.WithFileWriterFactory(writerFactory)
.WithDebuggingEnabled(true)
.Create()
.Add(file1)
.AddString(arbitraryCss)
.Add(file2)
.Render("test.css");
var expectedTag = string.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"somefile.css\" />\n<style type=\"text/css\">{0}</style>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"anotherfile.css\" />\n"
, arbitraryCss);
Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
}
示例14: Includes_Semicolon_And_Newline_Between_Scripts
public void Includes_Semicolon_And_Newline_Between_Scripts()
{
var writerFactory = new StubFileWriterFactory();
var tag = new JavaScriptBundleFactory()
.WithDebuggingEnabled(false)
.WithFileWriterFactory(writerFactory)
.WithHasher(new StubHasher("hashy"))
.Create()
.AddString("first")
.AddString("second")
.Render("~/output.js");
var expectedTag = "<script type=\"text/javascript\" src=\"output.js?r=hashy\"></script>";
Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
var minifiedScript = "first;\nsecond;\n";
Assert.AreEqual(minifiedScript, writerFactory.Files[TestUtilities.PrepareRelativePath(@"output.js")]);
}
示例15: CanMaintainOrderBetweenArbitraryAndFileAssetsInDebug
public void CanMaintainOrderBetweenArbitraryAndFileAssetsInDebug()
{
var file1 = "somefile.js";
var file2 = "anotherfile.js";
var subtract = "function sub(a,b){return a-b}";
var readerFactory = new StubFileReaderFactory();
readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(file1), javaScript);
readerFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(file2), javaScript2);
var writerFactory = new StubFileWriterFactory();
var tag = new JavaScriptBundleFactory()
.WithFileReaderFactory(readerFactory)
.WithFileWriterFactory(writerFactory)
.WithDebuggingEnabled(true)
.Create()
.Add(file1)
.AddString(subtract)
.Add(file2)
.Render("test.js");
var expectedTag = string.Format("<script type=\"text/javascript\" src=\"somefile.js\"></script>\n<script type=\"text/javascript\">{0}</script>\n<script type=\"text/javascript\" src=\"anotherfile.js\"></script>\n"
, subtract);
Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag));
}