Ejemplo n.º 1
0
        /// <summary>
        /// Register a downstream handler. Should start with the handler closest to the application and end with the handler which actually dispatches the message to the command handler.
        /// </summary>
        /// <param name="handler">The handler</param>
        public void RegisterDownstream(IDownstreamHandler handler)
        {
            if (handler == null) throw new ArgumentNullException("handler");

            var newContext = new DownstreamContext(handler);
            if (_downstreamHandlers.Count > 0)
                _downstreamHandlers[_downstreamHandlers.Count - 1].SetNext(newContext);

            _downstreamHandlers.Add(newContext);
        }
Ejemplo n.º 2
0
        public void Destination_IsInvoked()
        {
            var handler = Substitute.For<IUpstreamHandler>();
            var downHandler = Substitute.For<IDownstreamHandler>();
            var pipeline = new Decoupled.Pipeline.Pipeline();
            var context = new DownstreamContext(downHandler);
            var msg = Substitute.For<IUpstreamMessage>();

            pipeline.Add(context);
            pipeline.Add(new UpstreamContext(handler));
            pipeline.Start();
            context.SendUpstream(msg);

            handler.Received().HandleUpstream(Arg.Any<IUpstreamContext>(), msg);
        }
Ejemplo n.º 3
0
        public void DestinationIsNotSet()
        {
            var upContext = new UpstreamContext(new ForwardingUpHandler());
            var destination = Substitute.For<IUpstreamHandler>();
            var downHandler = Substitute.For<IDownstreamHandler>();
            var downContext = new DownstreamContext(downHandler);
            var pipeline = new Decoupled.Pipeline.Pipeline();
            var msg = Substitute.For<IUpstreamMessage>();

            pipeline.Add(downContext);
            pipeline.Add(upContext);
            pipeline.Add(new UpstreamContext(destination));
            pipeline.Start();
            upContext.Invoke(msg);

            destination.Received().HandleUpstream(Arg.Any<IUpstreamContext>(), msg);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add a new downstream handler (from the invoker down to the command handler)
        /// </summary>
        /// <param name="context">Context for the handler</param>
        public void Add(DownstreamContext context)
        {
            if (context == null) throw new ArgumentNullException("context");
            if (_fixed)
                throw new InvalidOperationException(
                    "The pipeline may not be modified after Start() has been called.");

            if (context.IsLast)
                context.SetNext(_myDownContext);
            _downstream.Add(context);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Pipeline" /> class.
 /// </summary>
 public Pipeline()
 {
     _myUpContext = new UpstreamContext(this);
     _myDownContext = new DownstreamContext(this);
 }
 /// <summary>
 /// Sets the next handler (which this will forward messages to)
 /// </summary>
 /// <param name="next">The next.</param>
 public void SetNext(DownstreamContext next)
 {
     if (next == null) throw new ArgumentNullException("next");
     _next = next;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Pipeline" /> class.
 /// </summary>
 public Pipeline()
 {
     _myUpContext   = new UpstreamContext(this);
     _myDownContext = new DownstreamContext(this);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Sets the downstream handler which this one will send upstream messages to
 /// </summary>
 /// <param name="down">Down.</param>
 /// <exception cref="System.ArgumentNullException">down</exception>
 public void SetDownstream(DownstreamContext down)
 {
     if (down == null) throw new ArgumentNullException("down");
     _down = down;
 }