本文整理汇总了C#中SqlServer.RollbackTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# SqlServer.RollbackTransaction方法的具体用法?C# SqlServer.RollbackTransaction怎么用?C# SqlServer.RollbackTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlServer
的用法示例。
在下文中一共展示了SqlServer.RollbackTransaction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SqlServer_FetchStoredProcedures_RollbackTransaction
// ReSharper disable InconsistentNaming
public void SqlServer_FetchStoredProcedures_RollbackTransaction()
// ReSharper restore InconsistentNaming
{
//------------Setup for test--------------------------
var factory = new Mock<IDbFactory>();
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(a => a.CommandText).Returns("Dave.Bob");
var conn = new Mock<IDbConnection>();
conn.Setup(a => a.State).Returns(ConnectionState.Open);
var dbTran = new Mock<IDbTransaction>();
conn.Setup(a => a.BeginTransaction()).Returns(dbTran.Object);
factory.Setup(a => a.CreateConnection(It.IsAny<string>())).Returns(conn.Object);
var sqlServer = new SqlServer(factory.Object);
try
{
PrivateObject pvt = new PrivateObject(sqlServer);
pvt.SetField("_connection", conn.Object);
sqlServer.Connect("a");
sqlServer.BeginTransaction();
sqlServer.RollbackTransaction();
factory.Verify(a => a.CreateConnection(It.IsAny<string>()));
conn.Verify(a => a.Open());
dbTran.Verify(a => a.Rollback());
dbTran.Verify(a => a.Dispose());
conn.Verify(a => a.BeginTransaction());
//------------Assert Results-------------------------
}
finally
{
sqlServer.Dispose();
}
}
示例2: SqlServer_CreateCommand_TranactionStarted_CommandTransactionIsNotNull
public void SqlServer_CreateCommand_TranactionStarted_CommandTransactionIsNotNull()
{
//------------Setup for test--------------------------
var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();
var sqlServer = new SqlServer();
try
{
sqlServer.Connect(dbSource.ConnectionString);
sqlServer.BeginTransaction();
//------------Execute Test---------------------------
var command = sqlServer.CreateCommand();
//------------Assert Results-------------------------
Assert.IsNotNull(command);
Assert.IsNotNull(command.Transaction);
}
finally
{
sqlServer.RollbackTransaction();
sqlServer.Dispose();
}
}