public void Should_register_handled_events_singleton() { //Arrange var services = Mock.Of <IServiceCollection>(); var provider = Mock.Of <IServiceProvider>(); Mock.Get(services).Setup(x => x.GetEnumerator()) .Returns(new List <ServiceDescriptor> { new ServiceDescriptor(typeof(INotificationHandler <EventMessage>), new EventHandler()) }.GetEnumerator()); //Act var builder = new MessagingHostConfigurationBuilder(provider, services); builder .AddSubscriberServices(cfg => cfg.FromMediatRHandledEvents().AddAllClasses()) .WithDefaultOptions() .UsePipeline(_ => { }); var config = builder.Build(); //Assert config.Subscribers.Should().NotBeEmpty(); config.Subscribers[0].MessageType.Should().Be(typeof(EventMessage)); config.Subscribers[0].Options.Should().Be(MessagingSubscriberOptions.Default); config.Subscribers[0].Pipeline.Should().NotBeNull(); }
public void Should_register_subscribers_singleton() { //Arrange var services = Mock.Of <IServiceCollection>(); var provider = Mock.Of <IServiceProvider>(); //Act var builder = new MessagingHostConfigurationBuilder(provider, services); builder .AddSubscriberServices(cfg => cfg.FromAssemblyOf <MessageToScanBase>().AddClassesAssignableTo <MessageToScanBase>()) .WithDefaultOptions() .UsePipeline(bld => { }); var config = builder.Build(); //Assert config.Subscribers.Should().NotBeEmpty(); config.Subscribers[0].MessageType.Should().Be(typeof(MessageToScan)); config.Subscribers[0].Options.Should().Be(MessagingSubscriberOptions.Default); config.Subscribers[0].Pipeline.Should().NotBeNull(); }
public void Should_register_handled_topics_singleton() { //Arrange var services = Mock.Of <IServiceCollection>(); var provider = Mock.Of <IServiceProvider>(); //Act var builder = new MessagingHostConfigurationBuilder(provider, services); builder .AddSubscriberServices(cfg => cfg.FromTopics("TopicName")) .WithDefaultOptions() .UsePipeline(_ => { }); var config = builder.Build(); //Assert config.Subscribers.Should().NotBeEmpty(); config.Subscribers[0].MessageType.Should().Be(typeof(object)); config.Subscribers[0].Options.Should().Be(MessagingSubscriberOptions.Default with { TopicName = "TopicName" }); config.Subscribers[0].Pipeline.Should().NotBeNull(); }