Esempio n. 1
0
        public void ao_lancar_excecao_quando_executar_script_deve_gravar_status_de_erro_na_changelog()
        {
            var dbmsSyntax2  = new Mock <IDbmsSyntax>();
            var changeScript = new Mock <ChangeScript>("Scripts", 1, new FileInfo("script.sql"), Encoding.UTF8);

            dbmsSyntax2.Setup(x => x.CreateChangeLogTableSqlScript(It.IsAny <string>())).Returns("ScriptCreateChangeLog");
            splitter.Setup(s => s.Split(It.IsAny <string>())).Returns <string>(s => new[] { s });
            changeScript.Setup(x => x.GetContent()).Returns("conteudo do script");
            queryExecuter.Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <StringBuilder>())).Throws(new DummyDbException());

            var directToDbApplier = new DirectToDbApplier(queryExecuter.Object, schemaVersionManager.Object, splitter.Object, dbmsSyntax2.Object, ChangeLogTableName, System.Console.Out);

            directToDbApplier.Invoking(x => x.ApplyChangeScript(changeScript.Object, false)).ShouldThrow <Exception>();

            schemaVersionManager.Verify(s => s.RecordScriptStatus(changeScript.Object, ScriptStatus.Started, It.IsAny <string>()), Times.Once);
            queryExecuter.Verify(x => x.BeginTransaction(), Times.Once);
            queryExecuter.Verify(x => x.Execute(It.IsAny <string>(), It.IsAny <StringBuilder>()), Times.Once);
            schemaVersionManager.Verify(s => s.RecordScriptStatus(changeScript.Object, ScriptStatus.Failure, It.IsAny <string>()), Times.Once);
            queryExecuter.Verify(x => x.CommitTransaction(), Times.Once);
        }
        public void ao_lancar_excecao_quando_executar_script_deve_gravar_status_de_erro_na_changelog()
        {
            var dbmsSyntax2 = new Mock<IDbmsSyntax>();
            var changeScript = new Mock<ChangeScript>("Scripts", 1, new FileInfo("script.sql"), Encoding.UTF8);
            dbmsSyntax2.Setup(x => x.CreateChangeLogTableSqlScript(It.IsAny<string>())).Returns("ScriptCreateChangeLog");
            splitter.Setup(s => s.Split(It.IsAny<string>())).Returns<string>(s => new[] { s });
            changeScript.Setup(x => x.GetContent()).Returns("conteudo do script");
            queryExecuter.Setup(x => x.Execute(It.IsAny<string>(), It.IsAny<StringBuilder>())).Throws(new DummyDbException());

            var directToDbApplier = new DirectToDbApplier(queryExecuter.Object, schemaVersionManager.Object, splitter.Object, dbmsSyntax2.Object, ChangeLogTableName, System.Console.Out);
            directToDbApplier.Invoking(x => x.ApplyChangeScript(changeScript.Object, false)).ShouldThrow<Exception>();

            schemaVersionManager.Verify(s => s.RecordScriptStatus(changeScript.Object, ScriptStatus.Started, It.IsAny<string>()), Times.Once);
            queryExecuter.Verify(x => x.BeginTransaction(), Times.Once);
            queryExecuter.Verify(x => x.Execute(It.IsAny<string>(), It.IsAny<StringBuilder>()), Times.Once);
            schemaVersionManager.Verify(s => s.RecordScriptStatus(changeScript.Object, ScriptStatus.Failure, It.IsAny<string>()), Times.Once);
            queryExecuter.Verify(x => x.CommitTransaction(), Times.Once);
        }