コード例 #1
0
ファイル: Program.cs プロジェクト: trichling/EventSourced
        static async Task Main(string[] args)
        {
            var tpyeResovler     = new FullyQualifiedTypeNameTypeResolver("EventSourced.Example.Aggregate.Events.{0}, EventSourced.Example");
            var connectionString = "Server=(local);Database=SqlStreamStoreDemo;Trusted_Connection=True;MultipleActiveResultSets=true";
            var settings         = new MsSqlStreamStoreSettings(connectionString);
            var streamStore      = new MsSqlStreamStore(settings);

            streamStore.CreateSchema().GetAwaiter().GetResult();

            var eventStore = new SqlStreamStoreEventStore(streamStore, tpyeResovler);
            var system     = new EventSourcingSystem(eventStore);

            var counterCurrentValuesReadModel = new CounterCurrentValuesReadModel(system);
            var allPersistenceIdsReadModel    = new AllPersistenceIdsReadModel(system);

            var counterId = Guid.Parse("8c936406-720a-45d4-b1e0-a95bd595943f");
            var counter   = await system.Get(() => new Counter(counterId));

            if (!counter.IsInitialized())
            {
                counter.Initialize(0);
            }

            counter.Increment(5);
            counter.Decrement(2);

            Thread.Sleep(5000);
        }
コード例 #2
0
        public async Task GivenExistingEventStore_CanBuildAllPersistenceIdsProjection()
        {
            var streamStore  = new InMemoryStreamStore();
            var tpyeResovler = new FullyQualifiedTypeNameTypeResolver("EventSourced.Example.Aggregate.Events.{0}, EventSourced.Example");
            var eventStore   = new SqlStreamStoreEventStore(streamStore, tpyeResovler);

            var system = new EventSourcingSystem(eventStore);

            await system.EventStore.Persist("test1", new { Data = "Test1" });

            await system.EventStore.Persist("test2", new { Data = "Test2" });

            var allPersistenceIdsProjection = new AllPersistenceIdsReadModel(system);

            Assert.Equal(2, allPersistenceIdsProjection.PersistenceIds.Count);
        }