Permalink
Browse files

Added Increment+Tests

  • Loading branch information...
1 parent 845314e commit f32d43d24b80ef93049d48d022242ece9c1489a8 @maddenpj maddenpj committed Jan 3, 2013
Showing with 112 additions and 0 deletions.
  1. +1 −0 Client.Tests/Client.Tests.csproj
  2. +69 −0 Client.Tests/IncrementTests.cs
  3. +42 −0 Client/Client.cs
@@ -63,6 +63,7 @@
<ItemGroup>
<Compile Include="DataPointModelTests.cs" />
<Compile Include="DeleteTests.cs" />
+ <Compile Include="IncrementTests.cs" />
<Compile Include="JsonDeserializationTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReadTests.cs" />
@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using Client.Model;
+using MbUnit.Framework;
+using RestSharp;
+using System.Linq.Expressions;
+using Moq;
+
+namespace Client.Tests
+{
+ [TestFixture]
+ public class IncrementTests
+ {
+ [Test]
+ public void Request()
+ {
+ var mockclient = TestCommon.GetMockRestClient();
+ var client = TestCommon.GetClient(mockclient.Object);
+
+ var data = new List<DataPoint>();
+ double valueToAdd = new Random().NextDouble() * 1000D;
+ data.Add(new DataPoint(DateTime.Now, valueToAdd));
+ client.IncrementByKey("key", data);
+
+ Expression<Func<RestRequest, bool>> assertion = req => req.Method == Method.POST && req.Resource == "/series/{property}/{value}/increment/";
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(assertion)));
+ }
+
+ [Test]
+ public void IncludesPoints()
+ {
+ var mockclient = TestCommon.GetMockRestClient();
+ var client = TestCommon.GetClient(mockclient.Object);
+
+ var data = new List<DataPoint>();
+ data.Add(new DataPoint(new DateTime(2012, 12, 12), 12.34));
+ data.Add(new DataPoint(new DateTime(2012, 12, 12, 0, 0, 1), 56.78));
+ data.Add(new DataPoint(new DateTime(2012, 12, 12, 0, 0, 2), 90.12));
+ client.IncrementByKey("testkey", data);
+
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => TestCommon.ContainsParameterByPattern(req.Parameters, "application/json", "12.34"))));
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => TestCommon.ContainsParameterByPattern(req.Parameters, "application/json", "56.78"))));
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => TestCommon.ContainsParameterByPattern(req.Parameters, "application/json", "90.12"))));
+ }
+
+ [Test]
+ public void RequestCount()
+ {
+ var numPoints = 100;
+
+ var mockClient = TestCommon.GetMockRestClient();
+ var client = TestCommon.GetClient(mockClient.Object);
+
+ var baseDateTime = new DateTime(2012, 06, 23);
+ for (int i = 0; i < numPoints; i++)
+ {
+ var points = new List<BulkPoint>
+ {
+ new BulkKeyPoint("testkey1", 12.555D * new Random().NextDouble()),
+ new BulkKeyPoint("testkey2", 555D * new Random().NextDouble())
+ };
+
+ var dataSet = new BulkDataSet(baseDateTime.AddMinutes(5 * i), points);
+ client.IncrementBulkData(dataSet);
+ }
+ mockClient.Verify(cl => cl.Execute(It.IsAny<RestRequest>()), Times.Exactly(100));
+ }
+ }
+}
View
@@ -241,6 +241,48 @@ public virtual void WriteBulkData(BulkDataSet dataSet)
}
/// <summary>
+ /// Increments a DataSet by id
+ /// </summary>
+ /// <param name="seriesId"> The id of the series into which the data points will be incremented</param>
+ /// <param name="data"> A list of DataPoints to increment </param>
+ public void IncrementById(string seriesId, IList<DataPoint> data)
+ {
+ IncrementDataPoints(SeriesProperty.Id, seriesId, data);
+ }
+
+ /// <summary>
+ /// Increments a DataSet by key
+ /// </summary>
+ /// <param name="seriesKey"> The key of the series into which the data points will be incremented</param>
+ /// <param name="data"> A list of DataPoints to incremented </param>
+ public void IncrementByKey(string seriesKey, IList<DataPoint> data)
+ {
+ IncrementDataPoints(SeriesProperty.Key, seriesKey, data);
+ }
+
+
+ private void IncrementDataPoints(string seriesProperty, string propertyValue, IList<DataPoint> data)
+ {
+ const string url = "/series/{property}/{value}/increment/";
+ RestRequest request = BuildRequest(url, Method.POST, data);
+ request.AddUrlSegment("property", seriesProperty);
+ request.AddUrlSegment("value", propertyValue);
+ Execute(request);
+ }
+
+
+ /// <summary>
+ /// Increments a set of datapoints for different series for the same timestamp
+ /// </summary>
+ /// <param name="dataSet"> A BulkDataSet to increments </param>
+ public virtual void IncrementBulkData(BulkDataSet dataSet)
+ {
+ const string url = "/increment/";
+ RestRequest request = BuildRequest(url, Method.POST, dataSet);
+ Execute(request);
+ }
+
+ /// <summary>
/// Deletes a range of data by id
/// </summary>
/// <param name="seriesId"> The id of the series into which the data points will be deleted</param>

0 comments on commit f32d43d

Please sign in to comment.