Example #1
0
        public void Configure(IApplicationBuilder app,
                              IEventStoreBus eventBus,
                              IEventStoreProjections projections,
                              WebSocketHandler wsHandler,
                              VotingReadModelService readModelService,
                              ILogger <Startup> logger)
        {
            app.UseCors("CorsPolicy");
            app.UseMvc();
            app.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Voting API"));
            app.UseWebSockets();
            app.MapWebSocketManager("/ws", wsHandler);

            projections.CreateAsync(Projections.Voting)
            .DefaultRetryAsync()
            .Wait();

            eventBus.Subscribe(
                async(@event) =>
            {
                var snapshot = await readModelService.AddOrUpdate(@event);
                logger.LogInformation(snapshot.ToString());
                await wsHandler.SendMessageToAllAsync(snapshot);
            })
            .DefaultRetryAsync()
            .Wait();
        }
        public async Task Given_CreatedVoting_When_StartAndVoteAndFinish_Then_SameSnapshots()
        {
            var sut = new VotingReadModelService(new FakeRepo());
            await sut.AddOrUpdate(GetCreatedEvent());

            var snapshot = await sut.AddOrUpdate(new VotingStartedEvent(votingId, new string[] { }, VotingPair.Create("C#", "F#")));

            var result = await sut.Get(votingId);

            Assert.Equal(result.Topics, snapshot.Topics);

            snapshot = await sut.AddOrUpdate(new TopicVotedEvent(votingId, "C#"));

            result = await sut.Get(votingId);

            Assert.Equal(result.Topics, snapshot.Topics);

            snapshot = await sut.AddOrUpdate(new VotingFinishedEvent(votingId, "C#"));

            result = await sut.Get(votingId);

            Assert.Equal(result.Topics, snapshot.Topics);
            Assert.Equal(result.Winner, snapshot.Winner);
        }