コード例 #1
0
        public void Should_be_able_prepare_a_query()
        {
            const string sql = "select @Id";

            var guid = Guid.NewGuid();
            var mc = new MappedColumn<Guid>("Id", DbType.Guid);
            var query = new RawQuery(sql).AddParameterValue(mc, guid);
            var dataParameterCollection = new Mock<IDataParameterCollection>();
            var dataParameterFactory = new Mock<IDbDataParameterFactory>();

            dataParameterFactory.Setup(m => m.Create("@Id", DbType.Guid, guid));

            var dataSource = new DataSource("data-source", dataParameterFactory.Object);

            var command = new Mock<IDbCommand>();

            dataParameterCollection.Setup(m => m.Add(It.IsAny<IDbDataParameter>())).Verifiable();

            command.SetupGet(m => m.Parameters).Returns(dataParameterCollection.Object);
            command.SetupSet(m => m.CommandText = sql).Verifiable();
            command.SetupSet(m => m.CommandType = CommandType.Text).Verifiable();

            query.Prepare(dataSource, command.Object);

            command.VerifyAll();
            dataParameterFactory.VerifyAll();
        }
コード例 #2
0
        public void Should_be_able_prepare_a_query()
        {
            const string sql = "select @Id";

            var guid  = Guid.NewGuid();
            var mc    = new MappedColumn <Guid>("Id", DbType.Guid);
            var query = new RawQuery(sql).AddParameterValue(mc, guid);
            var dataParameterCollection = new Mock <IDataParameterCollection>();

            var command = new Mock <IDbCommand>();

            dataParameterCollection.Setup(m => m.Add(It.IsAny <IDbDataParameter>())).Verifiable();

            command.SetupGet(m => m.Parameters).Returns(dataParameterCollection.Object);
            command.SetupSet(m => m.CommandText = sql).Verifiable();
            command.SetupSet(m => m.CommandType = CommandType.Text).Verifiable();
            command.Setup(m => m.CreateParameter()).Returns(new SqlParameter());

            query.Prepare(command.Object);

            command.VerifyAll();
        }