Exemple #1
0
        public void TestSerialize()
        {
            // test of MinimalTopicRankFeedEntitySerialize

            // first, check the normal case
            var separator = ":";
            var entity    = new TopicRankFeedEntity()
            {
                TopicHandle = "baz", UserHandle = "bar", AppHandle = "foo"
            };
            var result = StoreSerializers.MinimalTopicRankFeedEntitySerialize(entity);

            Assert.AreEqual("baz" + separator + "bar" + separator + "foo", result);

            // next, try a null input
            result = StoreSerializers.MinimalTopicRankFeedEntitySerialize(null);
            Assert.AreEqual(null, result);

            // next, try null values
            entity = new TopicRankFeedEntity();
            result = StoreSerializers.MinimalTopicRankFeedEntitySerialize(entity);
            Assert.AreEqual(separator + separator, result);

            // next, try inserting a handle with a ":"
            entity = new TopicRankFeedEntity()
            {
                TopicHandle = "ba:z", UserHandle = "bar", AppHandle = "foo"
            };
            try
            {
                result = StoreSerializers.MinimalTopicRankFeedEntitySerialize(entity);
                Assert.Fail("Serialize 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 MinimalUserRankFeedEntitySerialize

            // first, test the normal case
            var entity2 = new UserRankFeedEntity()
            {
                UserHandle = "bar", AppHandle = "foo"
            };

            result = StoreSerializers.MinimalUserRankFeedEntitySerialize(entity2);
            Assert.AreEqual("bar" + separator + "foo", result);

            // next, try a null input
            result = StoreSerializers.MinimalUserRankFeedEntitySerialize(null);
            Assert.AreEqual(null, result);

            // next, try null values
            entity2 = new UserRankFeedEntity();
            result  = StoreSerializers.MinimalUserRankFeedEntitySerialize(entity2);
            Assert.AreEqual(separator, result);

            // next, try inserting a handle with a ":"
            entity2 = new UserRankFeedEntity()
            {
                UserHandle = "bar:", AppHandle = "foo"
            };
            try
            {
                result = StoreSerializers.MinimalUserRankFeedEntitySerialize(entity2);
                Assert.Fail("Serialize routine was expected to throw an exception");
            }
            catch (Exception e)
            {
                // check that the operation throws the expected exception
                Assert.AreEqual(e.GetType(), typeof(InvalidOperationException));
            }
        }