Пример #1
0
        public PipelineTests()
        {
            var container = new Container(c =>
            {
                c.Scan(s =>
                {
                    s.AssemblyContainingType(typeof(RequestPipelineHandler <>));
                    s.ConnectImplementationsToTypesClosing(typeof(IHandle <>));
                    s.ConnectImplementationsToTypesClosing(typeof(IHandle <,>));
                    s.ConnectImplementationsToTypesClosing(typeof(IHandleAsync <>));
                    s.ConnectImplementationsToTypesClosing(typeof(IHandleAsync <,>));
                    s.TheCallingAssembly();
                    s.WithDefaultConventions();
                    s.AddAllTypesOf(typeof(IPreRequestHandler <>));
                    s.AddAllTypesOf(typeof(IPostRequestHandler <>));
                    s.AddAllTypesOf(typeof(IPostRequestResponseHandler <,>));
                });

                c.For(typeof(IHandle <>)).DecorateAllWith(typeof(RequestPipelineHandler <>));
                c.For(typeof(IHandle <,>)).DecorateAllWith(typeof(RequestResponsePipelineHandler <,>));
                c.For(typeof(IHandleAsync <>)).DecorateAllWith(typeof(AsyncRequestPipelineHandler <>));
                c.For(typeof(IHandleAsync <,>)).DecorateAllWith(typeof(AsyncRequestResponsePipelineHandler <,>));
            });

            container.AssertConfigurationIsValid();

            _dispatcher = AppDispatcherFactory.Create(app => app.UseCommonServiceLocator(new StructureMapServiceLocator(container)));
        }
Пример #2
0
        public void ShouldBeAbleToHandleRequestResponse()
        {
            var dispatcher = AppDispatcherFactory.Create(app =>
            {
                app.RegisterHandler <TestRequestResponseMessage, string>(message => message.Data + "-handled");
            });

            dispatcher.Handle <TestRequestResponseMessage, string>(new TestRequestResponseMessage {
                Data = "success"
            })
            .ShouldBe("success-handled");
        }
Пример #3
0
        public void ShouldHandleAsyncRequestResponse()
        {
            var dispatcher = AppDispatcherFactory.Create(app =>
            {
                app.RegisterHandler <TestAsyncRequestResponseMessage, string>(m => Task.FromResult(m.Data + "-handled"));
            });


            dispatcher.HandleAsync <TestAsyncRequestResponseMessage, string>(new TestAsyncRequestResponseMessage {
                Data = "success"
            })
            .Result.ShouldBe("success-handled");
        }
Пример #4
0
        public void ShouldBeAbleToHandleVoidRequest()
        {
            var testEffect = "";

            var dispatcher = AppDispatcherFactory.Create(app =>
            {
                app.RegisterHandler <TestRequestMessage>(message =>
                {
                    testEffect = message.Data;
                });
            });

            dispatcher.Handle(new TestRequestMessage {
                Data = "success"
            });

            testEffect.ShouldBe("success");
        }
Пример #5
0
        public void ShouldHandleAsyncRequest()
        {
            var testEffect = "";

            var dispatcher = AppDispatcherFactory.Create(app =>
            {
                app.RegisterHandler <TestAsyncRequestMessage>(message =>
                {
                    testEffect = message.Data;
                    return(Task.FromResult(0));
                });
            });

            dispatcher.HandleAsync(new TestAsyncRequestMessage {
                Data = "success"
            });

            testEffect.ShouldBe("success");
        }
Пример #6
0
        public IoCHandlerTests()
        {
            var serviceLocator = new StructureMapServiceLocator(new Container(c => c.Scan(s =>
            {
                s.TheCallingAssembly();
                s.ConnectImplementationsToTypesClosing(typeof(IHandle <>));
                s.ConnectImplementationsToTypesClosing(typeof(IHandle <,>));
                s.ConnectImplementationsToTypesClosing(typeof(IHandleAsync <>));
                s.ConnectImplementationsToTypesClosing(typeof(IHandleAsync <,>));
                s.WithDefaultConventions();
            })));

            _dependencyResolver = new CommonServiceLocatorDependencyResolver(serviceLocator);

            _dispatcher = AppDispatcherFactory.Create(app =>
            {
                app.UseDependencyResolver(_dependencyResolver);
            });
        }
Пример #7
0
 /// <summary>
 /// Create a static instance of IAppDispatcher (accessible from AppDispatcher.Instance).
 /// This is the default instance that is used by the the AppDispatcher helper class.
 /// </summary>
 /// <param name="config">AppDispatcher configuration</param>
 public static void Initialize(Action <IAppDispatcherConfigurator> config = null)
 {
     Instance     = AppDispatcherFactory.Create(config);
     _initialized = true;
 }