Exemplo n.º 1
0
        public OutboundQueueWorkerTests()
        {
            _queue = new InMemoryOutboundQueue();

            var services = new ServiceCollection();

            services
            .AddSingleton <ILoggerFactory, NullLoggerFactory>()
            .AddSingleton(typeof(ILogger <>), typeof(NullLogger <>))
            .AddSingleton <IOutboundQueueConsumer, InMemoryOutboundQueue>()
            .AddBus()
            .AddBroker <TestBroker>(options => options.AddDeferredOutboundConnector(_ => new InMemoryOutboundQueue()));

            var serviceProvider = services.BuildServiceProvider(new ServiceProviderOptions {
                ValidateScopes = true
            });

            serviceProvider.GetRequiredService <IOutboundRoutingConfiguration>()
            .Add <IIntegrationMessage>(TestEndpoint.Default);

            _broker = (TestBroker)serviceProvider.GetRequiredService <IBroker>();
            _broker.Connect();

            _worker = new OutboundQueueWorker(serviceProvider, _broker, new NullLogger <OutboundQueueWorker>(), new MessageLogger(new MessageKeyProvider(new[] { new DefaultPropertiesMessageKeyProvider() })), true, 100); // TODO: Test order not enforced

            InMemoryOutboundQueue.Clear();
        }
        public OutboundQueueWorkerTests()
        {
            _queue = new InMemoryOutboundQueue();

            var services = new ServiceCollection();

            services
            .AddSingleton <ILoggerFactory, NullLoggerFactory>()
            .AddSingleton(typeof(ILogger <>), typeof(NullLogger <>))
            .AddSingleton <IOutboundQueueConsumer, InMemoryOutboundQueue>()
            .AddSilverback().WithConnectionTo <TestBroker>(options => options.AddDeferredOutboundConnector(_ => new InMemoryOutboundQueue()));

            var serviceProvider = services.BuildServiceProvider(new ServiceProviderOptions {
                ValidateScopes = true
            });

            serviceProvider.GetRequiredService <IOutboundRoutingConfiguration>()
            .Add <IIntegrationMessage>(TestEndpoint.GetDefault());

            _broker = (TestBroker)serviceProvider.GetRequiredService <IBroker>();
            _broker.Connect();

            _worker = new OutboundQueueWorker(serviceProvider, _broker, new NullLogger <OutboundQueueWorker>(), new MessageLogger(), true, 100); // TODO: Test order not enforced

            InMemoryOutboundQueue.Clear();

            _sampleOutboundMessage = new OutboundMessage <TestEventOne>(
                new TestEventOne {
                Content = "Test"
            }, null, TestEndpoint.GetDefault());
            _sampleOutboundMessage.RawContent =
                new JsonMessageSerializer().Serialize(_sampleOutboundMessage.Content, _sampleOutboundMessage.Headers);
        }