Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        private SQLiteTableJournal GetJournal()
        {
            var sqLiteConnectionManager = new SQLiteConnectionManager(database.SharedConnection);

            sqLiteConnectionManager.OperationStarting(log, new List <SqlScript>());
            var journal = new SQLiteTableJournal(() => sqLiteConnectionManager, () => log, "SchemaVersions");

            return(journal);
        }
Ejemplo n.º 3
0
        private SQLiteTableJournal GetJournal()
        {
            var sqLiteConnectionManager = new SQLiteConnectionManager(database.ConnectionString);

            sqLiteConnectionManager.UpgradeStarting(log);
            var journal = new SQLiteTableJournal(() => sqLiteConnectionManager, () => log, "SchemaVersions");

            return(journal);
        }
        public void dbversion_is_zero_when_journal_table_not_exist()
        {
            // Given
            var dbConnection = Substitute.For <IDbConnection>();
            var command      = Substitute.For <IDbCommand>();

            dbConnection.CreateCommand().Returns(command);
            var connectionManager = Substitute.For <IConnectionManager>();

            command.ExecuteScalar().Returns(x => { throw new SqliteException("table not found", 400); });
            var consoleUpgradeLog = new ConsoleUpgradeLog();
            var journal           = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions");

            // When
            var scripts = journal.GetExecutedScripts();

            // Expect
            command.DidNotReceive().ExecuteReader();
            scripts.ShouldBeEmpty();
        }
Ejemplo n.º 5
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();
        }