gpt4 book ai didi

tdd - 如何测试 BundleConfig

转载 作者:行者123 更新时间:2023-12-04 20:29:52 25 4
gpt4 key购买 nike

我的包有问题。文件 .min 未按照 this link 上的报告生成.

我必须为它创建一个测试。这该怎么做?

[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.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);

关于tdd - 如何测试 BundleConfig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16418633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com