From 60021d92f447c9892c7d7686cd9326540576de43 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Mon, 13 Oct 2014 18:15:06 -0700 Subject: [PATCH] Adding test. This test asserts that a failing data migration throws an OrchardException. This exception is then handled by the controller to render the proper error message. --- .../DataMigration/DataMigrationTests.cs | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Orchard.Tests/DataMigration/DataMigrationTests.cs b/src/Orchard.Tests/DataMigration/DataMigrationTests.cs index 3837d5dd8..607139767 100644 --- a/src/Orchard.Tests/DataMigration/DataMigrationTests.cs +++ b/src/Orchard.Tests/DataMigration/DataMigrationTests.cs @@ -237,6 +237,24 @@ namespace Orchard.Tests.DataMigration { return 3; } } + + public class FailingDataMigration : DataMigrationImpl { + public override Feature Feature { + get { return new Feature() { Descriptor = new FeatureDescriptor { Id = "Feature4", Extension = new ExtensionDescriptor { Id = "Module4" } } }; } + } + + public int Create() { + SchemaBuilder.CreateTable("FOO", table => + table.Column("Id", DbType.Int32, column => + column.PrimaryKey().Identity())); + + return 1; + } + + public int UpdateFrom1() { + throw new Exception(); + } + } public class DataMigrationSimpleBuilder : DataMigrationImpl { public override Feature Feature { @@ -471,9 +489,28 @@ Features: Description: Feature "); - _dataMigrationManager.Update("Feature1"); + try {_dataMigrationManager.Update("Feature1"); } + catch (OrchardException) {} + Assert.That(_repository.Table.Count(), Is.EqualTo(0)); + _dataMigrationManager.Update("Feature1"); } + + [Test] + public void FailingDataMigrationShouldThrowOrchardException() { + Init(new[] { typeof(FailingDataMigration) }); + + _folders.Manifests.Add("Module4", @" +Name: Module4 +Version: 0.1 +OrchardVersion: 1 +Features: + Feature4: + Description: Feature +"); + + Assert.Throws(() => _dataMigrationManager.Update("Feature4")); + } } } \ No newline at end of file