正しいのはどれか。
var mockLogger = new Mock<EntLibLogger>();
mockLogger.Setup(i => i.CreateTracer(It.IsAny<string>()))
.Returns((string operationName) =>
{
var mockTracer = new Mock<EntLibTracer>(operationName);
mockTracer.Setup(i => i.IsTracingEnabled())
.Returns(true);
mockTracer.CallBase = true;
return mockTracer.Object;
});
mockLogger.CallBase = true;
//EntLibLogger.Current is a singleton that is shared across multiple threads.
//This Initialize method will set EntLibLogger.Current to the mocked instance
//instead of the default (non-mocked) configuration
EntLibLogger.Initialize(mockLogger.Object);
また
var mockTracer = new Mock<EntLibTracer>(operationName);
mockTracer.Setup(i => i.IsTracingEnabled())
.Returns(true);
mockTracer.CallBase = true;
var mockLogger = new Mock<EntLibLogger>();
mockLogger.Setup(i => i.CreateTracer(It.IsAny<string>()))
.Returns(mockTracer.Object);
mockLogger.CallBase = true;
EntLibLogger.Initialize(mockLogger.Object);
最初のアプローチは正しいと思いますが、Moq が内部で何らかの魔法をかけていて、検証したかっただけなのかどうかはわかりません :)