From 45c4c64f135bc3d2ba22090626d611636b7ce0da Mon Sep 17 00:00:00 2001 From: Judah Gabriel Himango Date: Thu, 15 Feb 2024 12:37:09 -0800 Subject: [PATCH] Adds test to ensure runner.Run throws if a migration throws. --- Raven.Migrations.Tests/RunnerTests.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Raven.Migrations.Tests/RunnerTests.cs b/Raven.Migrations.Tests/RunnerTests.cs index 09e9c33..637d0c4 100644 --- a/Raven.Migrations.Tests/RunnerTests.cs +++ b/Raven.Migrations.Tests/RunnerTests.cs @@ -4,6 +4,7 @@ using Raven.Client.Documents.Indexes; using Raven.TestDriver; using Xunit; +using static System.Formats.Asn1.AsnWriter; namespace Raven.Migrations.Tests { @@ -246,6 +247,17 @@ public void Can_call_migrations_that_are_not_direct_subclasses_of_Migration() var development = session.Load("migrated-using-BaseMigration"); development.Should().NotBeNull(); } + + [Fact] + public void Failed_migrations_throw() + { + var options = GetMigrationOptions(); + options.Profiles.Add("migration that throws exception"); + + using var store = GetDocumentStore(); + var runner = new MigrationRunner(store, options, new ConsoleLogger()); + Assert.Throws(() => runner.Run()); + } private MigrationOptions GetMigrationOptions() { @@ -335,7 +347,18 @@ public class _has_problems__with_underscores___ : Migration public override void Up() { } - } + } + + [Migration(6, "migration that throws exception")] + public class MigrationThrowsException : Migration + { + public override void Up() + { + throw new System.Exception("This is failing migration"); + } + } + + public abstract class BaseMigration : Migration {