1

我正在尝试对创建的自定义助手进行一些单元测试,以呈现捆绑中包含的脚本。

我的问题是我需要为 BundleTable.Bundles对象创建一个模拟,但我没有找到任何相关的方法来实现这一点。

我的方法如下所示:

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;
}

有什么想法可以实现这一目标吗?

我正在使用犀牛模拟。

4

1 回答 1

1

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

于 2014-03-06T17:58:22.820 回答