예제 #1
0
        public void creates_a_new_journal_table_when_not_exist()
        {
            // Given
            var dbConnection      = Substitute.For <IDbConnection>();
            var connectionManager = new TestConnectionManager(dbConnection, true);
            var command           = Substitute.For <IDbCommand>();
            var param1            = Substitute.For <IDbDataParameter>();
            var param2            = Substitute.For <IDbDataParameter>();
            var param3            = Substitute.For <IDbDataParameter>();

            dbConnection.CreateCommand().Returns(command);
            command.CreateParameter().Returns(param1, param2, param3);
            command.ExecuteScalar().Returns(x => 0);
            var consoleUpgradeLog = new ConsoleUpgradeLog();
            var journal           = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, () => new Sha256Hasher(), "SchemaVersions");

            // When
            journal.StoreExecutedScript(new SqlScript("test", "select 1"), () => command);

            // Expect
            command.Received(3).CreateParameter();
            param1.ParameterName.ShouldBe("scriptName");
            param3.ParameterName.ShouldBe("hash");
            param2.ParameterName.ShouldBe("applied");
            command.Received().ExecuteNonQuery();
        }
예제 #2
0
        public void creates_a_new_journal_table_when_not_exist()
        {
            // Given
            var dbConnection      = Substitute.For <IDbConnection>();
            var connectionManager = new TestConnectionManager(dbConnection, true);
            var command           = Substitute.For <IDbCommand>();
            var param             = Substitute.For <IDbDataParameter>();

            dbConnection.CreateCommand().Returns(command);
            command.CreateParameter().Returns(param);
            command.ExecuteScalar().Returns(x => { throw new SQLiteException("table not found"); });
            var consoleUpgradeLog = new ConsoleUpgradeLog();
            var journal           = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions");

            // When
            journal.StoreExecutedScript(new SqlScript("test", "select 1"));

            // Expect
            command.Received().CreateParameter();
            Assert.AreEqual("scriptName", param.ParameterName);
            command.Received().ExecuteNonQuery();
        }