Beispiel #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder.AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });
            services.AddMvcCore().AddApiExplorer().AddJsonFormatters();
            services.AddSwaggerGen(c =>
                                   c.SwaggerDoc("v1", new Info {
                Title = "Voting API", Version = "v1"
            })
                                   );

            services.AddEasyEventSourcing(
                EventStoreOptions.Create(
                    Configuration["EVENT_STORE"],
                    Configuration["EVENT_STORE_MANAGER_HOST"],
                    Configuration["STREAM_NAME"]),
                ReflectionHelper.DomainAssembly);

            services.AddWebSocketManager();
            services.AddSingleton <VotingReadModelService>();
        }
Beispiel #2
0
        private void AddEventStore(IServiceCollection services)
        {
            var options = EventStoreOptions.Create(Configuration);

            services.AddSingleton(EventStoreConnectionFactory.Create(options.ConnectionString));
            services.AddSingleton(new EventTypeResolver(ReflectionHelper.MessagesAssembly));
            services.AddTransient <IRepository, EventStoreRepository>();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var builder       = new ConfigurationBuilder().AddEnvironmentVariables();
            var configuration = builder.Build();

            Console.WriteLine("Starting Event Store Quiz Setup.");

            var options = EventStoreOptions.Create(configuration);
            var conn    = EventStoreConnectionFactory.Create(options.ConnectionString);

            EventStoreSetup.Create(conn, options).Wait();

            Console.WriteLine("Event Store Quiz Setup Done!");
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var builder       = new ConfigurationBuilder().AddEnvironmentVariables();
            var configuration = builder.Build();

            Console.WriteLine("Starting Event Store Quiz Setup.");

            var options     = EventStoreOptions.Create(configuration);
            var projections = new EventStoreProjectionsClient(options);

            Policy.Handle <Exception>()
            .WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
            .ExecuteAsync(async() => await projections.CreateAsync(Projections.QuestionAnswers))
            .Wait();

            Console.WriteLine("Event Store Quiz Setup Done!");
        }
Beispiel #5
0
        public static void Main(string[] args)
        {
            var quitEvent = new ManualResetEvent(false);

            Console.CancelKeyPress += (sender, eArgs) => {
                quitEvent.Set();
                eArgs.Cancel = true;
                Console.WriteLine("Application is shutting down...");
            };

            var builder       = new ConfigurationBuilder().AddEnvironmentVariables();
            var configuration = builder.Build();

            var options      = EventStoreOptions.Create(configuration);
            var typeResolver = new EventTypeResolver(ReflectionHelper.MessagesAssembly);
            var eventBus     = EventStoreConnectionFactory.Create(options.ConnectionString);

            eventBus.Subscribe(
                typeResolver, options.Subscription,
                msg =>
            {
                if (msg is QuestionRightAnsweredEvent rightEvent)
                {
                    Console.WriteLine($"Type:{rightEvent.GetType().Name}, OptionId:{rightEvent.OptionId}, QuestionId: {rightEvent.QuestionId}");
                }

                if (msg is QuestionWrongAnsweredEvent wrongEvent)
                {
                    Console.WriteLine($"Type:{wrongEvent.GetType().Name}, OptionId:{wrongEvent.OptionId}, QuestionId: {wrongEvent.QuestionId}");
                }
            })
            .Wait();

            Console.Write("Application started. Press Ctrl+C to shut down.");
            quitEvent.WaitOne();
        }
Beispiel #6
0
        public void Given_EmptyEventStoreOptions_When_Create_Then_DefaultValues()
        {
            var sut = EventStoreOptions.Create();

            AssertDefaultEventStoreOptions(sut);
        }
Beispiel #7
0
        public void Given_Valid_ManagerHost_When_Create_Then_Exception()
        {
            var sut = EventStoreOptions.Create(null, "admin:changeit@localhost:2113");

            AssertDefaultEventStoreOptions(sut);
        }
Beispiel #8
0
        public void Given_Missing_ManagerHost_When_Create_Then_Exception()
        {
            Action action = () => EventStoreOptions.Create(null, "user:password");

            Assert.ThrowsAny <ArgumentException>(action);
        }
Beispiel #9
0
        public void Given_MissingCredentials_For_ManagerHost_When_Create_Then_Exception()
        {
            Action action = () => EventStoreOptions.Create(null, "localhost:2113");

            Assert.ThrowsAny <ArgumentException>(action);
        }
Beispiel #10
0
        public void Given_Null_EventStoreOptions_When_Create_Then_DefaultValues()
        {
            var sut = EventStoreOptions.Create(null, null);

            AssertDefaultEventStoreOptions(sut);
        }