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"); }
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"); }
public ExceptionTests() { var container = new Container(); var serviceLocator = new StructureMapServiceLocator(container); var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator); _mediator = new Mediator(serviceLocatorProvider); }
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"); }