当前位置: 首页>>代码示例>>C#>>正文


C# Session.ExecuteScalar方法代码示例

本文整理汇总了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();
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:28,代码来源:SessionTests.cs

示例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")));
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:16,代码来源:SessionTests.cs

示例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);
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:14,代码来源:SessionTests.cs

示例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();
        }
开发者ID:natarajanmca11,项目名称:MicroLite,代码行数:28,代码来源:SessionTests.cs

示例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();
        }
开发者ID:rubenalves,项目名称:MicroLite,代码行数:26,代码来源:SessionTests.cs

示例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();
        }
开发者ID:rubenalves,项目名称:MicroLite,代码行数:26,代码来源:SessionTests.cs


注:本文中的Session.ExecuteScalar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。