コード例 #1
0
 public void Setup()
 {
     _mockLog            = new MockLog1();
     _mockMigrationDir   = new Mock <IMigrationDirectory>();
     _versionCommand     = new VersionCommand(_mockMigrationDir.Object);
     _versionCommand.Log = _mockLog;
     CreateDatabase();
 }
コード例 #2
0
 private static string GetArgumentList(ICommand command)
 {
     using (var logger = new MockLog1())
     {
         var writer = new CommandHelpWriter(logger);
         writer.WriteArgumentList(command.GetArgumentsType());
         return(logger.Output);
     }
 }
コード例 #3
0
        public void Should_Be_Able_To_Add_Logs_Manually()
        {
            var logRepository = new LogRepository();
            var mockLog2      = new MockLog1 {
                LogName = "MockLog2"
            };

            logRepository.Logs.Add(mockLog2);

            Assert.AreEqual(2, logRepository.Logs.Count);
        }
コード例 #4
0
        public void Setup()
        {
            _mockLog = new MockLog1();

            _mockMigrateCommand = new Mock <DatabaseCommandBase <MigrateCommandArgs> >();
            _mockMigrateCommand.SetupProperty(x => x.Log);

            _rollbackCommand     = new RollbackCommand(_mockMigrateCommand.Object);
            _rollbackCommand.Log = _mockLog;

            CreateDatabase();
        }
コード例 #5
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();
        }
コード例 #6
0
        public void GetPath_should_log_warning_if_migrateFolder_appSetting_isnt_found()
        {
            //  arrange
            var logger = new MockLog1();

            //  act
            string path = _subject.GetPath(logger, new DotNetMigrations.Commands.GenerateScriptCommandArgs());

            using (DisposableDirectory.Watch(path))
            {
                //  assert
                Assert.IsTrue(logger.Output.StartsWith("WARNING"));
            }
        }
コード例 #7
0
        public void GetPath_should_log_warning_if_seedFolder_appSetting_isnt_found()
        {
            //  arrange
            var logger = new MockLog1();

            //  act
            string path = _subject.GetPath(logger);

            using (DisposableDirectory.Watch(path))
            {
                //  assert
                Assert.IsTrue(logger.Output.StartsWith("WARNING"));
            }
        }
コード例 #8
0
        public void Should_Be_Able_To_WriteError_Characters_To_All_Logs()
        {
            var logRepository = new LogRepository();
            var mockLog2      = new MockLog1 {
                LogName = "MockLog2"
            };

            logRepository.Logs.Add(mockLog2);

            logRepository.WriteError("Text1");

            // Get a reference to our mock log
            var mock = logRepository.GetLog("MockLog") as MockLog1;

            Assert.AreEqual("ERROR: Text1\r\n", mock.Output);
            Assert.AreEqual("ERROR: Text1\r\n", mockLog2.Output);
        }
コード例 #9
0
        public void Should_Dispose_Of_All_Logs()
        {
            var logRepository = new LogRepository();
            var mockLog2      = new MockLog1 {
                LogName = "MockLog2"
            };

            logRepository.Logs.Add(mockLog2);

            // Get a reference to our mock log
            var mock = logRepository.GetLog("MockLog") as MockLog1;

            logRepository.Dispose();

            Assert.AreEqual("Disposed!\r\n", mock.Output);
            Assert.AreEqual("Disposed!\r\n", mockLog2.Output);
        }
コード例 #10
0
        public void Run_should_log_file_name_of_new_migration_script()
        {
            //  arrange
            var mockMigrationDir = new Mock <IMigrationDirectory>();

            mockMigrationDir.Setup(dir => dir.CreateBlankScript("my_name")).Returns("C:\\1234_my_name.sql");

            var cmd     = new GenerateScriptCommand(mockMigrationDir.Object);
            var mockLog = new MockLog1();

            cmd.Log = mockLog;
            var cmdArgs = new GenerateScriptCommandArgs();

            cmdArgs.MigrationName = "my_name";

            //  act
            cmd.Run(cmdArgs);

            //  assert
            mockLog.Output.Contains(" 1234_my_name.sql ");
        }
コード例 #11
0
 public void Setup()
 {
     _logger     = new MockLog1();
     _helpWriter = new CommandHelpWriter(_logger);
 }