Exemple #1
0
        public void TestDeserialize()
        {
            // test of MinimalTopicRankFeedEntityDeserialize

            // first, check the normal case
            var    separator = ":";
            string input     = "abc" + separator + "def" + separator + "foobar";
            var    result    = StoreSerializers.MinimalTopicRankFeedEntityDeserialize(input);

            Assert.AreEqual("abc", result.TopicHandle);
            Assert.AreEqual("def", result.UserHandle);
            Assert.AreEqual("foobar", result.AppHandle);

            // check the null case
            input  = null;
            result = StoreSerializers.MinimalTopicRankFeedEntityDeserialize(input);
            Assert.AreEqual(null, result);

            // check the null string case
            input  = separator + separator;
            result = StoreSerializers.MinimalTopicRankFeedEntityDeserialize(input);
            Assert.AreEqual(string.Empty, result.TopicHandle);
            Assert.AreEqual(string.Empty, result.UserHandle);
            Assert.AreEqual(string.Empty, result.AppHandle);

            // check a case that must never happen
            input = separator;
            try
            {
                result = StoreSerializers.MinimalTopicRankFeedEntityDeserialize(input);
                Assert.Fail("Deserialize routine was expected to throw an exception");
            }
            catch (Exception e)
            {
                // check that the operation throws the expected exception
                Assert.AreEqual(e.GetType(), typeof(InvalidOperationException));
            }

            // test of MinimalUserRankFeedEntityDeserialize

            // first, check the normal case
            input = "abc383" + separator + "def888";
            var result2 = StoreSerializers.MinimalUserRankFeedEntityDeserialize(input);

            Assert.AreEqual("abc383", result2.UserHandle);
            Assert.AreEqual("def888", result2.AppHandle);

            // check the null case
            input   = null;
            result2 = StoreSerializers.MinimalUserRankFeedEntityDeserialize(input);
            Assert.AreEqual(null, result2);

            // check the null string case
            input   = separator;
            result2 = StoreSerializers.MinimalUserRankFeedEntityDeserialize(input);
            Assert.AreEqual(string.Empty, result2.UserHandle);
            Assert.AreEqual(string.Empty, result2.AppHandle);

            // check a case that must never happen
            input = separator + separator;
            try
            {
                result2 = StoreSerializers.MinimalUserRankFeedEntityDeserialize(input);
                Assert.Fail("Deserialize routine was expected to throw an exception");
            }
            catch (Exception e)
            {
                // check that the operation throws the expected exception
                Assert.AreEqual(e.GetType(), typeof(InvalidOperationException));
            }
        }