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(); }
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 ExecuteSingleStatement() { IResource scriptResource = new StringResource("statement 1"); SimpleAdoTestUtils.ExecuteSqlScript(adoTemplate, scriptResource, false, SimpleAdoTestUtils.BLOCKDELIM_GO_EXP); A.CallTo(() => adoTemplate.ExecuteNonQuery(CommandType.Text, "statement 1")).MustHaveHappened(); }
public void ExecuteEmptyScript() { IResource scriptResource = new StringResource(""); mocks.ReplayAll(); SimpleAdoTestUtils.ExecuteSqlScript(adoTemplate, scriptResource, false, SimpleAdoTestUtils.BLOCKDELIM_GO_EXP); mocks.VerifyAll(); }
public void ExecuteScriptWithSemicolonSeparatedStatements() { IResource scriptResource = new StringResource("\tstatement 1 ;\nGO\n statement 2;"); A.CallTo(() => adoTemplate.ExecuteNonQuery(CommandType.Text, "\tstatement 1 ")).Returns(0); A.CallTo(() => adoTemplate.ExecuteNonQuery(CommandType.Text, "\nGO\n statement 2")).Returns(0); SimpleAdoTestUtils.ExecuteSqlScript(adoTemplate, scriptResource, false, SimpleAdoTestUtils.BLOCKDELIM_SEMICOLON_EXP); }
public void ExecuteScriptWithGOBlocks() { IResource scriptResource = new StringResource("\tstatement 1 \n\n\t GO\t \n statement 2\nGO"); A.CallTo(() => adoTemplate.ExecuteNonQuery(CommandType.Text, "\tstatement 1 \n")).Returns(0); A.CallTo(() => adoTemplate.ExecuteNonQuery(CommandType.Text, "\n statement 2\n")).Returns(0); SimpleAdoTestUtils.ExecuteSqlScript(adoTemplate, scriptResource, false, SimpleAdoTestUtils.BLOCKDELIM_GO_EXP); }
public void ExecuteScriptWithMissingSeparatorOnLastBlock() { IResource scriptResource = new StringResource("\tstatement 1 \n\n\t GO\t \n statement 2"); SimpleAdoTestUtils.ExecuteSqlScript(adoTemplate, scriptResource, false, SimpleAdoTestUtils.BLOCKDELIM_GO_EXP); A.CallTo(() => adoTemplate.ExecuteNonQuery(CommandType.Text, "\tstatement 1 \n")).MustHaveHappened(); A.CallTo(() => adoTemplate.ExecuteNonQuery(CommandType.Text, "\n statement 2")).MustHaveHappened(); }
public void ExecuteSingleStatement() { IResource scriptResource = new StringResource("statement 1"); Expect.Call(adoTemplate.ExecuteNonQuery(CommandType.Text, "statement 1")).Return(0); mocks.ReplayAll(); SimpleAdoTestUtils.ExecuteSqlScript(adoTemplate, scriptResource, false, SimpleAdoTestUtils.BLOCKDELIM_GO_EXP); mocks.VerifyAll(); }
public void ExecuteScriptWithMissingSeparatorOnLastBlock() { IResource scriptResource = new StringResource("\tstatement 1 \n\n\t GO\t \n statement 2"); Expect.Call(adoTemplate.ExecuteNonQuery(CommandType.Text, "\tstatement 1 \n")).Return(0); Expect.Call(adoTemplate.ExecuteNonQuery(CommandType.Text, "\n statement 2")).Return(0); mocks.ReplayAll(); SimpleAdoTestUtils.ExecuteSqlScript(adoTemplate, scriptResource, false, SimpleAdoTestUtils.BLOCKDELIM_GO_EXP); mocks.VerifyAll(); }