4

我的捆绑包有问题。文件.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??

}
4

1 回答 1

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);
于 2013-05-17T23:28:43.080 回答