Permalink
Browse files

Added Delete + tests

  • Loading branch information...
1 parent 83ee5a6 commit 52217ecfa0f6537bb6772a0bbdf5cac633854319 @maddenpj maddenpj committed Dec 21, 2012
Showing with 84 additions and 0 deletions.
  1. +1 −0 Client.Tests/Client.Tests.csproj
  2. +50 −0 Client.Tests/DeleteTests.cs
  3. +33 −0 Client/Client.cs
View
1 Client.Tests/Client.Tests.csproj
@@ -62,6 +62,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DataPointModelTests.cs" />
+ <Compile Include="DeleteTests.cs" />
<Compile Include="JsonDeserializationTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReadTests.cs" />
View
50 Client.Tests/DeleteTests.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Client.Model;
+using MbUnit.Framework;
+using RestSharp;
+using System.Linq.Expressions;
+using Moq;
+
+namespace Client.Tests
+{
+ [TestFixture]
+ class DeleteTests
+ {
+ [Test]
+ public void SmokeTest()
+ {
+ var mockclient = TestCommon.GetMockRestClient();
+ var client = TestCommon.GetClient(mockclient.Object);
+
+
+ client.DeleteById("series-id", new DateTime(2012, 1, 1), new DateTime(2012, 1, 1, 1, 0, 0));
+
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => req.Method == Method.DELETE)));
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => req.Resource == "/series/{property}/{value}/data")));
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "start", "2012-01-01T00:00:00.000-08:00"))));
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "end", "2012-01-01T01:00:00.000-08:00"))));
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "property", "id"))));
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "value", "series-id"))));
+ }
+
+ [Test]
+ public void Key()
+ {
+ var mockclient = TestCommon.GetMockRestClient();
+ var client = TestCommon.GetClient(mockclient.Object);
+
+
+ client.DeleteByKey("series-key", new DateTime(2012, 1, 1), new DateTime(2012, 1, 1, 1, 0, 0));
+
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => req.Method == Method.DELETE)));
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => req.Resource == "/series/{property}/{value}/data")));
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "start", "2012-01-01T00:00:00.000-08:00"))));
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "end", "2012-01-01T01:00:00.000-08:00"))));
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "property", "key"))));
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "value", "series-key"))));
+ }
+ }
+}
View
33 Client/Client.cs
@@ -238,6 +238,39 @@ public virtual void WriteBulkData(BulkDataSet dataSet)
Execute(request);
}
+ /// <summary>
+ /// Deletes a range of data by id
+ /// </summary>
+ /// <param name="Id"> The id of the series into which the data points will be deleted</param>
+ /// <param name="start"> Start of range </param>
+ /// <param name="end"> End of range </param>
+ public void DeleteById(string seriesId, DateTime start, DateTime end)
+ {
+ DeleteDataPoints("id", seriesId, start, end);
+ }
+
+ /// <summary>
+ /// Deletes a range of data by key
+ /// </summary>
+ /// <param name="key"> The key of the series into which the data points will be deleted</param>
+ /// <param name="start"> Start of range </param>
+ /// <param name="end"> End of range </param>
+ public void DeleteByKey(string seriesKey, DateTime start, DateTime end)
+ {
+ DeleteDataPoints("key", seriesKey, start, end);
+ }
+
+ private void DeleteDataPoints(string seriesProperty, string propertyValue, DateTime start, DateTime end)
+ {
+ const string url = "/series/{property}/{value}/data";
+ RestRequest request = BuildRequest(url, Method.DELETE);
+ request.AddUrlSegment("property", seriesProperty);
+ request.AddUrlSegment("value", propertyValue);
+ request.AddParameter(QueryStringParameter.Start, TempoDateTimeConvertor.ConvertDateTimeToString(start));
+ request.AddParameter(QueryStringParameter.End, TempoDateTimeConvertor.ConvertDateTimeToString(end));
+ Execute(request);
+ }
+
private RestRequest BuildRequest(string url, Method method, object body = null)
{

0 comments on commit 52217ec

Please sign in to comment.