Permalink
Browse files

Finished Tests

  • Loading branch information...
1 parent 04ba65a commit c1113c0a3df41c3e471f3020d3d523108749b27f @maddenpj maddenpj committed Dec 18, 2012
@@ -61,9 +61,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="DataPointModelTests.cs" />
+ <Compile Include="JsonDeserializationTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReadTests.cs" />
<Compile Include="JsonSerializationTests.cs" />
+ <Compile Include="SeriesModelTests.cs" />
<Compile Include="SeriesTests.cs" />
<Compile Include="TestCommon.cs" />
<Compile Include="WriteTests.cs" />
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Client.Model;
+using MbUnit.Framework;
+
+namespace Client.Tests
+{
+ [TestFixture]
+ class DataPointModelTests
+ {
+ [Test]
+ public void Unequality_Timestamp()
+ {
+ var dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1), 12.34);
+ var dp2 = new DataPoint(new DateTime(2012, 1, 1, 0, 2, 0), 12.34);
+
+ Assert.AreNotEqual(dp1, dp2);
+ }
+
+ [Test]
+ public void Equality()
+ {
+ var dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1), 12.34);
+ var dp2 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1), 12.34);
+
+ Assert.AreEqual(dp1, dp2);
+ }
+
+ [Test]
+ public void Unequality_Value()
+ {
+ var dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1), 12.34);
+ var dp2 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1), 10.34);
+
+ Assert.AreNotEqual(dp1, dp2);
+ }
+
+ [Test]
+ public void Unequality_Null()
+ {
+ var dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1), 12.34);
+
+ Assert.AreNotEqual(dp1, null);
+ }
+
+ [Test]
+ public void Equality_Null()
+ {
+ var dp1 = new DataPoint();
+
+ Assert.AreEqual(false, dp1.Equals(null));
+ }
+ }
+}
@@ -0,0 +1,204 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Client.Model;
+using MbUnit.Framework;
+using Moq;
+using RestSharp;
+
+namespace Client.Tests
+{
+ [TestFixture]
+ class JsonDeserializationTests
+ {
+ static JsonDeserializer deserializer = new JsonDeserializer();
+
+ [TestFixture]
+ class DataPointTests
+ {
+ [Test]
+ public void SmokeTest()
+ {
+ var jsonResponse = new RestResponse
+ {
+ Content = "{\"t\":\"2012-01-01T00:00:01.000-08:00\",\"v\":12.34}"
+ };
+
+ var result = JsonDeserializationTests.deserializer.Deserialize<DataPoint>(jsonResponse);
+ Assert.AreEqual(new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, DateTimeKind.Local), 12.34), result);
+ }
+
+ [Test]
+ public void Long()
+ {
+ var jsonResponse = new RestResponse
+ {
+ Content = "{\"t\":\"2012-01-01T00:00:01.000-08:00\",\"v\":1234}"
+ };
+
+ var result = JsonDeserializationTests.deserializer.Deserialize<DataPoint>(jsonResponse);
+ Assert.AreEqual(new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, DateTimeKind.Local), 1234.0), result);
+ }
+ }
+
+ [TestFixture]
+ class SeriesTests
+ {
+ [Test]
+ public void SmokeTest()
+ {
+ var jsonResponse = new RestResponse
+ {
+ Content = "{\"id\":\"series-id\",\"key\":\"series-key\",\"name\":null,\"attributes\":null,\"tags\":null}"
+ };
+ var series = new Series
+ {
+ Id = "series-id",
+ Key = "series-key"
+ };
+
+ var result = JsonDeserializationTests.deserializer.Deserialize<Series>(jsonResponse);
+ Assert.AreEqual(series, result);
+ }
+
+ [Test]
+ public void Name()
+ {
+ var jsonResponse = new RestResponse
+ {
+ Content = "{\"id\":\"series-id\",\"key\":\"series-key\",\"name\":\"series-name\",\"attributes\":null,\"tags\":null}"
+ };
+
+ var result = JsonDeserializationTests.deserializer.Deserialize<Series>(jsonResponse);
+ Assert.AreEqual("series-name", result.Name);
+ }
+
+ [Test]
+ public void Tags()
+ {
+ var jsonResponse = new RestResponse
+ {
+ Content = "{\"id\":\"series-id\",\"key\":\"series-key\",\"name\":null,\"attributes\":null,\"tags\":[\"tag1\",\"tag2\"]}"
+ };
+
+ var result = JsonDeserializationTests.deserializer.Deserialize<Series>(jsonResponse);
+ Assert.AreEqual(2, result.Tags.Count);
+ Assert.AreEqual("tag1", result.Tags[0]);
+ Assert.AreEqual("tag2", result.Tags[1]);
+ }
+
+ [Test]
+ public void Attributes()
+ {
+ var jsonResponse = new RestResponse
+ {
+ Content = "{\"id\":\"series-id\",\"key\":\"series-key\",\"name\":null,\"attributes\":{\"key1\":\"val1\",\"key2\":\"val2\"},\"tags\":null}"
+ };
+
+ var result = JsonDeserializationTests.deserializer.Deserialize<Series>(jsonResponse);
+ Assert.AreEqual(2, result.Attributes.Count);
+ Assert.AreEqual("val1", result.Attributes["key1"]);
+ Assert.AreEqual("val2", result.Attributes["key2"]);
+
+ }
+
+ [Test]
+ public void EmptyTags()
+ {
+ var jsonResponse = new RestResponse
+ {
+ Content = "{\"id\":\"series-id\",\"key\":\"series-key\",\"name\":null,\"attributes\":null,\"tags\":[]}"
+ };
+
+ var result = JsonDeserializationTests.deserializer.Deserialize<Series>(jsonResponse);
+ Assert.AreEqual(0, result.Tags.Count);
+ }
+
+ [Test]
+ public void EmptyAttributes()
+ {
+ var jsonResponse = new RestResponse
+ {
+ Content = "{\"id\":\"series-id\",\"key\":\"series-key\",\"name\":null,\"attributes\":{},\"tags\":null}"
+ };
+
+ var result = JsonDeserializationTests.deserializer.Deserialize<Series>(jsonResponse);
+ Assert.AreEqual(0, result.Attributes.Count);
+ }
+ }
+
+ [TestFixture]
+ class DataSetTests
+ {
+ static string jsonDataset = @"{
+ ""series"": {
+ ""id"": ""01868c1a2aaf416ea6cd8edd65e7a4b8"",
+ ""key"": ""key1"",
+ ""name"": """",
+ ""tags"": [
+ ""temp""
+ ],
+ ""attributes"": {
+ ""temp"": ""1""
+ }
+ },
+ ""start"": ""2012-01-08T00:00:00.000+0000"",
+ ""end"": ""2012-01-09T00:00:00.000+0000"",
+ ""data"": [
+ {""t"": ""2012-01-08T00:00:00.000+0000"", ""v"": 4.00},
+ {""t"": ""2012-01-08T06:00:00.000+0000"", ""v"": 3.00},
+ {""t"": ""2012-01-08T12:00:00.000+0000"", ""v"": 2.00},
+ {""t"": ""2012-01-08T18:00:00.000+0000"", ""v"": 3.00}
+ ],
+ ""summary"": {
+ ""mean"": 3.00,
+ ""sum"": 12.00,
+ ""min"": 2.00,
+ ""max"": 4.00,
+ ""stddev"": 0.8165,
+ ""ss"": 2.00,
+ ""count"": 4
+ }
+ }";
+
+ [Test]
+ public void SmokeTest()
+ {
+ var jsonResponse = new RestResponse
+ {
+ Content = DataSetTests.jsonDataset
+ };
+
+ var result = JsonDeserializationTests.deserializer.Deserialize<DataSet>(jsonResponse);
+ Assert.AreEqual(new DateTime(2012, 1, 8).ToLocalTime(), result.Start);
+ Assert.AreEqual(new DateTime(2012, 1, 9).ToLocalTime(), result.End);
+ Assert.AreEqual("01868c1a2aaf416ea6cd8edd65e7a4b8", result.Series.Id);
+ Assert.AreEqual(4, result.Data.Count);
+ Assert.AreEqual(new DataPoint(new DateTime(2012, 1, 8).ToLocalTime(), 4.0), result.Data[0]);
+ Assert.AreEqual(new DataPoint(new DateTime(2012, 1, 8, 6, 0, 0).ToLocalTime(), 3.0), result.Data[1]);
+ Assert.AreEqual(3.0, result.Summary["mean"]);
+ Assert.AreEqual(12.0, result.Summary["sum"]);
+ }
+
+ [Test]
+ public void EmptySummary()
+ {
+ var emptySummary = jsonDataset.Substring(0, jsonDataset.LastIndexOf("\"mean\""));
+ emptySummary += "}}";
+ var jsonResponse = new RestResponse
+ {
+ Content = emptySummary
+ };
+
+ var result = JsonDeserializationTests.deserializer.Deserialize<DataSet>(jsonResponse);
+ Assert.AreEqual(0, result.Summary.Count);
+
+
+ }
+ }
+ }
+
+
+
+}
@@ -15,7 +15,7 @@ public class JsonSerializationTests
public static JsonSerializer serializer = new JsonSerializer();
[TestFixture]
- public class DataPointSerializationTests
+ public class DataPointTests
{
[Test]
public void SmokeTest()
@@ -36,7 +36,7 @@ public void EmptyValue()
}
[TestFixture]
- public class SeriesSerializationTests
+ public class SeriesTests
{
[Test]
public void SmokeTest()
@@ -123,7 +123,7 @@ public void EmptyAttributes()
}
[TestFixture]
- public class BulkIdSerializationTests
+ public class BulkIdTests
{
[Test]
public void SmokeTest()
@@ -136,7 +136,7 @@ public void SmokeTest()
}
[TestFixture]
- public class BulkKeySerializationTests
+ public class BulkKeyTests
{
[Test]
public void SmokeTest()
@@ -149,7 +149,7 @@ public void SmokeTest()
}
[TestFixture]
- public class BulkDataSetSerializationTests
+ public class BulkDataSetTests
{
[Test]
public void SmokeTest()
Oops, something went wrong.

0 comments on commit c1113c0

Please sign in to comment.