Question

I am trying to do some unit tests for a custom helper created to render the scripts included in a bundle.

My problem is I need to create a mock for BundleTable.Bundles object, but I didn't find any relevant way how I can achieve this.

My method looks like here:

public IEnumerable<string> GetBundleFilesCollection(string bundleUrl)
{
        bundleUrl = string.Concat("~", bundleUrl);
        var collection = new BundleCollection { BundleTable.Bundles.GetBundleFor(bundleUrl) };
        var bundleResolver = new BundleResolver(collection);
        IEnumerable<string> fileUrls = bundleResolver.GetBundleContents(bundleUrl);
        return fileUrls;
}

Any ideas how I can achieve this?

I am using Rhino Mocks.

Était-ce utile?

La solution

The Bundles property on BundleTable is static and therefore not mockable (with Rhino Mocks). Perhaps you can populate the Bundles collection with data that would satisfy your test?

There are commercial products that let you mock/stub static methods (I think TypeMock Isolator allows this).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top