Exemplo n.º 1
0
        public void When_Building_A_Handler_For_An_Async_Command()
        {
            _chainOfResponsibility = _chainBuilder.BuildAsync(_requestContext, false).First();

            _chainOfResponsibility.Context.Should().NotBeNull();
            _chainOfResponsibility.Context.Should().BeSameAs(_requestContext);
        }
Exemplo n.º 2
0
 public void Add(IHandleRequestsAsync instance)
 {
     if (_asyncHandlerFactory == null)
         throw new ArgumentException("An instance of an async handler can not be added without an AsyncHandlerFactory.");
     _trackedAsyncObjects.Add(instance);
     _logger.Value.DebugFormat("Tracking async handler instance {0} of type {1}", instance.GetHashCode(), instance.GetType());
 }
        public void When_Building_A_Handler_For_An_Async_Command()
        {
            s_chainOfResponsibility = s_chainBuilder.BuildAsync(s_requestContext, false).First();

            Assert.NotNull(s_chainOfResponsibility.Context);
            Assert.AreSame(s_requestContext, s_chainOfResponsibility.Context);
        }
        public void When_A_Handler_Is_Part_Of_An_Async_Pipeline()
        {
            _pipeline = _pipelineBuilder.BuildAsync(new RequestContext(), false).First();

            TracePipeline().ToString().Should().Contain("MyImplicitHandlerAsync");
            TracePipeline().ToString().Should().Contain("MyLoggingHandlerAsync");
        }
Exemplo n.º 5
0
        private PipelineTracer TracePipeline(IHandleRequestsAsync <TRequest> firstInPipeline)
        {
            var pipelineTracer = new PipelineTracer();

            firstInPipeline.DescribePath(pipelineTracer);
            return(pipelineTracer);
        }
        public void When_Building_An_Async_Pipeline_That_Has_Sync_Handlers()
        {
            _exception = Catch.Exception(() => _pipeline = _pipelineBuilder.BuildAsync(new RequestContext(), false).First());

            Assert.NotNull(_exception);
            Assert.IsInstanceOf(typeof(ConfigurationException), _exception);
            StringAssert.Contains(typeof(MyLoggingHandler <>).Name, _exception.Message);
        }
Exemplo n.º 7
0
        public void When_Building_An_Async_Pipeline_That_Has_Sync_Handlers()
        {
            _exception = Catch.Exception(() => _pipeline = _pipelineBuilder.BuildAsync(new RequestContext(), false).First());

            _exception.Should().NotBeNull();
            _exception.Should().BeOfType <ConfigurationException>();
            _exception.Message.Should().Contain(typeof(MyLoggingHandler <>).Name);
        }
Exemplo n.º 8
0
 public void Add(IHandleRequestsAsync instance)
 {
     if (_asyncHandlerFactory == null)
     {
         throw new ArgumentException("An instance of an async handler can not be added without an AsyncHandlerFactory.");
     }
     _trackedAsyncObjects.Add(instance);
     _logger.Value.DebugFormat("Tracking async handler instance {0} of type {1}", instance.GetHashCode(), instance.GetType());
 }
 public void Release(IHandleRequestsAsync handler)
 {
     var disposable = handler as IDisposable;
     if (disposable != null)
     {
         disposable.Dispose();
     }
     handler = null;
 }
 public void Release(IHandleRequestsAsync handler)
 {
     // ReSharper disable once SuspiciousTypeConversion.Global
     var disposable = handler as IDisposable;
     if (disposable != null)
     {
         disposable.Dispose();
     }
 }
Exemplo n.º 11
0
            public void Release(IHandleRequestsAsync handler)
            {
                var disposable = handler as IDisposable;

                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
Exemplo n.º 12
0
        public void Release(IHandleRequestsAsync handler)
        {
            // ReSharper disable once SuspiciousTypeConversion.Global
            var disposable = handler as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }
        }
        public void Release(IHandleRequestsAsync handler)
        {
            if (!_isTransient)
            {
                return;
            }

            var disposal = handler as IDisposable;

            disposal?.Dispose();
        }
Exemplo n.º 14
0
        private void AppendToAsyncPipeline(IEnumerable <RequestHandlerAttribute> attributes, IHandleRequestsAsync <TRequest> implicitHandler, IRequestContext requestContext)
        {
            IHandleRequestsAsync <TRequest> lastInPipeline = implicitHandler;

            attributes.Each(attribute =>
            {
                var handlerType = attribute.GetHandlerType();
                if (handlerType.GetTypeInfo().GetInterfaces().Contains(typeof(IHandleRequestsAsync)))
                {
                    var decorator = _asyncHandlerFactory.CreateAsyncRequestHandler <TRequest>(attribute, requestContext);
                    lastInPipeline.SetSuccessor(decorator);
                    lastInPipeline = decorator;
                }
                else
                {
                    var message = string.Format("All handlers in an async pipeline must derive from IHandleRequestsAsync. You cannot have a mixed pipeline by including handler {0}", handlerType.Name);
                    throw new ConfigurationException(message);
                }
            });
        }
Exemplo n.º 15
0
 public void Release(IHandleRequestsAsync handler)
 {
 }
Exemplo n.º 16
0
 private IHandleRequestsAsync <TRequest> PushOntoAsyncPipeline(IEnumerable <RequestHandlerAttribute> attributes, IHandleRequestsAsync <TRequest> lastInPipeline, IRequestContext requestContext, bool continueOnCapturedContext)
 {
     attributes.Each(attribute =>
     {
         var handlerType = attribute.GetHandlerType();
         if (handlerType.GetTypeInfo().GetInterfaces().Contains(typeof(IHandleRequestsAsync)))
         {
             var decorator = _asyncHandlerFactory.CreateAsyncRequestHandler <TRequest>(attribute, requestContext);
             decorator.ContinueOnCapturedContext = continueOnCapturedContext;
             decorator.SetSuccessor(lastInPipeline);
             lastInPipeline = decorator;
         }
         else
         {
             var message = string.Format("All handlers in an async pipeline must derive from IHandleRequestsAsync. You cannot have a mixed pipeline by including handler {0}", handlerType.Name);
             throw new ConfigurationException(message);
         }
     });
     return(lastInPipeline);
 }
 public void Release(IHandleRequestsAsync handler)
 {
     var disposable = handler as IDisposable;
     disposable?.Dispose();
 }
            public void Release(IHandleRequestsAsync handler)
            {
                var disposable = handler as IDisposable;

                disposable?.Dispose();
            }
        public void When_Building_An_Async_Pipeline_Allow_ForiegnAttribues()
        {
            _pipeline = _pipeline_Builder.BuildAsync(new RequestContext(), false).First();

            Assert.AreEqual("MyValidationHandlerAsync`1|MyObsoleteCommandHandlerAsync|MyLoggingHandlerAsync`1|", TraceFilters().ToString());
        }
Exemplo n.º 20
0
 public void Release(IHandleRequestsAsync handler)
 {
 }
Exemplo n.º 21
0
 public void Add(IHandleRequestsAsync <TRequest> handler)
 {
     _filters.Add(handler);
 }
Exemplo n.º 22
0
        private void When_Building_An_Async_Pipeline_Allow_Pre_And_Post_Tasks()
        {
            _pipeline = _pipelineBuilder.BuildAsync(new RequestContext(), false).First();

            TraceFilters().ToString().Should().Be("MyValidationHandlerAsync`1|MyPreAndPostDecoratedHandlerAsync|MyLoggingHandlerAsync`1|");
        }
Exemplo n.º 23
0
 /// <summary>
 /// Sets the successor.
 /// </summary>
 /// <param name="successor">The successor.</param>
 public void SetSuccessor(IHandleRequestsAsync <TRequest> successor)
 {
     _successor = successor;
 }
 public void Release(IHandleRequestsAsync handler)
 {
     // todo not supported by all containers
 }
Exemplo n.º 25
0
        public void When_Building_An_Async_Pipeline_Preserve_The_Order()
        {
            _pipeline = _pipeline_Builder.BuildAsync(new RequestContext(), false).First();

            PipelineTracer().ToString().Should().Be("MyLoggingHandlerAsync`1|MyValidationHandlerAsync`1|MyDoubleDecoratedHandlerAsync|");
        }
Exemplo n.º 26
0
        public void When_Building_An_Async_Pipeline_Allow_ForeignAttributes()
        {
            _pipeline = _pipeline_Builder.BuildAsync(new RequestContext(), false).First();

            TraceFilters().ToString().Should().Be("MyValidationHandlerAsync`1|MyObsoleteCommandHandlerAsync|MyLoggingHandlerAsync`1|");
        }