public void Invocation_of_callback_before_timeout_should_not_invoke_the_callback_with_timeout_context() { // arrange m_localContainer.Register( Component.For <IService>().LifeStyle.Transient.At(REMOTE_ADDR, SERVICE_KEY, PROXY_KEY) ); m_remoteContainer.Register( Component.For <IService>().Instance(m_service).Named(SERVICE_KEY) ); var proxy = m_localContainer.Resolve <IService>(); var timeoutResult = new WaitableValue <bool>(); var addResult = new WaitableValue <int>(); Action <int, int, Action <int> > delayedCallbackInvocation = (x, y, cb) => Observable.Timer(TimeSpan.FromSeconds(0.3)).Subscribe(_ => cb(x + y)); m_service.Stub(s => s.Add(0, 0, null)) .IgnoreArguments() .Call().Action(delayedCallbackInvocation); // act MessagelessContext.Execute( ctx => proxy.Add(111, 222, result => { if (MessagelessContext.CurrentContext.CallbackTimedOut) { timeoutResult.Value = true; } else { addResult.Value = result; } }), timeout: TimeSpan.FromSeconds(0.5)); // assert var calledWithTimeoutContext = timeoutResult.WaitOne(TimeSpan.FromSeconds(1)); calledWithTimeoutContext.Should().BeFalse(); var calledWithResult = addResult.WaitOne(TimeSpan.FromSeconds(0.1)); calledWithResult.Should().BeTrue(); addResult.Value.Should().Be(111 + 222); }
public void Ignoring_a_callback_with_timeout_should_invoke_the_callback_with_timeout_context() { // arrange m_localContainer.Register( Component.For <IService>().LifeStyle.Transient.At(REMOTE_ADDR, SERVICE_KEY, PROXY_KEY) ); m_remoteContainer.Register( Component.For <IService>().Instance(m_service).Named(SERVICE_KEY) ); var proxy = m_localContainer.Resolve <IService>(); var result = new WaitableValue <bool>(); Action <int, int, Action <int> > ignoreCallback = (x, y, cb) => { }; m_service.Stub(s => s.Add(0, 0, null)) .IgnoreArguments() .Call().Action(ignoreCallback); // act MessagelessContext.Execute( ctx => proxy.Add(111, 222, i => { result.Value = MessagelessContext.CurrentContext.CallbackTimedOut; }), timeout: TimeSpan.FromSeconds(0.5)); // assert var calledWithTimeoutContext = result.WaitOne(TimeSpan.FromSeconds(1)); calledWithTimeoutContext.Should().BeTrue(); result.Value.Should().BeTrue(); }