public async Task Can_get_stream_message_count_with_created_before_date() { using (var fixture = new PostgresStreamStoreFixture("dbo")) { using (var store = await fixture.GetPostgresStreamStore()) { fixture.GetUtcNow = () => new DateTime(2016, 1, 1, 0, 0, 0); var streamId = "stream-1"; await store.AppendToStream( streamId, ExpectedVersion.NoStream, CreateNewStreamMessages(1, 2, 3)); fixture.GetUtcNow = () => new DateTime(2016, 1, 1, 0, 1, 0); await store.AppendToStream( streamId, ExpectedVersion.Any, CreateNewStreamMessages(4, 5, 6)); var streamCount = await store.GetmessageCount(streamId, new DateTime(2016, 1, 1, 0, 1, 0)); streamCount.ShouldBe(3); // The first 3 } } }
public async Task <PostgresStreamStoreFixture> Get( ITestOutputHelper outputHelper, string schema = "dbo") { var fixturePool = _fixturePoolBySchema.GetOrAdd( schema, _ => new ConcurrentQueue <PostgresStreamStoreFixture>()); if (!fixturePool.TryDequeue(out var fixture)) { var databaseName = $"test_{Guid.NewGuid():n}"; var dockerInstance = new PostgresContainer(databaseName); await dockerInstance.Start(); await dockerInstance.CreateDatabase(); fixture = new PostgresStreamStoreFixture( schema, dockerInstance, databaseName, onDispose: () => fixturePool.Enqueue(fixture)); outputHelper.WriteLine($"Using new fixture with db {databaseName}"); } else { outputHelper.WriteLine($"Using pooled fixture with db {fixture.DatabaseName}"); } await fixture.Prepare(); return(fixture); }
public async Task Can_use_multiple_schemas() { using (var fixture = new PostgresStreamStoreFixture("dbo")) { using (var dboStore = await fixture.GetStreamStore()) { using (var barStore = await fixture.GetStreamStore("bar")) { await dboStore.AppendToStream("stream-1", ExpectedVersion.NoStream, CreateNewStreamMessages(1, 2)); await barStore.AppendToStream("stream-1", ExpectedVersion.NoStream, CreateNewStreamMessages(1, 2)); var dboHeadPosition = await dboStore.ReadHeadPosition(); var fooHeadPosition = await dboStore.ReadHeadPosition(); dboHeadPosition.ShouldBe(1); fooHeadPosition.ShouldBe(1); } } } }
public async Task Can_call_initialize_repeatably(string schema) { using (var fixture = await PostgresStreamStoreFixture.Create(schema, testOutputHelper: TestOutputHelper, createSchema: false)) { await fixture.Store.CreateSchemaIfNotExists(); await fixture.Store.CreateSchemaIfNotExists(); } }
public static async Task <PostgresStreamStoreFixture> Create( string schema = "dbo", ITestOutputHelper testOutputHelper = null, bool createSchema = true) { var fixture = new PostgresStreamStoreFixture(schema, testOutputHelper, createSchema); await fixture.Init(); return(fixture); }
public async Task Can_call_initialize_repeatably(string schema) { using (var fixture = new PostgresStreamStoreFixture(schema)) { using (var store = await fixture.GetPostgresStreamStore()) { await store.InitializeStore(); await store.InitializeStore(); } } }
public async Task Can_call_initialize_repeatably(string schema) { using (var fixture = new PostgresStreamStoreFixture(schema, TestOutputHelper)) { using (var store = await fixture.GetUninitializedPostgresStreamStore()) { await store.CreateSchema(); await store.CreateSchema(); } } }
public async Task when_try_scavenge_fails_returns_negative_one() { using (var fixture = await PostgresStreamStoreFixture.Create(testOutputHelper: TestOutputHelper)) { var cts = new CancellationTokenSource(); cts.Cancel(); var result = await fixture.Store.TryScavenge(new StreamIdInfo("stream-1"), cts.Token); result.ShouldBe(-1); } }
public async Task When_stream_does_not_exist_then_stream_message_count_should_be_zero() { using (var fixture = new PostgresStreamStoreFixture("dbo")) { using (var store = await fixture.GetPostgresStreamStore()) { var streamId = "stream-doesnotexist"; var streamCount = await store.GetmessageCount(streamId); streamCount.ShouldBe(0); } } }
public async Task Can_drop_all() { var streamStoreObjects = new List <string>(); string ReadInformationSchema((string name, string table) _) => $"SELECT {_.name}_name FROM information_schema.{_.table} WHERE {_.name}_schema = 'dbo'"; using (var fixture = await PostgresStreamStoreFixture.Create(testOutputHelper: TestOutputHelper)) { await fixture.Store.DropAll(); var commandText = string.Join( $"{Environment.NewLine}UNION{Environment.NewLine}", new[]
public async Task Can_get_stream_message_count() { using (var fixture = new PostgresStreamStoreFixture("dbo")) { using (var store = await fixture.GetPostgresStreamStore()) { var streamId = "stream-1"; await store.AppendToStream( streamId, ExpectedVersion.NoStream, CreateNewStreamMessages(1, 2, 3, 4, 5)); var streamCount = await store.GetmessageCount(streamId); streamCount.ShouldBe(5); } } }
protected override async Task <IStreamStoreFixture> CreateFixture() => await PostgresStreamStoreFixture.Create(testOutputHelper : TestOutputHelper);