@@ -26,7 +26,7 @@ public sealed class MicrosoftSqlClientParameterTests : ParameterTests<MicrosoftS
26
26
#endif
27
27
public abstract class ParameterTests < TProvider > : TestBase < TProvider > where TProvider : DatabaseProvider
28
28
{
29
- public class DbParams : SqlMapper . IDynamicParameters , IEnumerable < IDbDataParameter >
29
+ public class DbDynamicParams : SqlMapper . IDynamicParameters , IEnumerable < IDbDataParameter >
30
30
{
31
31
private readonly List < IDbDataParameter > parameters = new List < IDbDataParameter > ( ) ;
32
32
public IEnumerator < IDbDataParameter > GetEnumerator ( ) { return parameters . GetEnumerator ( ) ; }
@@ -42,6 +42,21 @@ void SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, SqlMapper.Id
42
42
command . Parameters . Add ( parameter ) ;
43
43
}
44
44
}
45
+
46
+ public class DbCustomParam : SqlMapper . ICustomQueryParameter
47
+ {
48
+ private readonly IDbDataParameter _sqlParameter ;
49
+
50
+ public DbCustomParam ( IDbDataParameter sqlParameter )
51
+ {
52
+ _sqlParameter = sqlParameter ;
53
+ }
54
+
55
+ public void AddParameter ( IDbCommand command , string name )
56
+ {
57
+ command . Parameters . Add ( _sqlParameter ) ;
58
+ }
59
+ }
45
60
46
61
private static IEnumerable < IDataRecord > CreateSqlDataRecordList ( IDbCommand command , IEnumerable < int > numbers )
47
62
{
@@ -799,9 +814,9 @@ public class HazSqlHierarchy
799
814
#endif
800
815
801
816
[ Fact ]
802
- public void TestCustomParameters ( )
817
+ public void TestDynamicParameters ( )
803
818
{
804
- var args = new DbParams {
819
+ var args = new DbDynamicParams {
805
820
Provider . CreateRawParameter ( "foo" , 123 ) ,
806
821
Provider . CreateRawParameter ( "bar" , "abc" )
807
822
} ;
@@ -811,7 +826,53 @@ public void TestCustomParameters()
811
826
Assert . Equal ( 123 , foo ) ;
812
827
Assert . Equal ( "abc" , bar ) ;
813
828
}
829
+
830
+ [ Fact ]
831
+ public void TestDynamicParametersReuse ( )
832
+ {
833
+ var args = new DbDynamicParams {
834
+ Provider . CreateRawParameter ( "foo" , 123 ) ,
835
+ Provider . CreateRawParameter ( "bar" , "abc" )
836
+ } ;
837
+ var result1 = connection . Query ( "select Foo=@foo, Bar=@bar" , args ) . Single ( ) ;
838
+ var result2 = connection . Query ( "select Foo=@foo, Bar=@bar" , args ) . Single ( ) ;
839
+ Assert . Equal ( 123 , result1 . Foo ) ;
840
+ Assert . Equal ( "abc" , result1 . Bar ) ;
841
+ Assert . Equal ( 123 , result2 . Foo ) ;
842
+ Assert . Equal ( "abc" , result2 . Bar ) ;
843
+ }
814
844
845
+
846
+ [ Fact ]
847
+ public void TestCustomParameter ( )
848
+ {
849
+ var args = new {
850
+ foo = new DbCustomParam ( Provider . CreateRawParameter ( "foo" , 123 ) ) ,
851
+ bar = "abc"
852
+ } ;
853
+ var result = connection . Query ( "select Foo=@foo, Bar=@bar" , args ) . Single ( ) ;
854
+ int foo = result . Foo ;
855
+ string bar = result . Bar ;
856
+ Assert . Equal ( 123 , foo ) ;
857
+ Assert . Equal ( "abc" , bar ) ;
858
+ }
859
+
860
+ [ Fact ]
861
+ public void TestCustomParameterReuse ( )
862
+ {
863
+ var args = new {
864
+ foo = new DbCustomParam ( Provider . CreateRawParameter ( "foo" , 123 ) ) ,
865
+ bar = "abc"
866
+ } ;
867
+ var result1 = connection . Query ( "select Foo=@foo, Bar=@bar" , args ) . Single ( ) ;
868
+ var result2 = connection . Query ( "select Foo=@foo, Bar=@bar" , args ) . Single ( ) ;
869
+ Assert . Equal ( 123 , result1 . Foo ) ;
870
+ Assert . Equal ( "abc" , result1 . Bar ) ;
871
+ Assert . Equal ( 123 , result2 . Foo ) ;
872
+ Assert . Equal ( "abc" , result2 . Bar ) ;
873
+ }
874
+
875
+
815
876
[ Fact ]
816
877
public void TestDynamicParamNullSupport ( )
817
878
{
0 commit comments