Example #1
0
        protected (IStreamStore, Action) GetStore()
        {
            IStreamStore streamStore = null;
            IDisposable  disposable  = null;

            Output.WriteLine(ConsoleColor.Yellow, "Store type:");
            new Menu()
            .Add("InMem", () => streamStore = new InMemoryStreamStore())
            .Add("MS SQL V2 (Docker)",
                 () =>
            {
                var fixture = new MsSqlStreamStoreFixture("dbo");
                Console.WriteLine(fixture.ConnectionString);
                streamStore = fixture.GetStreamStore().Result;
                disposable  = fixture;
            })
            .Add("MS SQL V3 (Docker)",
                 () =>
            {
                var fixture = new MsSqlStreamStoreV3Fixture("dbo");
                Console.WriteLine(fixture.ConnectionString);
                streamStore = fixture.GetStreamStore().Result;
                disposable  = fixture;
            })
            .Add("MS SQL V3 (LocalDB)",
                 () =>
            {
                var sqlLocalDb = new SqlLocalDb();
                Console.WriteLine(sqlLocalDb.ConnectionString);
                streamStore = sqlLocalDb.StreamStore;
                disposable  = sqlLocalDb;
            })
            .Add("Postgres (Docker)",
                 () =>
            {
                var fixture = new PostgresStreamStoreFixture("dbo");
                Console.WriteLine(fixture.ConnectionString);
                streamStore = fixture.GetPostgresStreamStore(true).Result;
                disposable  = fixture;
            })
            .Add("Postgres (Server)",
                 () =>
            {
                Console.Write("Enter the connection string: ");
                var connectionString = Console.ReadLine();
                var fixture          = new PostgresStreamStoreFixture("dbo", connectionString);
                Console.WriteLine(fixture.ConnectionString);
                streamStore = fixture.GetPostgresStreamStore(true).Result;
                disposable  = fixture;
            })
            .Display();

            return(
                streamStore,
                () =>
            {
                streamStore.Dispose();
                disposable?.Dispose();
            });
        }
Example #2
0
        protected IStreamStore GetStore()
        {
            IStreamStore streamStore = null;

            Output.WriteLine(ConsoleColor.Yellow, "Store type:");
            new Menu()
            .Add("InMem", () => streamStore = new InMemoryStreamStore())
            .Add("MS SQL (SqlLocalDB, NamedPipes)", () => streamStore = new MsSqlStreamStoreFixture("dbo").GetStreamStore().Result)
            .Display();

            return(streamStore);
        }
Example #3
0
 public async Task ConcurrentUnitOfWorkCanNotBeNull()
 {
     using (var fixture = new MsSqlStreamStoreFixture("dbo"))
     {
         using (var store = await fixture.GetStreamStore())
         {
             Assert.Throws <ArgumentNullException>(() =>
                                                   new AsyncRepository <AggregateRootEntityStub>(
                                                       AggregateRootEntityStub.Factory, null,
                                                       store,
                                                       new EventDeserializer()));
         }
     }
 }
Example #4
0
        public async Task GetOptionalAsyncReturnsEmpty()
        {
            using (var fixture = new MsSqlStreamStoreFixture("dbo"))
            {
                using (var store = await fixture.GetStreamStore())
                {
                    var sut = new RepositoryScenarioBuilder(store)
                              .BuildForAsyncRepository();

                    var result = await sut.GetOptionalAsync(_model.UnknownIdentifier);

                    Assert.Equal(result, Optional <AggregateRootEntityStub> .Empty);
                }
            }
        }
Example #5
0
        public async Task GetReturnsRootOfKnownId()
        {
            using (var fixture = new MsSqlStreamStoreFixture("dbo"))
            {
                using (var store = await fixture.GetMsSqlStreamStore())
                {
                    var sut = new RepositoryScenarioBuilder(store)
                              .ScheduleAppendToStream(_model.KnownIdentifier, new EventStub(1))
                              .BuildForAsyncRepository();

                    var result = await sut.GetAsync(_model.KnownIdentifier);

                    result.RecordedEvents.ShouldBeEquivalentTo(new[] { new EventStub(1) });
                }
            }
        }
Example #6
0
        public async Task GetOptionalAsyncReturnsRootForKnownId()
        {
            using (var fixture = new MsSqlStreamStoreFixture("dbo"))
            {
                using (var store = await fixture.GetStreamStore())
                {
                    var sut = new RepositoryScenarioBuilder(store)
                              .ScheduleAttachToUnitOfWork(new Aggregate(_model.KnownIdentifier, 0, _root))
                              .BuildForAsyncRepository();

                    var result = await sut.GetOptionalAsync(_model.KnownIdentifier);

                    Assert.Equal(result, new Optional <AggregateRootEntityStub>(_root));
                }
            }
        }
Example #7
0
        public async Task AddAttachesToUnitOfWork()
        {
            using (var fixture = new MsSqlStreamStoreFixture("dbo"))
            {
                using (var store = await fixture.GetStreamStore())
                {
                    var sut = new RepositoryScenarioBuilder(store)
                              .BuildForAsyncRepository();

                    sut.Add(_model.KnownIdentifier, _root);

                    Aggregate aggregate;
                    var       result = sut.UnitOfWork.TryGet(_model.KnownIdentifier, out aggregate);
                    Assert.True(result);
                    Assert.Equal(aggregate.Identifier, _model.KnownIdentifier);
                    Assert.Equal(aggregate.Root, _root);
                }
            }
        }
Example #8
0
        public async Task GetAsyncThrows()
        {
            using (var fixture = new MsSqlStreamStoreFixture("dbo"))
            {
                using (var store = await fixture.GetStreamStore())
                {
                    var sut = new RepositoryScenarioBuilder(store)
                              .BuildForAsyncRepository();

                    var exception =
                        await Assert.ThrowsAsync <AggregateNotFoundException>(async() =>
                    {
                        var _ = await sut.GetAsync(_model.UnknownIdentifier);
                    });

                    Assert.Equal(exception.Identifier, _model.UnknownIdentifier);
                    Assert.Equal(exception.ClrType, typeof(AggregateRootEntityStub));
                }
            }
        }
 private static async Task MainAsync(CancellationToken cancellationToken)
 {
     try
     {
         using (var fixture = new MsSqlStreamStoreFixture("dbo"))
         {
             using (var store = await fixture.GetStreamStore())
             {
                 using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken))
                 {
                     await RunLoadTest(cts, store);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw;
     }
 }