Beispiel #1
0
        public void ExecuteScriptTransactedSuccess()
        {
            IDbProvider    dbProvider   = A.Fake <IDbProvider>();
            IDbConnection  dbConnection = A.Fake <IDbConnection>();
            IDbTransaction dbTx         = A.Fake <IDbTransaction>();
            IDbCommand     dbCommand    = A.Fake <IDbCommand>();
            DefaultTransactionDefinition txDefinition = new DefaultTransactionDefinition();

            A.CallTo(() => dbProvider.CreateConnection()).Returns(dbConnection);
            A.CallTo(() => dbConnection.BeginTransaction(txDefinition.TransactionIsolationLevel)).Returns(dbTx);
            A.CallTo(() => dbProvider.CreateCommand()).Returns(dbCommand);
            A.CallTo(() => dbCommand.ExecuteNonQuery()).Returns(0);

            AdoTemplate          adoOps = new AdoTemplate(dbProvider);
            IPlatformTransaction tx     = SimpleAdoTestUtils.CreateTransaction(dbProvider, txDefinition);

            SimpleAdoTestUtils.ExecuteSqlScript(adoOps, "simple sql cmd");
            tx.Commit();
            tx.Dispose();

            A.CallTo(() => dbConnection.Open()).MustHaveHappenedOnceExactly();
            A.CallTo(() => dbTx.Commit()).MustHaveHappenedOnceExactly();
            A.CallTo(() => dbCommand.Dispose()).MustHaveHappenedOnceExactly();
            A.CallTo(() => dbConnection.Dispose()).MustHaveHappenedOnceExactly();

            A.CallToSet(() => dbCommand.Connection).WhenArgumentsMatch(x => x[0] == dbConnection).MustHaveHappenedOnceExactly();
            A.CallToSet(() => dbCommand.Transaction).WhenArgumentsMatch(x => x[0] == dbTx).MustHaveHappenedOnceExactly();
            A.CallToSet(() => dbCommand.CommandText).WhenArgumentsMatch(x => (string)x[0] == "simple sql cmd").MustHaveHappenedOnceExactly();
            A.CallToSet(() => dbCommand.CommandType).WhenArgumentsMatch(x => (CommandType)x[0] == CommandType.Text).MustHaveHappenedOnceExactly();
        }
        public void ExecuteScriptTransactedSuccess()
        {
            IDbProvider    dbProvider   = (IDbProvider)mocks.DynamicMock(typeof(IDbProvider));
            IDbConnection  dbConnection = (IDbConnection)mocks.CreateMock(typeof(IDbConnection));
            IDbTransaction dbTx         = (IDbTransaction)mocks.CreateMock(typeof(IDbTransaction));
            IDbCommand     dbCommand    = (IDbCommand)mocks.CreateMock(typeof(IDbCommand));
            DefaultTransactionDefinition txDefinition = new DefaultTransactionDefinition();

            Expect.Call(dbProvider.CreateConnection()).Return(dbConnection);
            dbConnection.Open();
            Expect.Call(dbConnection.BeginTransaction(txDefinition.TransactionIsolationLevel)).Return(dbTx);
            Expect.Call(dbProvider.CreateCommand()).Return(dbCommand);
            dbCommand.Connection  = dbConnection;
            dbCommand.Transaction = dbTx;
            dbCommand.CommandText = "simple sql cmd";
            dbCommand.CommandType = CommandType.Text;
            Expect.Call(dbCommand.ExecuteNonQuery()).Return(0);
            dbTx.Commit();
            dbCommand.Dispose();
            dbConnection.Dispose();
            mocks.ReplayAll();

            AdoTemplate          adoOps = new AdoTemplate(dbProvider);
            IPlatformTransaction tx     = SimpleAdoTestUtils.CreateTransaction(dbProvider, txDefinition);

            SimpleAdoTestUtils.ExecuteSqlScript(adoOps, "simple sql cmd");
            tx.Commit();
            tx.Dispose();
            mocks.VerifyAll();
        }
Beispiel #3
0
        public void ExecuteScriptTransactedRollsbackIfNoCommit()
        {
            IDbProvider    dbProvider   = A.Fake <IDbProvider>();
            IDbConnection  dbConnection = A.Fake <IDbConnection>();
            IDbTransaction dbTx         = A.Fake <IDbTransaction>();
            DefaultTransactionDefinition txDefinition = new DefaultTransactionDefinition();

            A.CallTo(() => dbProvider.CreateConnection()).Returns(dbConnection);
            A.CallTo(() => dbConnection.BeginTransaction(txDefinition.TransactionIsolationLevel)).Returns(dbTx);

            AdoTemplate          adoOps = new AdoTemplate(dbProvider);
            IPlatformTransaction tx     = SimpleAdoTestUtils.CreateTransaction(dbProvider, txDefinition);

            tx.Dispose();

            A.CallTo(() => dbConnection.Open()).MustHaveHappenedOnceExactly();
            A.CallTo(() => dbTx.Rollback()).MustHaveHappenedOnceExactly();
            A.CallTo(() => dbConnection.Dispose()).MustHaveHappenedOnceExactly();
        }
        public void ExecuteScriptTransactedRollsbackIfNoCommit()
        {
            IDbProvider    dbProvider   = (IDbProvider)mocks.CreateMock(typeof(IDbProvider));
            IDbConnection  dbConnection = (IDbConnection)mocks.CreateMock(typeof(IDbConnection));
            IDbTransaction dbTx         = (IDbTransaction)mocks.CreateMock(typeof(IDbTransaction));
            DefaultTransactionDefinition txDefinition = new DefaultTransactionDefinition();

            Expect.Call(dbProvider.CreateConnection()).Return(dbConnection);
            dbConnection.Open();
            Expect.Call(dbConnection.BeginTransaction(txDefinition.TransactionIsolationLevel)).Return(dbTx);
            dbTx.Rollback();
            dbConnection.Dispose();
            mocks.ReplayAll();

            AdoTemplate          adoOps = new AdoTemplate(dbProvider);
            IPlatformTransaction tx     = SimpleAdoTestUtils.CreateTransaction(dbProvider, txDefinition);

            tx.Dispose();
            mocks.VerifyAll();
        }