문제

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