예제 #1
0
        public E2EBase()
        {
            r = new Random();

            //Config
            var config = new ConfigurationBuilder()
                         .AddJsonFile("config.json")
                         .AddJsonFile("config.user.json", true);
            var configRoot = config.Build();

            //IoC
            var collection = new ServiceCollection();

            collection.AddSingleton <IDomainEventHandler <TestEvent>, TestEventHandler>();
            serviceProvider = collection.BuildServiceProvider();

            eventTypes = new Dictionary <string, Type> {
                { typeof(TestEvent).FullName, typeof(TestEvent) }
            };

            mockLogger = new MockLogger <DomainEventPublisher>();

            var publisherSection = configRoot.GetSection("Publisher.Settings");

            publisherSettings       = GetSettings <DomainEventPublisherSettings>(publisherSection);
            publisherSettings.Topic = publisherSection["Address"];
            publisher = new DomainEventPublisher(publisherSettings, mockLogger);

            var receiverSection = configRoot.GetSection("Receiver.Settings");

            receiverSettings       = GetSettings <DomainEventReceiverSettings>(receiverSection);
            receiverSettings.Queue = publisherSection["Address"];
            enabled = configRoot.GetValue <bool>("EnableE2ETests");
        }
예제 #2
0
        public void Install(IServiceCollection services, IConfigurationRoot configuration)
        {
            var config    = configuration.GetSection("ServiceBus");
            var rsettings = new DomainEventReceiverSettings {
                Queue      = config.GetValue <string>("Queue"),
                AppName    = config.GetValue <string>("AppName"),
                Protocol   = config.GetValue <string>("Protocol"),
                PolicyName = config.GetValue <string>("Policy"),
                Key        = config.GetValue <string>("Key"),
                Namespace  = config.GetValue <string>("Namespace"),
                Durable    = 1,
                Credits    = config.GetValue <int>("Credits")
            };

            services.AddSingleton(rsettings);

            var psettings = new DomainEventPublisherSettings {
                Topic      = config.GetValue <string>("Topic"),
                AppName    = config.GetValue <string>("AppName"),
                Protocol   = config.GetValue <string>("Protocol"),
                PolicyName = config.GetValue <string>("Policy"),
                Key        = config.GetValue <string>("Key"),
                Namespace  = config.GetValue <string>("Namespace"),
                Durable    = 1,
                Credits    = config.GetValue <int>("Credits")
            };

            services.AddSingleton(psettings);

            // Register Hosted Services
            services.AddTransient <IDomainEventPublisher, DomainEventPublisher>();
            services.AddTransient <IDomainEventOutboxPublisher, DomainEventOutboxPublisher <DatabaseContext> >();
            services.AddTransient <IDomainEventHandler <WidgetStageChangedEvent>, WidgetStateChangedHandler>();
            services.AddSingleton <IDomainEventReceiver, DomainEventReceiver>();

            var receiverHostedServiceSettings = configuration.GetSection("ReceiverHostedService").Get <ReceiverHostedServiceSettings>();

            receiverHostedServiceSettings.MessageTypes = new Dictionary <string, Type> {
                { typeof(WidgetStageChangedEvent).FullName, typeof(WidgetStageChangedEvent) }
            };
            services.AddSingleton(receiverHostedServiceSettings);
            services.AddHostedService <ReceiverHostedService>();

            // outbox hosted service
            var outboxConfiguration = configuration.GetSection("OutboxHostedService").Get <OutboxHostedServiceConfiguration>();

            services.AddSingleton(outboxConfiguration);
            services.AddHostedService <OutboxHostedService <DatabaseContext> >();
        }
예제 #3
0
        public BaseHostTest()
        {
            random = new Random();
            var start = random.Next(10000, Int16.MaxValue);
            var port  = GetAvailablePort(start);

            receiverSettings = new DomainEventReceiverSettings()
            {
                Protocol   = "amqp",
                PolicyName = "guest",
                Key        = "guest",
                Namespace  = $"localhost:{port}",
                Queue      = "queue",
                AppName    = "unittest" + port.ToString()
            };

            publisterSettings = new DomainEventPublisherSettings()
            {
                Protocol   = "amqp",
                PolicyName = "guest",
                Key        = "guest",
                Namespace  = $"localhost:{port}",
                Topic      = "/exchange/test/",
                AppName    = "unittest" + port.ToString()
            };
            Address = new Address(publisterSettings.ConnectionString);

            host = new ContainerHost(Address);
            host.Listeners[0].SASL.EnableExternalMechanism  = true;
            host.Listeners[0].SASL.EnableAnonymousMechanism = true;
            host.Open();

            eventTypes = new Dictionary <string, Type> {
                { typeof(TestEvent).FullName, typeof(TestEvent) }
            };

            var services = new ServiceCollection();

            provider = services.BuildServiceProvider();
        }
예제 #4
0
        public StubTest()
        {
            var services = new ServiceCollection();

            services.AddLogging();
            services.AddSingleton <IDomainEventHandler <TestEvent>, TestEventHandler>();
            var provider = services.BuildServiceProvider();

            var eventTypeLookup = new Dictionary <string, Type> {
                { typeof(TestEvent).FullName, typeof(TestEvent) },
            };

            this.broker = new ConcurrentQueueBroker();
            var psettings = new DomainEventPublisherSettings()
            {
                Topic = "topic"
            };
            var rsettings = new DomainEventReceiverSettings();

            this.publisher = new DomainEventPublisherStub(psettings, new NullLogger <DomainEventPublisherStub>(), broker);
            this.receiver  = new DomainEventReceiverStub(rsettings, provider, new NullLogger <DomainEventReceiverStub>(), broker);

            this.receiver.StartAndListen(eventTypeLookup);
        }
예제 #5
0
 public DomainEventPublisherStub(DomainEventPublisherSettings settings, ILogger <DomainEventPublisherStub> logger, IStubBroker queue) : base(settings, logger)
 {
     this.queue = queue;
 }
 public DomainEventOutboxPublisher(DomainEventPublisherSettings settings, TDbContext context, ILogger <DomainEventOutboxPublisher <TDbContext> > logger)
 {
     Settings     = settings;
     this.context = context;
     Logger       = logger;
 }