11using System ;
22using Microsoft . VisualStudio . TestTools . UnitTesting ;
3+ using System . Dynamic ;
34
45using AdysTech . InfluxDB . Client . Net ;
56using System . Threading . Tasks ;
67using System . Collections . Generic ;
8+ using System . Diagnostics ;
79
810namespace InfluxDB . Client . Test
911{
@@ -52,7 +54,7 @@ public async Task TestGetInfluxDBNamesAsync()
5254 {
5355 try
5456 {
55-
57+
5658 var client = new InfluxDBClient ( influxUrl , dbUName , dbpwd ) ;
5759 var r = await client . GetInfluxDBNamesAsync ( ) ;
5860 Assert . IsTrue ( r != null && r . Count > 0 , "GetInfluxDBNamesAsync retunred null or empty collection" ) ;
@@ -65,13 +67,12 @@ public async Task TestGetInfluxDBNamesAsync()
6567 }
6668 }
6769
68-
6970 [ TestMethod ]
70- public async Task TestGetInfluxDBStructureAsync_InvalidDB ( )
71+ public async Task TestGetInfluxDBStructureAsync ( )
7172 {
7273 try
7374 {
74-
75+
7576 var client = new InfluxDBClient ( influxUrl , dbUName , dbpwd ) ;
7677 var r = await client . GetInfluxDBStructureAsync ( "InvalidDB" ) ;
7778 Assert . IsTrue ( r != null && r . Count == 0 , "GetInfluxDBNamesAsync retunred null or non empty collection" ) ;
@@ -84,6 +85,24 @@ public async Task TestGetInfluxDBStructureAsync_InvalidDB()
8485 }
8586 }
8687
88+ [ TestMethod ]
89+ public async Task TestGetInfluxDBStructureAsync_InvalidDB ( )
90+ {
91+ try
92+ {
93+
94+ var client = new InfluxDBClient ( influxUrl , dbUName , dbpwd ) ;
95+ var r = await client . GetInfluxDBStructureAsync ( dbName ) ;
96+ Assert . IsTrue ( r != null && r . Count >= 0 , "GetInfluxDBNamesAsync retunred null or non empty collection" ) ;
97+ }
98+ catch ( Exception e )
99+ {
100+ Assert . Fail ( "Unexpected exception of type {0} caught: {1}" ,
101+ e . GetType ( ) , e . Message ) ;
102+ return ;
103+ }
104+ }
105+
87106 [ TestMethod ]
88107 [ ExpectedException ( typeof ( ArgumentException ) ) ]
89108 public async Task TestCreateDatabaseAsync_InvalidName ( )
@@ -97,7 +116,7 @@ public async Task TestCreateDatabaseAsync()
97116 {
98117 try
99118 {
100-
119+
101120 var client = new InfluxDBClient ( influxUrl , dbUName , dbpwd ) ;
102121 var r = await client . CreateDatabaseAsync ( dbName ) ;
103122 Assert . IsTrue ( r , "CreateDatabaseAsync retunred false" ) ;
@@ -121,7 +140,7 @@ public async Task TestPostValueAsync()
121140 try
122141 {
123142 var client = new InfluxDBClient ( influxUrl , dbUName , dbpwd ) ;
124- var r = await client . PostValueAsync ( dbName , measurementName , DateTime . UtcNow . ToEpoch ( TimePrecision . Seconds ) , TimePrecision . Seconds , "testTag=testTagValue" , "Temp" , 33.05 ) ;
143+ var r = await client . PostValueAsync ( dbName , measurementName , DateTime . UtcNow . ToEpoch ( TimePrecision . Seconds ) , TimePrecision . Seconds , "testTag=testTagValue" , "Temp" , new Random ( ) . NextDouble ( ) ) ;
125144 Assert . IsTrue ( r , "PostValueAsync retunred false" ) ;
126145 }
127146 catch ( Exception e )
@@ -141,7 +160,7 @@ public async Task TestPostValuesAsync()
141160 var client = new InfluxDBClient ( influxUrl , dbUName , dbpwd ) ;
142161 var val = new Random ( ) ;
143162 var values = new Dictionary < string , double > ( ) { { "filed1" , val . NextDouble ( ) * 10 } , { "filed2" , val . NextDouble ( ) * 10 } , { "filed3" , val . NextDouble ( ) * 10 } } ;
144- var r = await client . PostValuesAsync ( dbName , measurementName , DateTime . UtcNow . ToEpoch ( TimePrecision . Seconds ) , TimePrecision . Seconds , "testTag=testTagValue" , values ) ;
163+ var r = await client . PostValuesAsync ( dbName , measurementName , DateTime . UtcNow . ToEpoch ( TimePrecision . Seconds ) , TimePrecision . Seconds , "testTag=testTagValue" , values ) ;
145164 Assert . IsTrue ( r , "PostValuesAsync retunred false" ) ;
146165 }
147166 catch ( Exception e )
@@ -152,5 +171,32 @@ public async Task TestPostValuesAsync()
152171 return ;
153172 }
154173 }
174+
175+ [ TestMethod ]
176+ public async Task TestQueryAsync ( )
177+ {
178+ try
179+ {
180+
181+ var client = new InfluxDBClient ( influxUrl , dbUName , dbpwd ) ;
182+ var r = await client . QueryDBAsync ( "stress" , "select * from performance limit 10" ) ;
183+ DateTime d ;
184+ Assert . IsTrue ( r != null && DateTime . TryParse ( r [ 0 ] . time , out d ) , "QueryDBAsync retunred null or invalid data" ) ;
185+ }
186+ catch ( Exception e )
187+ {
188+ Assert . Fail ( "Unexpected exception of type {0} caught: {1}" ,
189+ e . GetType ( ) , e . Message ) ;
190+ return ;
191+ }
192+ }
193+
194+ [ TestMethod ]
195+ [ ExpectedException ( typeof ( ArgumentException ) ) ]
196+ public async Task TestQueryAsync_MultiSeries ( )
197+ {
198+ var client = new InfluxDBClient ( influxUrl , dbUName , dbpwd ) ;
199+ var r = await client . QueryDBAsync ( "_internal" , "Show Series" ) ;
200+ }
155201 }
156202}
0 commit comments