I am trying to use swtich code, which I should use Owned Instances instead of going around the container.
public class SyncManager { private Func<Owned<ISynchProcessor>> _syncProcessor = null; public SyncManager(Func<Owned<ISynchProcessor>> syncProcessor) { _syncProcessor = syncProcessor; } private void Handle() { using (var service = _syncProcessor()) { service.Value.Process(); } } }
Now I want Moq the Func <Own> and enter it, but calls to _syncProcessor () do not solve anything. So I tried this.
Mock<ITimer> timer = new Mock<ITimer>(); Mock<Func<Owned<ISynchProcessor>>> syncProcessor = new Mock<Func<Owned<ISynchProcessor>>>(); Mock<Owned<ISynchProcessor>> proc = new Mock<Owned<ISynchProcessor>>(); [TestInitialize] public void TestInitialize() { timer = new Mock<ITimer>(); syncProcessor = new Mock<Func<Owned<ISynchProcessor>>>(); syncProcessor.Setup(item => item.Invoke()).Returns(() => proc.Object); }
but it gives me a runtime error that it cannot use an object like System.Linq.Expressions.InstanceMethodCallExpressionN to enter System.Linq.InvocationExpression
source share