public async Task Can_get_stream_message_count_with_created_before_date()
        {
            using (var fixture = new MsSqlStreamStoreV3Fixture("dbo"))
            {
                using (var store = await fixture.GetMsSqlStreamStore())
                {
                    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
                }
            }
        }
Exemple #2
0
 public async Task Can_drop_all()
 {
     using (var fixture = await MsSqlStreamStoreV3Fixture.Create())
     {
         await fixture.Store.DropAll();
     }
 }
Exemple #3
0
        public async Task <MsSqlStreamStoreV3Fixture> Get(
            ITestOutputHelper outputHelper,
            string schema = "dbo")
        {
            var fixturePool = _fixturePoolBySchema.GetOrAdd(
                schema,
                _ => new ConcurrentQueue <MsSqlStreamStoreV3Fixture>());

            if (!fixturePool.TryDequeue(out var fixture))
            {
                var dbUniqueName   = (DateTime.UtcNow - DateTime.UnixEpoch).TotalMilliseconds;
                var databaseName   = $"sss-v3-{dbUniqueName}";
                var dockerInstance = new DockerMsSqlServerDatabase(databaseName);
                await dockerInstance.CreateDatabase();

                fixture = new MsSqlStreamStoreV3Fixture(
                    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 MsSqlStreamStoreV3Fixture("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 <MsSqlStreamStoreV3Fixture> Get(
            ITestOutputHelper outputHelper,
            string schema = "dbo")
        {
            var fixturePool = _fixturePoolBySchema.GetOrAdd(
                schema,
                _ => new ConcurrentQueue <MsSqlStreamStoreV3Fixture>());

            if (!fixturePool.TryDequeue(out var fixture))
            {
                var databaseName   = $"sss-v3-{Guid.NewGuid():N}";
                var dockerInstance = new SqlServerContainer(databaseName);
                await dockerInstance.Start();

                await dockerInstance.CreateDatabase();

                fixture = new MsSqlStreamStoreV3Fixture(
                    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);
        }
Exemple #6
0
        public async Task Can_call_initialize_repeatably(string schema)
        {
            using (var fixture = await MsSqlStreamStoreV3Fixture.Create(schema, createSchema: false))
            {
                await fixture.Store.CreateSchemaIfNotExists();

                await fixture.Store.CreateSchemaIfNotExists();
            }
        }
 public async Task Can_drop_all()
 {
     using (var fixture = new MsSqlStreamStoreV3Fixture("dbo"))
     {
         using (var store = await fixture.GetMsSqlStreamStore())
         {
             await store.DropAll();
         }
     }
 }
Exemple #8
0
        public async Task When_schema_is_not_created_then_should_be_indicated()
        {
            using (var fixture = await MsSqlStreamStoreV3Fixture.Create(createSchema: false))
            {
                var result = await fixture.Store.CheckSchema();

                result.ExpectedVersion.ShouldBe(3);
                result.CurrentVersion.ShouldBe(0);
                result.IsMatch().ShouldBeFalse();
            }
        }
Exemple #9
0
        public async Task Can_check_schema()
        {
            using (var fixture = await MsSqlStreamStoreV3Fixture.Create())
            {
                var result = await fixture.Store.CheckSchema();

                result.ExpectedVersion.ShouldBe(3);
                result.CurrentVersion.ShouldBe(3);
                result.IsMatch().ShouldBeTrue();
            }
        }
        public async Task Can_call_initialize_repeatably(string schema)
        {
            using (var fixture = new MsSqlStreamStoreV3Fixture(schema))
            {
                using (var store = await fixture.GetMsSqlStreamStore())
                {
                    await store.CreateSchema();

                    await store.CreateSchema();
                }
            }
        }
Exemple #11
0
 public static async Task<MsSqlStreamStoreV3Fixture> Create(
     string schema = "dbo",
     bool createSchema = true,
     bool deleteDatabaseOnDispose = true)
 {
     var fixture = new MsSqlStreamStoreV3Fixture(
         schema,
         false,
         deleteDatabaseOnDispose,
         createSchema);
     await fixture.Init();
     return fixture;
 }
        public async Task When_schema_is_not_created_then_should_be_indicated()
        {
            using (var fixture = new MsSqlStreamStoreV3Fixture("dbo"))
            {
                using (var store = await fixture.GetUninitializedStreamStore())
                {
                    var result = await store.CheckSchema();

                    result.ExpectedVersion.ShouldBe(3);
                    result.CurrentVersion.ShouldBe(0);
                    result.IsMatch().ShouldBeFalse();
                }
            }
        }
        public async Task Can_migrate()
        {
            // Set up an old schema + data.
            var schema    = "baz";
            var v2Fixture = new MsSqlStreamStoreFixture(schema, deleteDatabaseOnDispose: false);
            var v2Store   = await v2Fixture.GetMsSqlStreamStore();

            await v2Store.AppendToStream("stream-1",
                                         ExpectedVersion.NoStream,
                                         StreamStoreAcceptanceTests.CreateNewStreamMessages(1, 2, 3));

            await v2Store.AppendToStream("stream-2",
                                         ExpectedVersion.NoStream,
                                         StreamStoreAcceptanceTests.CreateNewStreamMessages(1, 2, 3));

            await v2Store.SetStreamMetadata("stream-1", ExpectedVersion.Any, maxAge : 10, maxCount : 20);

            v2Store.Dispose();
            v2Fixture.Dispose();

            // Migrate with V3 schema.
            var v3Fixture = new MsSqlStreamStoreV3Fixture(schema, databaseNameOverride: v2Fixture.DatabaseName);
            var v3Store   = await v3Fixture.GetMsSqlStreamStore();

            var checkSchemaResult = await v3Store.CheckSchema();

            checkSchemaResult.IsMatch().ShouldBeFalse();

            await v3Store.Migrate(CancellationToken.None);

            checkSchemaResult = await v3Store.CheckSchema();

            checkSchemaResult.IsMatch().ShouldBeTrue();

            v3Store.Dispose();
            v3Fixture.Dispose();
        }
Exemple #14
0
        public async Task Can_use_multiple_schemas()
        {
            var dboStore = fixture.Store;

            using (var barFixture = await MsSqlStreamStoreV3Fixture.Create("bar"))
            {
                var barStore = barFixture.Store;

                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 barHeadPosition = await barStore.ReadHeadPosition();

                dboHeadPosition.ShouldBe(1);
                barHeadPosition.ShouldBe(1);
            }
        }
Exemple #15
0
 protected override async Task <IStreamStoreFixture> CreateFixture()
 => await MsSqlStreamStoreV3Fixture.Create("foo");