Ejemplo n.º 1
0
        public void Should_receive_a_response_from_a_valid_request()
        {
            bool responseHandled = false;
            bool faultHandled    = false;

            CompleteEvent.WaitOne(TimeSpan.FromSeconds(2), true);

            LocalBus.PublishRequest(new ValidRequest(), x =>
            {
                x.Handle <Replay>(r =>
                {
                    responseHandled = true;
                    CompleteEvent.Set();
                });
                x.HandleFault((c, f) =>
                {
                    faultHandled = true;
                    CompleteEvent.Set();
                });
            });

            CompleteEvent.WaitOne(TimeSpan.FromSeconds(20), true);

            Assert.That(responseHandled, Is.True);
            Assert.That(faultHandled, Is.False);
        }
Ejemplo n.º 2
0
        public void Should_receive_a_fault_from_a_failed_request()
        {
            bool responedHendeled = false;
            bool faultHendeled    = false;

            CompleteEvent.WaitOne(TimeSpan.FromSeconds(2), true);

            LocalBus.PublishRequest(new InvalidRequest(), x =>
            {
                x.Handle <Replay>(r =>
                {
                    responedHendeled = true;
                    CompleteEvent.Set();
                });
                x.HandleFault((c, f) =>
                {
                    faultHendeled = true;
                    CompleteEvent.Set();
                });
            });

            CompleteEvent.WaitOne(Debugger.IsAttached ? 5.Minutes() : 20.Seconds(), true);

            Assert.That(responedHendeled, Is.False);
            Assert.That(faultHendeled, Is.True);
        }
Ejemplo n.º 3
0
        public bool Wait()
        {
            bool alreadyCompleted;

            lock (_lock)
                alreadyCompleted = _completed;

            bool result = alreadyCompleted || CompleteEvent.WaitOne(_timeout == TimeSpan.MaxValue ? Int32.MaxValue : (int)_timeout.TotalMilliseconds, true);

            if (!result)
            {
                Fail(RequestTimeoutException.FromCorrelationId(_requestId));
            }

            Close();

            if (_exception != null)
            {
                throw _exception;
            }

            return(result);
        }
Ejemplo n.º 4
0
        public bool Wait()
        {
            bool alreadyCompleted;

            lock (_lock)
                alreadyCompleted = _completed;

            bool result = alreadyCompleted || CompleteEvent.WaitOne(_timeout == TimeSpan.MaxValue
                                                                        ? -1
                                                                        : (int)_timeout.TotalMilliseconds, true);

            if (!result)
            {
                lock (_completionCallbacks)
                {
                    if (_timeoutHandler != null)
                    {
                        _completionCallbacks.Add(asyncResult => _timeoutHandler.HandleTimeout(_message));
                    }
                    else
                    {
                        _exception = new RequestTimeoutException(_requestId);
                    }
                }

                NotifyComplete();
            }

            Close();

            if (_exception != null)
            {
                throw _exception;
            }

            return(result);
        }