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.

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top