4

I have a problem with my bundles. Files .min is not being generated as reported on this link.

I have to create a test for it. How to do this?

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

}
Community
  • 1
  • 1
ridermansb
  • 10,779
  • 24
  • 115
  • 226

1 Answers1

0

You can unit test bundles via the Optimizer/Optimization settings classes in the 1.1-beta1 package:

You will also need to implement a VirtualPathProvider if you want to truly unit test this, but then you should be able to do something like:

        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);
Hao Kung
  • 28,040
  • 6
  • 84
  • 93