Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Start working on pulling data out of JSON into objects

  • Loading branch information...
commit e3ea376c2dbf2a9d8c021be9a7662621eb773cb2 1 parent 5a893cd
@rtyler authored
Showing with 85 additions and 0 deletions.
  1. +1 −0  Proggitbot.nant.build
  2. +63 −0 source/Entry.cs
  3. +21 −0 tests/ProggitTest.cs
View
1  Proggitbot.nant.build
@@ -49,6 +49,7 @@
output="${build.dir}/${project.tests}">
<sources>
<include name="${project.sourcedir}/Proggitbot.cs"/>
+ <include name="${project.sourcedir}/Entry.cs"/>
<include name="${project.testdir}/**.cs"/>
</sources>
<references>
View
63 source/Entry.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Web.Script.Serialization;
+
+namespace Proggitbot
+{
+ [Serializable]
+ public class Entry
+ {
+ #region "Member Variables"
+ private string kind = null;
+ private EntryData data = null;
+ #endregion
+ }
+
+ [Serializable]
+ public class EntryData
+ {
+ #region "Member Variables"
+ private string domain = null;
+ private string subreddit = null;
+ private string id = null;
+ private string author = null;
+ private Int64 score = 0;
+ private string subreddit_id = null;
+ private Int64 downs = 0;
+ private Int64 ups = 0;
+ private string name = null;
+ private DateTime created;
+ private DateTime created_utc;
+ private string url = null;
+ private string title = null;
+ private Int64 num_comments = 0;
+ #endregion
+
+ #region "Public Properties"
+ public string Domain
+ {
+ get { return this.domain; }
+ set { this.domain = value; }
+ }
+
+ public string Author
+ {
+ get { return this.author; }
+ set { this.author = value; }
+ }
+
+ public string Url
+ {
+ get { return this.url; }
+ set { this.url = value; }
+ }
+
+ public string Title
+ {
+ get { return this.title; }
+ set { this.title = value; }
+ }
+ #endregion
+ }
+}
+
View
21 tests/ProggitTest.cs
@@ -1,4 +1,5 @@
using System;
+using System.Web.Script.Serialization;
using Proggitbot;
using NUnit.Framework;
@@ -8,5 +9,25 @@ namespace Proggitbot.Tests
[TestFixture]
public class ParseJson
{
+ protected readonly string sampleDataField = "{\"domain\": \"ted.com\",\"media_embed\": { },\"subreddit\": \"programming\",\"selftext_html\": null,\"selftext\": \"\",\"likes\": null,\"saved\": false,\"id\": \"9k30b\",\"clicked\": false,\"author\": \"scientologist2\",\"media\": null,\"score\": 353,\"hidden\": false,\"thumbnail\": \"\",\"subreddit_id\": \"t5_2fwo\",\"downs\": 97,\"name\": \"t3_9k30b\",\"created\": 1252871681.0,\"url\": \"http://www.ted.com/talks/dan_pink_on_motivation.html\",\"title\": \"The science of motivation vs. problem solving\",\"created_utc\": 1252846481.0,\"num_comments\": 82,\"ups\": 450}";
+
+ protected JavaScriptSerializer json = null;
+
+ [SetUp]
+ public void SetUp()
+ {
+ this.json = new JavaScriptSerializer();
+ }
+
+ [Test]
+ public void DeserializeIntoEntryData()
+ {
+ EntryData data = this.json.Deserialize<EntryData>(this.sampleDataField);
+
+ Assert.IsNotNull(data, "EntryData object is null");
+ Assert.AreEqual("The science of motivation vs. problem solving", data.Title, "Title mismatch");
+ Assert.AreEqual("scientologist2", data.Author, "Author mismatch");
+ Assert.AreEqual("ted.com", data.Domain, "Domain mismatch");
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.