public void Execute() { // validate all steps var validator = new Validator(_options); string errors; string warnings; // ReSharper disable RedundantEnumerableCastCall validator.Validate(_downMigrations.Concat(_upMigrations).Cast<IMigrationReporter>(), out errors, out warnings); // .Cast<IMigrationReporter>() is required for .NET 3.5 // ReSharper restore RedundantEnumerableCastCall if (!string.IsNullOrEmpty(errors)) { throw new InvalidOperationException("Cannot execute the migration(s) as there are validation errors:" + Environment.NewLine + errors); } if (!string.IsNullOrEmpty(warnings)) { Log.Warning(warnings); } // execute all steps foreach (IMigrationStep step in _downMigrations) { ExecuteStep(step); } foreach (IMigrationStep step in _upMigrations) { ExecuteStep(step); } }
public void Execute() { if (IsExecuted) throw new InvalidOperationException("Cannot execute the same batch twice."); IsExecuted = true; // validate all steps var validator = new Validator(_options); string errors; string warnings; // ReSharper disable RedundantEnumerableCastCall validator.Validate(_migrations.Cast<IMigrationReporter>(), out errors, out warnings); // .Cast<IMigrationReporter>() is required for .NET 3.5 // ReSharper restore RedundantEnumerableCastCall if (!string.IsNullOrEmpty(errors)) { throw new InvalidOperationException("Cannot execute the migration(s) as there are validation errors:" + Environment.NewLine + errors); } if (!string.IsNullOrEmpty(warnings)) { Log.Warning(warnings); } // execute all steps foreach (IMigrationStep step in _migrations) { ExecuteStep(step); } Debug.Assert(IsExecuted, "At the end of this method _isExecuted must be true."); }
private static void Validate(MigrationOptions options, IMigrationReport report, out string errors, out string warnings) { var validator = new Validator(options); IMigrationReporter reporter = MockRepository.GenerateStub<IMigrationReporter>(); reporter.Expect(r => r.Report(null)).IgnoreArguments().Return(report); IMigrationReporter[] reporters = new[] { reporter }; validator.Validate(reporters, out errors, out warnings); }
private static void Validate(IEnumerable<ProviderInfo> providerInfos, MigrationOptions options, IMigrationReport report, out string errors, out string warnings) { var validator = new Validator(providerInfos, options); IMigrationReporter reporter = A.Fake<IMigrationReporter>(); A.CallTo(() => reporter.Report(A<IMigrationContext>._)).Returns(report); IMigrationReporter[] reporters = new[] { reporter }; validator.Validate(reporters, out errors, out warnings); }