コード例 #1
0
        public void Should_resolve_main_handler()
        {
            var builder = new StringBuilder();
            var writer  = new StringWriter(builder);

            var container = new Container(cfg =>
            {
                cfg.Scan(scanner =>
                {
                    scanner.TheCallingAssembly();
                    scanner.IncludeNamespaceContainingType <Ping>();
                    scanner.WithDefaultConventions();
                    scanner.AddAllTypesOf(typeof(INotificationHandler <>));
                });
                cfg.For <TextWriter>().Use(writer);
            });

            var serviceLocator         = new StructureMapServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            var mediator = new Mediator(serviceLocatorProvider);

            mediator.Publish(new Ping {
                Message = "Ping"
            });

            var result = builder.ToString().Split(new [] { Environment.NewLine }, StringSplitOptions.None);

            result.ShouldContain("Ping Pong");
            result.ShouldContain("Ping Pung");
        }
コード例 #2
0
        public void Should_resolve_main_void_handler()
        {
            var builder = new StringBuilder();
            var writer  = new StringWriter(builder);

            var container = new Container(cfg =>
            {
                cfg.Scan(scanner =>
                {
                    scanner.TheCallingAssembly();
                    scanner.IncludeNamespaceContainingType <Ping>();
                    scanner.WithDefaultConventions();
                    scanner.AddAllTypesOf(typeof(IAsyncRequestHandler <,>));
                });
                cfg.For <TextWriter>().Use(writer);
            });


            var serviceLocator         = new StructureMapServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            var mediator = new Mediator(serviceLocatorProvider);

            var response = mediator.SendAsync(new Ping {
                Message = "Ping"
            });

            Task.WaitAll(response);

            builder.ToString().ShouldBe("Ping Pong");
        }
コード例 #3
0
ファイル: ExceptionTests.cs プロジェクト: strvmarv/MediatR
        public ExceptionTests()
        {
            var container              = new Container();
            var serviceLocator         = new StructureMapServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            _mediator = new Mediator(serviceLocatorProvider);
        }
コード例 #4
0
ファイル: SendTests.cs プロジェクト: strvmarv/MediatR
        public void Should_resolve_main_handler()
        {
            var container = new Container(cfg =>
                                          cfg.Scan(scanner =>
            {
                scanner.TheCallingAssembly();
                scanner.IncludeNamespaceContainingType <Ping>();
                scanner.WithDefaultConventions();
                scanner.AddAllTypesOf(typeof(IRequestHandler <,>));
            }));

            var serviceLocator         = new StructureMapServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            var mediator = new Mediator(serviceLocatorProvider);

            var response = mediator.Send(new Ping {
                Message = "Ping"
            });

            response.Message.ShouldBe("Ping Pong");
        }