【问题标题】:How to test BundleConfig如何测试 BundleConfig
【发布时间】:2013-05-01 09:10:36
【问题描述】:
我的捆绑包有问题。如this link 报告的那样,没有生成文件 .min。
我必须为它创建一个测试。如何做到这一点?
[TestInitialize]
public void Setup()
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
[TestMethod, Owner("Bundles")]
public void Deve_realizar_bundle_arquivos_min()
{
// Arrange
// Act
var bundle = BundleTable.Bundles.GetBundleFor("~/Scripts");
// Assert
// How to check if file "jquery.pnotify.min.js" is in bundle??
}
【问题讨论】:
标签:
tdd
mstest
asp.net-optimization
【解决方案1】:
您可以通过 1.1-beta1 包中的优化器/优化设置类对捆绑包进行单元测试:
如果您想真正进行单元测试,您还需要实现一个 VirtualPathProvider,但是您应该能够执行以下操作:
BundleCollection bundles = new BundleCollection();
OptimizationSettings config = new OptimizationSettings() {
ApplicationPath = TestContext.DeploymentDirectory,
BundleTable = BundleConfig.RegisterBundles(bundles)
};
BundleResponse response = Optimizer.BuildBundle("~/bundles/js", config);
Assert.IsNotNull(response);
Assert.AreEqual("alert(\"first\")", response.Content);
Assert.AreEqual(JsMinify.JsContentType, response.ContentType);
response = Optimizer.BuildBundle("~/bundles/css", config);
Assert.IsNotNull(response);
Assert.AreEqual("Css1{color:blue}", response.Content);
Assert.AreEqual(CssMinify.CssContentType, response.ContentType);