Exemplo n.º 1
0
        public void BindParameter_BindAndRebindParameterFact()
        {
            var builder = new SqlExpressionBuilderSelect();

            builder.From("table", "t");
            builder.Where("t.foo = @foo");

            var param = new SqlParameter("@foo", SqlDbType.Int)
            {
                Value = 5
            };

            builder.BindParameter(param);
            Assert.Equal(1, builder.Parameters.Count());
            Assert.Equal(param, builder.Parameters.First());

            // Rebind by new param
            var newParam = new SqlParameter("@foo", SqlDbType.Int)
            {
                Value = 6
            };

            builder.BindParameter(newParam);
            Assert.Equal(1, builder.Parameters.Count());
            Assert.Equal(newParam, builder.Parameters.First());

            // Rebind by overwrite
            builder.BindParameter("@foo", 7);
            Assert.Equal(1, builder.Parameters.Count());
            Assert.Equal(newParam, builder.Parameters.First());
            Assert.Equal(7, builder.Parameters.First().Value);
        }
Exemplo n.º 2
0
        public void BindParameter_ThrowsOnParameterNotFoundFact()
        {
            var builder = new SqlExpressionBuilderSelect();

            builder.From("table", "t");

            Assert.Throws <InvalidOperationException>(() => builder.BindParameter("@foo", DbType.Int32, 12));

            Assert.Throws <InvalidOperationException>(() => builder.BindParameter("@foo", 12));
        }
Exemplo n.º 3
0
        public void BindParameter_DoesNotThrowOnSupressedWarningFact()
        {
            var builder = new SqlExpressionBuilderSelect();

            builder.From("table", "t");

            Assert.DoesNotThrow(() => builder.BindParameter("@foo", DbType.Int32, 12, true));
        }
Exemplo n.º 4
0
        public void BindParameter_DoesNotThrowOnParameterFoundFact()
        {
            var builder = new SqlExpressionBuilderSelect();

            builder.From("table", "t");

            builder.Where("t.foo = @foo");

            Assert.DoesNotThrow(() => builder.BindParameter("@foo", DbType.Int32, 12));
        }