在我的测试用例中遇到了问题,我试图模拟返回我的 ICacheProvider
但它总是返回 null
。
[Fact]
public void Raise_ShoultReturnTrue_IfItsInCache()
{
var cacheProvider = Substitute.For<ICacheProvider>();
cacheProvider.Fetch(Arg.Any<string>(), default(Func<IEnumerable<int>>)).ReturnsForAnyArgs(GetFakeCacheDB());
//I was expecting the var below to contain the data from GetFakeCacheDB method
var cacheProviderReturn = cacheProvider.Fetch("anything", returnEmpty);
//there is more stuff here but doesnt matter for the question
}
private HashSet<int> returnEmpty()
{
return new HashSet<int>();
}
private IEnumerable<int> GetFakeCacheDB()
{
var cacheData = new List<int>()
{
57352,
38752
};
return cacheData;
}
public interface ICacheProvider
{
void Add<T>(string key, T item);
void Add<T>(string key, T item, DateTime? absoluteExpiry, TimeSpan? relativeExpiry);
T Fetch<T>(string key, Func<T> dataLookup);
T Fetch<T>(string key, Func<T> dataLookup, DateTime? absoluteExpiry, TimeSpan? relativeExpiry);
void Remove<T>(string key);
}
我的测试用例有什么问题?