Skip to content

Commit 4872780

Browse files
committed
Added more tests
1 parent c6d91de commit 4872780

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

AdysTech.InfluxDB.Client.Net.Test/InfluxDBClientTest.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace InfluxDB.Client.Test
1010
public class InfluxDBClientTest
1111
{
1212
const string dbName = "testDB";
13+
const string measurementName = "TestMeasurement";
1314
const string invalidDbName = "test DB";
1415
const string dbUName = "admin";
1516
const string dbpwd = "admin";
@@ -50,7 +51,7 @@ public async Task TestGetInfluxDBNamesAsync()
5051
{
5152
try
5253
{
53-
//pass 8089, which is not influx port
54+
5455
var client = new InfluxDBClient (influxUrl, dbUName, dbpwd);
5556
var r = await client.GetInfluxDBNamesAsync ();
5657
Assert.IsTrue (r != null && r.Count > 0, "GetInfluxDBNamesAsync retunred null or empty collection");
@@ -69,7 +70,7 @@ public async Task TestGetInfluxDBStructureAsync_InvalidDB()
6970
{
7071
try
7172
{
72-
//pass 8089, which is not influx port
73+
7374
var client = new InfluxDBClient (influxUrl, dbUName, dbpwd);
7475
var r = await client.GetInfluxDBStructureAsync ("InvalidDB");
7576
Assert.IsTrue (r != null && r.Count == 0, "GetInfluxDBNamesAsync retunred null or non empty collection");
@@ -82,12 +83,20 @@ public async Task TestGetInfluxDBStructureAsync_InvalidDB()
8283
}
8384
}
8485

86+
[TestMethod]
87+
[ExpectedException (typeof (ArgumentException))]
88+
public async Task TestCreateDatabaseAsync_InvalidName()
89+
{
90+
var client = new InfluxDBClient (influxUrl, dbUName, dbpwd);
91+
var r = await client.CreateDatabaseAsync (invalidDbName);
92+
}
93+
8594
[TestMethod]
8695
public async Task TestCreateDatabaseAsync()
8796
{
8897
try
8998
{
90-
//pass 8089, which is not influx port
99+
91100
var client = new InfluxDBClient (influxUrl, dbUName, dbpwd);
92101
var r = await client.CreateDatabaseAsync (dbName);
93102
Assert.IsTrue (r, "CreateDatabaseAsync retunred false");
@@ -105,13 +114,23 @@ public async Task TestCreateDatabaseAsync()
105114
}
106115
}
107116

108-
109117
[TestMethod]
110-
[ExpectedException (typeof (ArgumentException))]
111-
public async Task TestCreateDatabaseAsync_InvalidName()
118+
public async Task TestPostValueAsync()
112119
{
113-
var client = new InfluxDBClient (influxUrl, dbUName, dbpwd);
114-
var r = await client.CreateDatabaseAsync (invalidDbName);
120+
try
121+
{
122+
var client = new InfluxDBClient (influxUrl, dbUName, dbpwd);
123+
var r = await client.PostValueAsync (dbName, measurementName, DateTime.Now.ToEpoch(TimePrecision.Seconds),TimePrecision.Seconds,"testTag=testTagValue","Temp",33.05);
124+
Assert.IsTrue (r, "PostValueAsync retunred false");
125+
}
126+
catch ( Exception e )
127+
{
128+
129+
Assert.Fail ("Unexpected exception of type {0} caught: {1}",
130+
e.GetType (), e.Message);
131+
return;
132+
}
115133
}
134+
116135
}
117136
}

AdysTech.InfluxDB.Client.Net/AdysTech.InfluxDB.Client.Net.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<Reference Include="System.Xml" />
4141
</ItemGroup>
4242
<ItemGroup>
43+
<Compile Include="ExtensionMethods.cs" />
4344
<Compile Include="IInfluxDBClient.cs" />
4445
<Compile Include="InfluxDBClient.cs" />
4546
<Compile Include="Properties\AssemblyInfo.cs" />
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace AdysTech.InfluxDB.Client.Net
8+
{
9+
public static class EpochHelper
10+
{
11+
private static readonly DateTime Origin = new DateTime (1970, 1, 1);
12+
13+
public static long ToEpoch(this DateTime time, TimePrecision precision)
14+
{
15+
TimeSpan t = time - Origin;
16+
switch ( precision )
17+
{
18+
case TimePrecision.Hours: return (long) t.TotalHours;
19+
case TimePrecision.Minutes: return (long) t.TotalMinutes;
20+
case TimePrecision.Seconds: return (long) t.TotalSeconds;
21+
case TimePrecision.Milliseconds: return (long) t.TotalMilliseconds;
22+
case TimePrecision.Microseconds: return (long) t.TotalMilliseconds * 1000;
23+
case TimePrecision.Nanoseconds: return (long) t.TotalMilliseconds * 1000 * 1000;
24+
}
25+
return 0;
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)