Ejemplo n.º 1
0
        public void Should_resolve_topic_name_from_custom_resolver()
        {
            //Arrange
            var sut = new DefaultTopicRegistry(Mock.Of <IConfiguration>());

            //Act
            var topicName = sut.GetTopicForMessageType(typeof(MyEvent));

            //Assert
            topicName.Should().Be("cucu");
        }
Ejemplo n.º 2
0
        private static ContractCommandHandlers GetCommandHandler()
        {
            var configurationBuilder = new ConfigurationBuilder()
                                       .SetBasePath(Directory.GetCurrentDirectory())
                                       .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                       .AddEnvironmentVariables();

            var environment   = Environment.GetEnvironmentVariable("NETCORE_ENVIRONMENT");
            var isDevelopment = string.Equals(environment, "development", StringComparison.OrdinalIgnoreCase);

            if (isDevelopment)
            {
                configurationBuilder.AddUserSecrets(Assembly.GetCallingAssembly());
            }

            var configuration = configurationBuilder.Build();

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                         .Enrich.FromLogContext()
                         .Enrich.With <CorrelationLogEventEnricher>()
                         .WriteTo.MSSqlServer(configuration.GetConnectionString("Logs"), "Logs", autoCreateSqlTable: true)
                         .CreateLogger();

            var loggerFactory = new LoggerFactory();

            loggerFactory.AddSerilog();

            var stanConnectionProvider  = new StanConnectionProvider(configuration, new Logger <StanConnectionProvider>(loggerFactory), null);
            var topicRegistry           = new DefaultTopicRegistry(configuration);
            var messageTypeRegistry     = new DefaultMessageTypeRegistry();
            var messageSerdes           = new NewtonsoftJsonMessageSerDes(messageTypeRegistry);
            var messagingTopicPublisher = new NatsMessagingTopicPublisher(stanConnectionProvider, new Logger <NatsMessagingTopicPublisher>(loggerFactory));
            var messageBusPublisher     = new MessageBusPublisher(messagingTopicPublisher, topicRegistry, messageSerdes, configuration);

            var scripts         = new Scripts();
            var eventRepository = new AdoNetEventRepository(scripts, new Logger <AdoNetEventRepository>(loggerFactory), new Options());

            var eventStoreSerDes    = new NewtonsoftJsonEventStoreSerDes();
            var eventStore          = new EventStore.EventStore(eventRepository, eventStoreSerDes, new Logger <EventStore.EventStore>(loggerFactory));
            var eventStoreDecorator = new MessagingEventStoreDecorator(eventStore, messageBusPublisher, new MessagingTopicResolver(new Options()));
            var mediator            = new OpenFaaSMediator(configuration, new Logger <OpenFaaSMediator>(loggerFactory));
            var repository          = new EventSourcedRepository <Contract>(eventStoreDecorator, null, mediator, new EventSourcingOptions(), new Logger <EventSourcedRepository <Contract> >(loggerFactory));
            var result = new ContractCommandHandlers(repository);

            //disposables = new List<IDisposable>{stanConnectionProvider};

            return(result);
        }