public AddMigrationCommand(string name, bool force, bool ignoreChanges)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));

            Execute(
                () =>
                    {
                        var rescaffolding = false;

                        using (var facade = GetFacade())
                        {
                            var pendingMigrations = facade.GetPendingMigrations();

                            if (pendingMigrations.Any())
                            {
                                var lastMigration = pendingMigrations.Last();

                                if (!string.Equals(lastMigration, name, StringComparison.OrdinalIgnoreCase)
                                    &&
                                    !string.Equals(
                                        lastMigration.MigrationName(), name, StringComparison.OrdinalIgnoreCase))
                                {
                                    throw Error.MigrationsPendingException(pendingMigrations.Join());
                                }

                                rescaffolding = true;
                                name = lastMigration;
                            }

                            WriteLine(Strings.LoggingGenerate(name));

                            var scaffoldedMigration = facade.Scaffold(
                                name, Project.GetLanguage(), Project.GetRootNamespace(), ignoreChanges);
                            var userCodePath = new MigrationWriter(this)
                                .Write(
                                    scaffoldedMigration,
                                    rescaffolding,
                                    force,
                                    name);

                            if (!rescaffolding)
                            {
                                WriteWarning(Strings.SnapshotBehindWarning(scaffoldedMigration.MigrationId));
                            }

                            Project.OpenFile(userCodePath);
                        }
                    });
        }
        private void TestWrite(Func<MigrationWriter, ScaffoldedMigration, string> action, bool skipUserCodeVerification = false)
        {
            var command = CreateCommand(_projectDir);
            var writer = new MigrationWriter(command);
            var scaffoldedMigration = new ScaffoldedMigration
                {
                    MigrationId = MigrationId,
                    Language = Language,
                    Directory = MigrationsDirectory,
                    UserCode = "The user code.",
                    DesignerCode = "The designer code.",
                    Resources =
                        {
                            { ResourceName, "The resource." }
                        }
                };

            var relativeUserCodePath = action(writer, scaffoldedMigration);

            Assert.Equal(UserCodePath, relativeUserCodePath);

            if (!skipUserCodeVerification)
            {
                var userCodePath = Path.Combine(_projectDir, UserCodePath);
                Assert.Equal("The user code.", File.ReadAllText(userCodePath));
            }

            var designerCodePath = Path.Combine(_projectDir, DesignerCodePath);
            Assert.Equal("The designer code.", File.ReadAllText(designerCodePath));

            var resourcesPath = Path.Combine(_projectDir, ResourcesPath);

            using (var reader = new ResXResourceReader(resourcesPath))
            {
                var resources = reader.Cast<DictionaryEntry>();

                Assert.Equal(1, resources.Count());
                Assert.Contains(new DictionaryEntry(ResourceName, "The resource."), resources);
            }
        }