11using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Threading . Tasks ;
5+ using Apache . Arrow ;
6+ using InfluxDB3 . Client . Internal ;
7+ using InfluxDB3 . Client . Query ;
8+ using Moq ;
29
310namespace InfluxDB3 . Client . Test ;
411
@@ -37,4 +44,59 @@ public void NotSpecifiedDatabase()
3744 Assert . That ( ae , Is . Not . Null ) ;
3845 Assert . That ( ae . Message , Is . EqualTo ( "Please specify the 'database' as a method parameter or use default configuration at 'ClientConfig.Database'." ) ) ;
3946 }
47+
48+ [ Test ]
49+ public async Task PassNamedParametersToFlightClient ( )
50+ {
51+ //
52+ // Mock the FlightSqlClient
53+ //
54+ var mockFlightSqlClient = new Mock < IFlightSqlClient > ( ) ;
55+ mockFlightSqlClient
56+ . Setup ( m => m . Execute ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < QueryType > ( ) ,
57+ It . IsAny < Dictionary < string , object > > ( ) ) )
58+ . Returns ( new List < RecordBatch > ( ) . ToAsyncEnumerable ( ) ) ;
59+
60+ //
61+ // Setup the client with the mocked FlightSqlClient
62+ //
63+ _client = new InfluxDBClient ( MockServerUrl ) ;
64+ _client . FlightSqlClient . Dispose ( ) ;
65+ _client . FlightSqlClient = mockFlightSqlClient . Object ;
66+
67+ const string query = "select * from cpu where location = $location and core_count = $core-count and production = $production and max_frequency > $max-frequency" ;
68+ const QueryType queryType = QueryType . SQL ;
69+ var namedParameters = new Dictionary < string , object >
70+ {
71+ { "location" , "us" } ,
72+ { "core-count" , 4 } ,
73+ { "production" , true } ,
74+ { "max-frequency" , 3.5 }
75+ } ;
76+
77+ _ = await _client . QueryPoints ( query , database : "my-db" , queryType : queryType , namedParameters : namedParameters )
78+ . ToListAsync ( ) ;
79+ mockFlightSqlClient . Verify ( m => m . Execute ( query , "my-db" , queryType , namedParameters ) , Times . Exactly ( 1 ) ) ;
80+ }
81+
82+ [ Test ]
83+ public void NotSupportedQueryParameterType ( )
84+ {
85+ _client = new InfluxDBClient ( MockServerUrl ) ;
86+ var ae = Assert . ThrowsAsync < ArgumentException > ( async ( ) =>
87+ {
88+ _ = await _client
89+ . Query ( "select * from cpu where location = $location" , database : "my-db" ,
90+ queryType : QueryType . SQL , namedParameters : new Dictionary < string , object >
91+ {
92+ { "location" , DateTime . UtcNow }
93+ } )
94+ . ToListAsync ( ) ;
95+ } ) ;
96+
97+ Assert . That ( ae , Is . Not . Null ) ;
98+ Assert . That ( ae . Message ,
99+ Is . EqualTo (
100+ "The parameter 'location' has unsupported type 'System.DateTime'. The supported types are 'string', 'bool', 'int' and 'float'." ) ) ;
101+ }
40102}
0 commit comments