コード例 #1
0
        public async Task Migrations_in_a_race_do_not_throw()
        {
            InitializeDatabase <MigrationsTestEventStore>();

            var columnName = Any.CamelCaseName(3);
            var barrier    = new Barrier(2);

            var migrator = new AnonymousMigrator(c =>
            {
                c.Execute(string.Format(@"alter table [eventstore].[events] add {0} nvarchar(50) null", columnName));
                barrier.SignalAndWait(10000);
            }, version);

            var task1 = Task.Run(() => InitializeDatabase <MigrationsTestEventStore>(migrator));
            var task2 = Task.Run(() => InitializeDatabase <MigrationsTestEventStore>(migrator));

            await Task.WhenAll(task1, task2);

            using (var context = new MigrationsTestEventStore())
            {
                var result = context.QueryDynamic(
                    @"SELECT * FROM sys.columns WHERE name='@columnName'",
                    new Dictionary <string, object> {
                    { "columnName", columnName }
                }).Single();
                result.Should().BeEmpty();
            }
        }
コード例 #2
0
        public void When_a_migration_throws_then_the_change_is_rolled_back()
        {
            InitializeDatabase <MigrationsTestEventStore>();

            var columnName = Any.CamelCaseName(3);

            try
            {
                InitializeDatabase <MigrationsTestEventStore>(
                    new AnonymousMigrator(c =>
                {
                    c.Execute(string.Format(@"alter table [eventstore].[events] add {0} nvarchar(50) null", columnName));
                    throw new DataMisalignedException();
                }, version));
            }
            catch (DataMisalignedException)
            {
            }

            GetAppliedVersions <MigrationsTestEventStore>().Should().NotContain(s => s == version.ToString());

            using (var context = new MigrationsTestEventStore())
            {
                var result = context.QueryDynamic(
                    @"SELECT * FROM sys.columns WHERE name='@columnName'",
                    new Dictionary <string, object> {
                    { "columnName", columnName }
                }).Single();
                result.Should().BeEmpty();
            }
        }