0

VS 2012,.NET 4.0,Moq.4.1.1308.2321,调试配置。我的静态类像这样创建 Moq 对象:

public static Mock<IQuoteStorage> MakeMoq()
{
    var moq = new Mock<IQuoteStorage>();
    moq.Setup(s => s.GetTickersHistoryStarts()).Returns<Dictionary<string, DateSpan>>(
        delegate
        {
            return new Dictionary<string, DateSpan>();                        
        });

    moq.Setup(s => s.GetMinuteCandlesPacked(It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>())).Returns((string ticker, DateTime start, DateTime end) =>
        {
            return new PackedCandleStream(new List<CandleDataPacked>(), false);                      
        });

    return moq;            
}

我将此 MakeMoq().Object 存储在名为 QuoteStorageProxy 的类的静态变量实现器中。然后我使用这个 QuoteStorageProxy - 创建它的一个实例并调用一些方法。在这种方法中,我检查

if (implementer == null) // ReferenceEquals do the same
    throw new Exception("...");

我看不出实施者(Moq.Object)为空的任何原因。VS 调试器显示它的字段!在立即我检查“implementer == null”并得到错误。我仍然得到例外!

它怎么可能同时为空而不为空?

4

0 回答 0