public void Constructor_should_default_TargetVersion_to_negative_1()
        {
            //  act
            var args = new MigrateCommandArgs();

            //  assert
            Assert.AreEqual(-1, args.TargetVersion);
        }
Пример #2
0
        public void Setup()
        {
            _commandArgs            = new MigrateCommandArgs();
            _commandArgs.Connection = TestConnectionString;

            _mockLog = new MockLog1();

            _mockMigrationScripts = new List <IMigrationScriptFile>();

            _mockMigrationDir = new Mock <IMigrationDirectory>();
            _mockMigrationDir.Setup(x => x.GetScripts()).Returns(() => _mockMigrationScripts);

            _migrateCommand     = new MigrateCommand(_mockMigrationDir.Object);
            _migrateCommand.Log = _mockLog;

            //  setup the mock migration scripts
            var mockScript1 = new Mock <IMigrationScriptFile>();

            mockScript1.SetupGet(x => x.Version).Returns(1);
            mockScript1.Setup(x => x.Read()).Returns(() => new MigrationScriptContents(
                                                         @"CREATE TABLE [TestTable] (Id INT NOT NULL)
                                                                GO
                                                                INSERT INTO [TestTable] (Id) VALUES (1)",
                                                         @"DROP TABLE [TestTable]"));
            _mockMigrationScripts.Add(mockScript1.Object);

            var mockScript2 = new Mock <IMigrationScriptFile>();

            mockScript2.SetupGet(x => x.Version).Returns(2);
            mockScript2.Setup(x => x.Read()).Returns(() => new MigrationScriptContents(
                                                         "INSERT INTO [TestTable] (Id) VALUES (2)",
                                                         "DELETE FROM [TestTable] WHERE Id = 2"));
            _mockMigrationScripts.Add(mockScript2.Object);

            //  setup a migration script that throws an exception during Setup, but don't add it to the scripts collection
            _mockScriptWithBadSetup = new Mock <IMigrationScriptFile>();
            _mockScriptWithBadSetup.SetupGet(x => x.Version).Returns(3);
            _mockScriptWithBadSetup.SetupGet(x => x.FilePath).Returns("C:\\3_my_bad_script.sql");
            _mockScriptWithBadSetup.Setup(x => x.Read()).Returns(() => new MigrationScriptContents(
                                                                     "INSERT INTO [NonExistantTable] (Id) VALUES (1)",
                                                                     null));

            //  setup a migration script that throws an exception during Teardown, but don't add it to the scripts collection
            _mockScriptWithBadTeardown = new Mock <IMigrationScriptFile>();
            _mockScriptWithBadTeardown.SetupGet(x => x.Version).Returns(4);
            _mockScriptWithBadTeardown.SetupGet(x => x.FilePath).Returns("C:\\4_my_bad_script.sql");
            _mockScriptWithBadTeardown.Setup(x => x.Read()).Returns(() => new MigrationScriptContents(
                                                                        "INSERT INTO [TestTable] (Id) VALUES (4)",
                                                                        "DELETE FROM [NonExistantTable] WHERE Id = 4"));
            CreateDatabase();
        }