2013-05-07 17 views
3

我的套件有問題。文件.min未生成,如this link所報告。如何測試BundleConfig

我必須爲它創建一個測試。這個怎麼做?

[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?? 

} 

回答

0

您可以通過優化/優化設置類的1.1-β1封裝的單元測試包:

您還需要實現的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);