如何测试BundleConfig

时间:2013-05-07 12:06:23

标签: tdd mstest asp.net-optimization

我的捆绑包有问题。未在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??

}

1 个答案:

答案 0 :(得分:0)

您可以通过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);