public void Statement2_SqlNull_RConverter() { using (var conn = new Connection()) { var r = ResultConverter.Builder <int>().Compile(); Assert.Throws <ArgumentNullException>( () => conn.CompileStatement <int, int>(null !, r)); } }
public void ConverterTypes() { ParameterConverter.Builder <User>() // customize parameter mappings .Compile(); ResultConverter.Builder <User>() // customize result mappings .Compile(); }
public void Statement2_PConverterNull_BothConverters() { using (var conn = new Connection()) { ParameterConverter <int> p = null !; var r = ResultConverter.Builder <int>().Compile(); Assert.Throws <ArgumentNullException>( () => conn.CompileStatement("", r, p)); } }
public void To_Fails() { R <int> r = default; var conv = ResultConverter.Builder <R <int> >() .With(re => re.Value, (long v) => throw new Exception("throw")) .Compile(); using (var tbl = new TestTable("create table t (x int)")) using (var insert = tbl.Stmt("insert into t values(1)")) using (var select = tbl.Stmt("select x from t", conv)) { insert.Execute(); Assert.Throws <AssignmentException>(() => select.Execute(out r)); } }
public void Custom_FromNull() { var rc = ResultConverter.Builder <R <int?> >() .With(r => r.Value, () => 5) .Compile(); using (var connection = new Connection()) using (var stmt = connection.CompileStatement <R <int?>, int?>("select @x", rc)) { Assert.True( stmt .Bind(null) .Execute(out R <int?> r)); Assert.Equal(expected: 5, r.Value); } }
public void Result_Ignore() { R <string, int> r = default; var conv = ResultConverter.Builder <R <string, int> >() .Ignore(re => re.Value1) .Compile(); using (var tbl = new TestTable("create table t (x int)")) using (var insert = tbl.Stmt("insert into t values (1)")) using (var select = tbl.Stmt("select x from t", conv)) { insert.Execute(); Assert.True(select.Execute(out r)); Assert.Equal(1, r.Value2); } }
public void Custom_FromInt() { P <int> p = default; R <int> r = default; var conv = ResultConverter.Builder <R <int> >() .With(re => re.Value, (long v) => - 1 * (int)v).Compile(); using (var tbl = new TestTable("create table t (x int)")) using (var insert = tbl.Stmt("insert into t values (@x)", p.C)) using (var select = tbl.Stmt("select x from t", conv)) { p.Value = 5; insert.Bind(p).Execute(); Assert.True(select.Execute(out r)); Assert.Equal(-1 * p.Value, r.Value); } }