本文整理汇总了C#中Session.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# Session.ExecuteScalar方法的具体用法?C# Session.ExecuteScalar怎么用?C# Session.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session.ExecuteScalar方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteScalarUsesTypeConvertersToResolveResultType
public void ExecuteScalarUsesTypeConvertersToResolveResultType()
{
var result = (byte)1;
var mockSqlDialect = new Mock<ISqlDialect>();
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteScalar()).Returns(result);
var mockConnection = new Mock<IDbConnection>();
mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object);
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.CreateConnection()).Returns(mockConnection.Object);
var session = new Session(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new IDeleteListener[0],
new IInsertListener[0],
new IUpdateListener[0]);
Assert.Equal((CustomerStatus)result, session.ExecuteScalar<CustomerStatus>(new SqlQuery("")));
mockDbDriver.VerifyAll();
mockCommand.VerifyAll();
}
示例2: ExecuteScalarThrowsObjectDisposedExceptionIfDisposed
public void ExecuteScalarThrowsObjectDisposedExceptionIfDisposed()
{
var session = new Session(
ConnectionScope.PerTransaction,
new Mock<ISqlDialect>().Object,
new Mock<IDbDriver>().Object,
new IDeleteListener[0],
new IInsertListener[0],
new IUpdateListener[0]);
using (session)
{
}
Assert.Throws<ObjectDisposedException>(() => session.ExecuteScalar<int>(new SqlQuery("SELECT")));
}
示例3: ExecuteScalarThrowsArgumentNullExceptionForNullSqlQuery
public void ExecuteScalarThrowsArgumentNullExceptionForNullSqlQuery()
{
var session = new Session(
ConnectionScope.PerTransaction,
new Mock<ISqlDialect>().Object,
new Mock<IDbDriver>().Object,
new IDeleteListener[0],
new IInsertListener[0],
new IUpdateListener[0]);
var exception = Assert.Throws<ArgumentNullException>(() => session.ExecuteScalar<object>(null));
Assert.Equal("sqlQuery", exception.ParamName);
}
示例4: ExecuteScalarBuildsAndExecutesCommand
public void ExecuteScalarBuildsAndExecutesCommand()
{
var result = new object();
var mockSqlDialect = new Mock<ISqlDialect>();
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteScalar()).Returns(result);
var mockConnection = new Mock<IDbConnection>();
mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object);
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.CreateConnection()).Returns(mockConnection.Object);
var session = new Session(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new IDeleteListener[0],
new IInsertListener[0],
new IUpdateListener[0]);
Assert.Equal(result, session.ExecuteScalar<object>(new SqlQuery("")));
mockDbDriver.VerifyAll();
mockCommand.VerifyAll();
}
示例5: ExecuteScalarUsesTypeConvertersToResolveResultType
public void ExecuteScalarUsesTypeConvertersToResolveResultType()
{
var sqlQuery = new SqlQuery("");
var result = (byte)1;
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteScalar()).Returns(result);
mockCommand.As<IDisposable>().Setup(x => x.Dispose());
var mockSqlDialect = new Mock<ISqlDialect>();
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.GetConnection(ConnectionScope.PerTransaction)).Returns(new Mock<IDbConnection>().Object);
mockDbDriver.Setup(x => x.BuildCommand(It.IsNotNull<SqlQuery>())).Returns(mockCommand.Object);
var session = new Session(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new IListener[0]);
Assert.Equal((CustomerStatus)result, session.ExecuteScalar<CustomerStatus>(sqlQuery));
mockDbDriver.VerifyAll();
mockCommand.VerifyAll();
}
示例6: ExecuteScalarBuildsAndExecutesCommand
public void ExecuteScalarBuildsAndExecutesCommand()
{
var sqlQuery = new SqlQuery("");
var result = new object();
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(x => x.ExecuteScalar()).Returns(result);
mockCommand.As<IDisposable>().Setup(x => x.Dispose());
var mockSqlDialect = new Mock<ISqlDialect>();
var mockDbDriver = new Mock<IDbDriver>();
mockDbDriver.Setup(x => x.GetConnection(ConnectionScope.PerTransaction)).Returns(new Mock<IDbConnection>().Object);
mockDbDriver.Setup(x => x.BuildCommand(It.IsNotNull<SqlQuery>())).Returns(mockCommand.Object);
var session = new Session(
ConnectionScope.PerTransaction,
mockSqlDialect.Object,
mockDbDriver.Object,
new IListener[0]);
Assert.Equal(result, session.ExecuteScalar<object>(sqlQuery));
mockDbDriver.VerifyAll();
mockCommand.VerifyAll();
}