C# 对象仍然为空,显示其字段

C# 对象仍然为空,显示其字段,c#,nunit,moq,C#,Nunit,Moq,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&

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;            
}
我看不出实现者(Moq.Object)为空的任何原因。VS调试器显示其字段!在立即中,我选中“implementer==null”并得到false。我还是有例外


它如何能同时为null和notnull?

您能分享
QuoteStorageProxy
的(相关)代码吗?是否在某个点重置变量?什么是直接的?另一个注意事项:我们谈论的是单元测试环境吗?如果是这样,它似乎有很多测试逻辑!您可能需要为您的单元测试进行单元测试?这真的与Moq相关吗?您有一个属性
MakeMoq().Object
,它不是空引用(您检查了吗?)。然后将其分配给一个
static
字段,
implementer=MakeMoq().Object。赋值后,
quoteStrageProxy.implementer
null?如果
implementer
稍后为null,则必须有人为其分配了null。
if (implementer == null) // ReferenceEquals do the same
    throw new Exception("...");