Наследование: LoggerBase
        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);
        }
        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"));
            }
        }
        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);
        }
        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);
        }
        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();
        }
 public void Setup()
 {
     _logger = new MockLog1();
     _helpWriter = new CommandHelpWriter(_logger);
 }
 private static string GetArgumentSyntax(ICommand command)
 {
     using (var logger = new MockLog1())
     {
         var writer = new CommandHelpWriter(logger);
         writer.WriteArgumentSyntax(command.GetArgumentsType());
         return logger.Output;
     }
 }
        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();
        }