Browse files

Fixed failing test error messages

  • Loading branch information...
1 parent d5c743c commit 3dd3bc4e39f0e40708b232d9aa1082936038d925 @maddenpj maddenpj committed Dec 17, 2012
Showing with 77 additions and 69 deletions.
  1. +61 −33 Client.Tests/ReadTests.cs
  2. +4 −10 Client.Tests/TestCommon.cs
  3. +12 −26 Client.Tests/WriteTests.cs
View
94 Client.Tests/ReadTests.cs
@@ -33,59 +33,76 @@ public void ItShouldReadSeriesDataByKey()
[Test]
public void ItShouldReadSeriesDataByKey_RequestMethod()
{
- Expression<Func<RestRequest, bool>> assertion = req => req.Method == Method.GET;
+ var mockclient = TestCommon.GetMockRestClient<DataSet>(new DataSet());
+ var client = TestCommon.GetClient(mockclient.Object);
- var client = TestCommon.GetClient(TestCommon.GetMockRestClient<DataSet>(new DataSet(),assertion).Object);
var results = client.ReadByKey("testkey", new DateTime(2012, 06, 23), new DateTime(2012, 06, 24), IntervalParameter.Raw());
+
+ Expression<Func<RestRequest, bool>> assertion = req => req.Method == Method.GET;
+ mockclient.Verify(cl => cl.Execute<DataSet>(It.Is<RestRequest>(assertion)));
}
[Test]
public void ItShouldReadSeriesDataByKey_RequestStartTime()
{
- Expression<Func<RestRequest, bool>> assertion = req => TestCommon.ContainsParameter(req.Parameters, "start", "2012-06-23T00:00:00.000-07:00");
+ var mockclient = TestCommon.GetMockRestClient<DataSet>(new DataSet());
+ var client = TestCommon.GetClient(mockclient.Object);
- var client = TestCommon.GetClient(TestCommon.GetMockRestClient<DataSet>(new DataSet(), assertion).Object);
var results = client.ReadByKey("testkey", new DateTime(2012, 06, 23), new DateTime(2012, 06, 24), IntervalParameter.Raw());
+
+ Expression<Func<RestRequest, bool>> assertion = req => TestCommon.ContainsParameter(req.Parameters, "start", "2012-06-23T00:00:00.000-07:00");
+ mockclient.Verify(cl => cl.Execute<DataSet>(It.Is<RestRequest>(assertion)));
}
[Test]
public void ItShouldReadSeriesDataByKey_RequestEndTime()
{
- Expression<Func<RestRequest, bool>> assertion = req => TestCommon.ContainsParameter(req.Parameters, "end", "2012-06-24T00:00:00.000-07:00");
-
- var client = TestCommon.GetClient(TestCommon.GetMockRestClient<DataSet>(new DataSet(), assertion).Object);
+ var mockclient = TestCommon.GetMockRestClient<DataSet>(new DataSet());
+ var client = TestCommon.GetClient(mockclient.Object);
+
var results = client.ReadByKey("testkey", new DateTime(2012, 06, 23), new DateTime(2012, 06, 24), IntervalParameter.Raw());
+
+ Expression<Func<RestRequest, bool>> assertion = req => TestCommon.ContainsParameter(req.Parameters, "end", "2012-06-24T00:00:00.000-07:00");
+ mockclient.Verify(cl => cl.Execute<DataSet>(It.Is<RestRequest>(assertion)));
}
[Test]
public void ItShouldReadSeriesDataByKey_RequestUrl()
{
- Expression<Func<RestRequest, bool>> assertion = req => req.Resource == "/series/{property}/{value}/data" &&
- TestCommon.ContainsParameter(req.Parameters, "property", "key") &&
- TestCommon.ContainsParameter(req.Parameters, "value", "testkey");
+ var mockclient = TestCommon.GetMockRestClient<DataSet>(new DataSet());
+ var client = TestCommon.GetClient(mockclient.Object);
- var client = TestCommon.GetClient(TestCommon.GetMockRestClient<DataSet>(new DataSet(), assertion).Object);
var results = client.ReadByKey("testkey", new DateTime(2012, 06, 23), new DateTime(2012, 06, 24), IntervalParameter.Raw());
+
+ mockclient.Verify(cl => cl.Execute<DataSet>(It.Is<RestRequest>(req => req.Resource == "/series/{property}/{value}/data")));
+ mockclient.Verify(cl => cl.Execute<DataSet>(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "property", "key"))));
+ mockclient.Verify(cl => cl.Execute<DataSet>(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "value", "testkey"))));
+
}
[Test]
public void ItShouldReadSeriesDataByKey_RequestInterval()
{
- Expression<Func<RestRequest, bool>> assertion = req => TestCommon.ContainsParameter(req.Parameters, "interval", "raw");
-
- var client = TestCommon.GetClient(TestCommon.GetMockRestClient<DataSet>(new DataSet(), assertion).Object);
+ var mockclient = TestCommon.GetMockRestClient<DataSet>(new DataSet());
+ var client = TestCommon.GetClient(mockclient.Object);
+
var results = client.ReadByKey("testkey", new DateTime(2012, 06, 23), new DateTime(2012, 06, 24), IntervalParameter.Raw());
+
+ Expression<Func<RestRequest, bool>> assertion = req => TestCommon.ContainsParameter(req.Parameters, "interval", "raw");
+ mockclient.Verify(cl => cl.Execute<DataSet>(It.Is<RestRequest>(assertion)));
}
[Test]
public void ItShouldReadSeriesDataById_RequestUrl()
{
- Expression<Func<RestRequest, bool>> assertion = req => req.Resource == "/series/{property}/{value}/data" &&
- TestCommon.ContainsParameter(req.Parameters, "property", "id") &&
- TestCommon.ContainsParameter(req.Parameters, "value", "testid");
+ var mockclient = TestCommon.GetMockRestClient<DataSet>(new DataSet());
+ var client = TestCommon.GetClient(mockclient.Object);
- var client = TestCommon.GetClient(TestCommon.GetMockRestClient<DataSet>(new DataSet(), assertion).Object);
var results = client.ReadById("testid", new DateTime(2012, 06, 23), new DateTime(2012, 06, 24), IntervalParameter.Raw());
+
+ mockclient.Verify(cl => cl.Execute<DataSet>(It.Is<RestRequest>(req => req.Resource == "/series/{property}/{value}/data")));
+ mockclient.Verify(cl => cl.Execute<DataSet>(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "property", "id"))));
+ mockclient.Verify(cl => cl.Execute<DataSet>(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "value", "testid"))));
}
[Test]
@@ -115,46 +132,57 @@ public void ItShouldReadMultipleSeries_Response()
[Test]
public void ItShouldReadMultipleSeries_RequestUrl()
{
- Expression<Func<RestRequest, bool>> assertion = req => req.Resource == "/data/";
- var client = TestCommon.GetClient(TestCommon.GetMockRestClient<List<DataSet>>(new List<DataSet>(), assertion).Object);
+ var mockclient = TestCommon.GetMockRestClient<List<DataSet>>(new List<DataSet>());
+ var client = TestCommon.GetClient(mockclient.Object);
+
var filter = new Filter();
filter.AddKey("series1");
filter.AddKey("series2");
- var results = client.ReadMultipleSeries(new DateTime(2012, 06, 23), new DateTime(2012, 06, 24), filter, IntervalParameter.Raw());
+ var results = client.ReadMultipleSeries(new DateTime(2012, 06, 23), new DateTime(2012, 06, 24), filter, IntervalParameter.Raw());
+
+ Expression<Func<RestRequest, bool>> assertion = req => req.Resource == "/data/";
+ mockclient.Verify(cl => cl.Execute<List<DataSet>>(It.Is<RestRequest>(assertion)));
+
}
[Test]
public void ItShouldReadMultipleSeries_RequestFilter()
{
- Expression<Func<RestRequest, bool>> assertion = req => TestCommon.ContainsParameter(req.Parameters, "key", "series1") &&
- TestCommon.ContainsParameter(req.Parameters, "key", "series2");
-
- var client = TestCommon.GetClient(TestCommon.GetMockRestClient<List<DataSet>>(new List<DataSet>(), assertion).Object);
+ var mockclient = TestCommon.GetMockRestClient<List<DataSet>>(new List<DataSet>());
+ var client = TestCommon.GetClient(mockclient.Object);
+
var filter = new Filter();
filter.AddKey("series1");
filter.AddKey("series2");
var results = client.ReadMultipleSeries(new DateTime(2012, 06, 23), new DateTime(2012, 06, 24), filter, IntervalParameter.Raw());
+
+ mockclient.Verify(cl => cl.Execute<List<DataSet>>(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "key", "series1"))));
+ mockclient.Verify(cl => cl.Execute<List<DataSet>>(It.Is<RestRequest>(req => TestCommon.ContainsParameter(req.Parameters, "key", "series2"))));
}
[Test]
public void ItShouldReadSeriesDataByKey_RequestInterval1Hour()
{
- Expression<Func<RestRequest, bool>> assertion = req => TestCommon.ContainsParameter(req.Parameters, "interval", "1hour");
-
- var client = TestCommon.GetClient(TestCommon.GetMockRestClient<DataSet>(new DataSet(), assertion).Object);
+ var mockclient = TestCommon.GetMockRestClient<DataSet>(new DataSet());
+ var client = TestCommon.GetClient(mockclient.Object);
+
var results = client.ReadByKey("testkey", new DateTime(2012, 06, 23), new DateTime(2012, 06, 24), IntervalParameter.Hours(1));
+
+ Expression<Func<RestRequest, bool>> assertion = req => TestCommon.ContainsParameter(req.Parameters, "interval", "1hour");
+ mockclient.Verify(cl => cl.Execute<DataSet>(It.Is<RestRequest>(assertion)));
}
[Test]
public void ItShouldReadSeriesDataByKey_RequestFunction()
{
- Expression<Func<RestRequest, bool>> assertion = req => TestCommon.ContainsParameter(req.Parameters, "function", "sum");
-
- var client = TestCommon.GetClient(TestCommon.GetMockRestClient<DataSet>(new DataSet(), assertion).Object);
+ var mockclient = TestCommon.GetMockRestClient<DataSet>(new DataSet());
+ var client = TestCommon.GetClient(mockclient.Object);
+
var results = client.ReadByKey("testkey", new DateTime(2012, 06, 23), new DateTime(2012, 06, 24), IntervalParameter.Hours(1), FoldingFunction.Sum);
+
+ Expression<Func<RestRequest, bool>> assertion = req => TestCommon.ContainsParameter(req.Parameters, "function", "sum");
+ mockclient.Verify(cl => cl.Execute<DataSet>(It.Is<RestRequest>(assertion)));
}
-
-
}
}
View
14 Client.Tests/TestCommon.cs
@@ -21,11 +21,8 @@ public static Client GetClient(RestClient restClient = null)
.Build();
}
- public static Mock<RestClient> GetMockRestClient<T>(T response, Expression<Func<RestRequest, bool>> requestValidator = null) where T : new()
+ public static Mock<RestClient> GetMockRestClient<T>(T response) where T : new()
{
- if (requestValidator == null)
- requestValidator = req => true;
-
var res = new RestSharp.RestResponse<T>
{
StatusCode = System.Net.HttpStatusCode.OK,
@@ -34,22 +31,19 @@ public static Mock<RestClient> GetMockRestClient<T>(T response, Expression<Func<
};
var restClient = new Mock<RestClient>();
- restClient.Setup(cl => cl.Execute<T>(It.Is<RestRequest>(requestValidator))).Returns(res);
+ restClient.Setup(cl => cl.Execute<T>(It.IsAny<RestRequest>())).Returns(res);
return restClient;
}
- public static Mock<RestClient> GetMockRestClient(Expression<Func<RestRequest, bool>> requestValidator = null)
+ public static Mock<RestClient> GetMockRestClient()
{
- if (requestValidator == null)
- requestValidator = req => true;
-
var res = new RestSharp.RestResponse
{
StatusCode = System.Net.HttpStatusCode.OK
};
var restClient = new Mock<RestClient>();
- restClient.Setup(cl => cl.Execute(It.Is<RestRequest>(requestValidator))).Returns(res);
+ restClient.Setup(cl => cl.Execute(It.IsAny<RestRequest>())).Returns(res);
return restClient;
}
View
38 Client.Tests/WriteTests.cs
@@ -11,52 +11,38 @@ namespace Client.Tests
[TestFixture]
public class WriteTests
{
- private const string API_KEY = "fddc9934f6784a739cc82e2833521218";
- private const string API_SECRET = "6d1f4fae625b4847968b472d3feb5ba5";
- private const string TEST_SERIES_ID = "17b836c0635844a686249969c5b768c6";
- private const string TEST_SERIES_KEY_1 = "asdf";
- private const string TEST_SERIES_KEY_2 = "my_favorite_series";
-
- private Client GetClient()
- {
- return new ClientBuilder()
- .Host("api.tempo-db.com")
- .Key(API_KEY)
- .Port(443)
- .Secret(API_SECRET)
- .Secure(true)
- .Build();
- }
-
[Test]
public void ItShouldAddDataPointToSeriesByKey_RequestMethod()
{
- Expression<Func<RestRequest, bool>> assertion = req => req.Method == Method.POST;
+ var mockclient = TestCommon.GetMockRestClient();
+ var client = TestCommon.GetClient(mockclient.Object);
- var client = TestCommon.GetClient(TestCommon.GetMockRestClient(assertion).Object);
var data = new List<DataPoint>();
double valueToAdd = new Random().NextDouble()*1000D;
data.Add(new DataPoint(DateTime.Now, valueToAdd));
client.WriteByKey("testkey", data);
+
+ Expression<Func<RestRequest, bool>> assertion = req => req.Method == Method.POST;
+ mockclient.Verify(cl => cl.Execute(It.Is<RestRequest>(assertion)));
}
[Test]
public void ItShouldAddDataPointToSeriesByKey_IncludesPoints()
{
- Expression<Func<RestRequest, bool>> assertion = req => TestCommon.ContainsParameterByPattern(req.Parameters, "application/json", "12.34") &&
- TestCommon.ContainsParameterByPattern(req.Parameters, "application/json", "56.78") &&
- TestCommon.ContainsParameterByPattern(req.Parameters, "application/json", "90.12");
+ var mockclient = TestCommon.GetMockRestClient();
+ var client = TestCommon.GetClient(mockclient.Object);
- var client = TestCommon.GetClient(TestCommon.GetMockRestClient(assertion).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.WriteByKey("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 ItShouldAddBulkDataToMultipleSeries_RequestCount()
{

0 comments on commit 3dd3bc4

Please sign in to comment.