Esempio n. 1
0
        TestTryParseStatus()
        {
            Dictionary <String, Object> statusValueDictionary =
                GetStatusValueDictionary();

            Int64    statusID;
            DateTime statusDateUtc;
            String   screenName;
            String   text;
            String   rawStatusJson;
            Dictionary <String, Object> userValueDictionary;

            Boolean returnValue = TwitterStatusParser.TryParseStatus(
                statusValueDictionary,
                out statusID,
                out statusDateUtc,
                out screenName,
                out text,
                out rawStatusJson,
                out userValueDictionary
                );

            Assert.IsTrue(returnValue);

            Assert.AreEqual(330018625320787969, statusID);
            Assert.AreEqual(new DateTime(2013, 5, 2, 17, 59, 6), statusDateUtc);
            Assert.AreEqual("Andrew_Muras", screenName);

            Assert.AreEqual("Completed 1st SNA analysis a week ago using NodeXL-Marathon Oil used same tool and interesting perspective on analyzing COPs #apqckmconf",
                            text);

            // The expected raw status JSON, which is stored in a test file, is not
            // identical to what came in the Twitter response.  Specifically, the
            // JavaScriptSerializer that TryParseStatus() used to rebuild the JSON
            // escapes single quotes and does not escape forward slashes.

            String expectedRawStatusJson = ReadTextFile(
                ExpectedRawStatusJsonFilePath);

            Assert.AreEqual(expectedRawStatusJson, rawStatusJson);

            // Confirm that the raw status JSON can be parsed again.

            Object deserializedStatus =
                (new JavaScriptSerializer()).DeserializeObject(rawStatusJson);

            Dictionary <String, Object> rebuiltStatusValueDictionary =
                (Dictionary <String, Object>)deserializedStatus;

            Assert.AreEqual(statusValueDictionary.Count,
                            rebuiltStatusValueDictionary.Count);
        }
Esempio n. 2
0
        TestUserValueDictionaryToRawJson()
        {
            Dictionary <String, Object> statusValueDictionary =
                GetStatusValueDictionary();

            Int64    statusID;
            DateTime statusDateUtc;
            String   screenName;
            String   text;
            String   rawStatusJson;
            Dictionary <String, Object> userValueDictionary;

            Boolean returnValue = TwitterStatusParser.TryParseStatus(
                statusValueDictionary,
                out statusID,
                out statusDateUtc,
                out screenName,
                out text,
                out rawStatusJson,
                out userValueDictionary
                );

            Assert.IsTrue(returnValue);

            String rawUserJson = TwitterStatusParser.UserValueDictionaryToRawJson(
                userValueDictionary);

            // The expected raw user JSON, which is stored in a test file, is not
            // identical to what came in the Twitter response.  Specifically, the
            // JavaScriptSerializer that UserValueDictionaryToRawJson() used to
            // rebuild the JSON escapes single quotes and does not escape forward
            // slashes.

            String expectedRawUserJson = ReadTextFile(ExpectedRawUserJsonFilePath);

            Assert.AreEqual(expectedRawUserJson, rawUserJson);

            // Confirm that the raw user JSON can be parsed again.

            Object deserializedUser =
                (new JavaScriptSerializer()).DeserializeObject(rawUserJson);

            Dictionary <String, Object> rebuiltUserValueDictionary =
                (Dictionary <String, Object>)deserializedUser;

            Assert.AreEqual(userValueDictionary.Count,
                            rebuiltUserValueDictionary.Count);
        }