Exemple #1
0
 public void Statement2_SqlNull_PConverter()
 {
     using (var conn = new Connection())
     {
         var p = ParameterConverter.Builder <int>().Compile();
         Assert.Throws <ArgumentNullException>(
             () => conn.CompileStatement <int, int>(null !, p));
     }
 }
Exemple #2
0
        public void ConverterTypes()
        {
            ParameterConverter.Builder <User>()
            // customize parameter mappings
            .Compile();

            ResultConverter.Builder <User>()
            // customize result mappings
            .Compile();
        }
Exemple #3
0
 public void Statement2_RConverterNull_BothConverters()
 {
     using (var conn = new Connection())
     {
         var p = ParameterConverter.Builder <int>().Compile();
         ResultConverter <int> r = null !;
         Assert.Throws <ArgumentNullException>(
             () => conn.CompileStatement("", r, p));
     }
 }
Exemple #4
0
        public void From_Fails()
        {
            P <int> p    = default;
            var     conv = ParameterConverter.Builder <P <int> >()
                           .With(pa => pa.Value, v => ThrowConvertTo <long>())
                           .Ignore(pa => pa.C)
                           .Compile();

            using (var tbl = new TestTable("create table t (x int)"))
                using (var insert = tbl.Stmt("insert into t values (@x)", conv))
                {
                    Assert.Throws <BindingException>(() => insert.Bind(p));
                }
        }
Exemple #5
0
        public void Custom_ToInt()
        {
            P <int> p    = default;
            var     conv = ParameterConverter.Builder <P <int> >()
                           .With(pa => pa.Value, v => - 1 * v)
                           .Ignore(pa => pa.C).Compile();
            R <int> r = default;

            using (var tbl = new TestTable("create table t (x int)"))
                using (var insert = tbl.Stmt("insert into t values (@x)", conv))
                    using (var select = tbl.Stmt("select x from t", r.C))
                    {
                        p.Value = 5;
                        insert.Bind(p).Execute();
                        Assert.True(select.Execute(out r));
                        Assert.Equal(-1 * p.Value, r.Value);
                    }
        }
Exemple #6
0
        public void Custom_ToNull()
        {
            var pc = ParameterConverter.Builder <P <int> >()
                     .With(p => p.Value)
                     .Ignore(p => p.C)
                     .Compile();

            using (var connection = new Connection())
                using (var stmt = connection.CompileStatement <int?, P <int> >("select @x", pc))
                {
                    Assert.True(
                        stmt
                        .Bind(new P <int> {
                        Value = 5
                    })
                        .Execute(out int?r));
                    Assert.Null(r);
                }
        }