Ejemplo n.º 1
0
        private static async Task TestReadSide(Tenant tenant, string streamName, FakeLogFactory logFactory, TestConfigStore configStore)
        {
            var cw = new EventStreamConsumer(configStore, tenant, streamName, "PRODUCT-LEASE", logFactory);
            await cw.InitAsync();

            await cw.RunAndBlock((evts) =>
            {
                Console.Write("Event received ..", evts);
            }, CancellationToken.None);
        }
Ejemplo n.º 2
0
        private static async Task Run()
        {
            var tenant = new Tenant
            {
                TenantId = Guid.Parse("{48A7FB91-7B14-4EB7-98FC-B145B6504BB6}"),
                Name     = "ABC Company"
            };

            var logFactory  = new FakeLogFactory();
            var configStore = new TestConfigStore(logFactory);

            var cw = new EventStreamConsumer(configStore, tenant, Streams.Users, $"{Streams.Users}-lease", logFactory);
            await cw.InitAsync();

            var repoFactory = new RepositoryFactory(configStore, logFactory);

            var docRepo = await repoFactory.CreateDocumentRepositoryAsync <IUserMaterialzeRepository>(tenant).ConfigureAwait(false);

            await cw.RunAndBlock((evts) =>
            {
                foreach (var @evt in evts.OrderBy(e => e.Version))
                {
                    if (evt is UserRegistered)
                    {
                        docRepo.AddUserAsync(new UserDto
                        {
                            UserId = (evt as UserRegistered).AggregateId.ToLowercaseAlphaNum(),
                            Name   = (evt as UserRegistered).UserName,
                            Email  = (evt as UserRegistered).Email
                        }, evt.Version);
                    }

                    else if (evt is UserNameChanged)
                    {
                        docRepo.UpdateUserAsync(new UserDto
                        {
                            UserId = (evt as UserNameChanged).AggregateId.ToLowercaseAlphaNum(),
                            Name   = (evt as UserNameChanged).NewName
                        }, evt.Version);
                    }
                }
            }, CancellationToken.None);
        }