コード例 #1
0
        public void Test_CompileSuccess()
        {
            MockApiClient.setAPIResponse(
                new ApiResponse(
                    200,
                    "{\"hash\":\"" + TestData.definition_hash + "\",\"created_at\":\"2011-12-13 14:15:16\",\"dpu\":10}",
                    200, 150));

            Definition def = new Definition(m_user, TestData.definition);
            Assert.AreEqual(TestData.definition, def.get(), "Definition CSDL not set correctly");

            try
            {
                def.compile();
            }
            catch (InvalidDataException e)
            {
                Assert.Fail("InvalidDataException: " + e.Message);
            }
            catch (CompileFailedException e)
            {
                Assert.Fail("CompileFailedException: " + e.Message);
            }
            catch (ApiException e)
            {
                Assert.Fail("ApiException: " + e.Message);
            }

            Assert.AreEqual(200, m_user.getRateLimit(), "Incorrect rate limit");
            Assert.AreEqual(150, m_user.getRateLimitRemaining(), "Incorrect rate limit remaining");
            Assert.AreEqual(TestData.definition_hash, def.getHash(), "Incorrect hash");
            Assert.AreEqual(DateTime.ParseExact("2011-12-13 14:15:16", "yyyy-MM-dd HH:mm:ss", null), def.getCreatedAt(), "Incorrect created at date");
            Assert.AreEqual(10, def.getTotalDpu(), "Incorrect total DPU");
        }
コード例 #2
0
 public void Test_CreateDefinition()
 {
     Definition def = new Definition(m_user);
     Assert.AreEqual(String.Empty, def.get(), "Default definition CSDL is not empty");
     def.set(TestData.definition);
     Assert.AreEqual(TestData.definition, def.get(), "Definition CSDL not set correctly");
 }
コード例 #3
0
        /// <summary>
        /// A factory method for creating a consumer from a Definition object.
        /// </summary>
        /// <param name="user">The user object that's creating this consumer.</param>
        /// <param name="type">The consumer type.</param>
        /// <param name="definition">The Definition to be consumed.</param>
        /// <param name="event_handler">An object that implements IEventHandler which will receive the events.</param>
        /// <returns>An object of a type derived from this class.</returns>
        public static StreamConsumer factory(User user, string type, Definition definition, IEventHandler event_handler)
        {
            switch (type)
            {
                case "http":
                    return new StreamConsumer_Http(user, definition, event_handler);

                default:
                    throw new InvalidDataException("Consumer type \"" + type + "\" is unknown");
            }
        }
コード例 #4
0
 /// <summary>
 /// Construct a consumer for the given definition.
 /// </summary>
 /// <param name="user">The User object which is creating this consumer.</param>
 /// <param name="definition">The Definition to be consumed.</param>
 /// <param name="event_handler">The object that will receive events.</param>
 public StreamConsumer(User user, Definition definition, IEventHandler event_handler)
 {
     init(user, event_handler);
     m_hashes.Add(definition.getHash());
 }
コード例 #5
0
 /// <summary>
 /// Subscribe this endpoint to a Definition.
 /// </summary>
 /// <param name="definition">The Definition to which to subscribe.</param>
 /// <param name="name">A name for this subscription.</param>
 /// <returns>A PushSubscription object.</returns>
 public PushSubscription subscribe(Definition definition, string name)
 {
     return subscribeStreamHash(definition.getHash(), name);
 }
コード例 #6
0
 /// <summary>
 /// Construct a consumer for the given definition.
 /// </summary>
 /// <param name="user">The User object which is creating this consumer.</param>
 /// <param name="definition">The Definition to be consumed.</param>
 /// <param name="event_handler">The object that will receive events.</param>
 public StreamConsumer_Http(User user, Definition definition, IEventHandler event_handler)
     : base(user, definition, event_handler)
 {
 }
コード例 #7
0
        public void Test_CompileFailure()
        {
            MockApiClient.setAPIResponse(
                new ApiResponse(
                    400,
                    "{\"error\":\"The target interactin.content does not exist\"}",
                    200, 150));

            Definition def = new Definition(m_user, TestData.invalid_definition);
            Assert.AreEqual(TestData.invalid_definition, def.get(), "Definition CSDL not set correctly");

            try
            {
                def.compile();
                Assert.Fail("Expected CompileFailedException was not thrown");
            }
            catch (InvalidDataException e)
            {
                Assert.Fail("InvalidDataException: " + e.Message);
            }
            catch (CompileFailedException e)
            {
                Assert.AreEqual("The target interactin.content does not exist", e.Message, "Incorrect compile error message in the CompileFailedException");
            }
            catch (ApiException e)
            {
                Assert.Fail("ApiException: " + e.Message);
            }
        }
コード例 #8
0
 public void Test_ConstructionWithCSDL()
 {
     Definition def = new Definition(m_user, TestData.definition);
     Assert.AreEqual(TestData.definition, def.get(), "Definition CSDL is not as expected");
 }
コード例 #9
0
 public void Test_Construction()
 {
     Definition def = new Definition(m_user);
     Assert.AreEqual(String.Empty, def.get(), "Default CSDL is not empty");
 }
コード例 #10
0
        public void Test_GetBuffered()
        {
            MockApiClient.setAPIResponse(
                new ApiResponse(
                    200,
                    "{\"hash\":\"" + TestData.definition_hash + "\",\"created_at\":\"2011-12-13 14:15:16\",\"dpu\":10}",
                    200, 150));

            Definition def = new Definition(m_user, TestData.definition);
            Assert.AreEqual(TestData.definition, def.get(), "Definition CSDL not set correctly");
            Assert.AreEqual(TestData.definition_hash, def.getHash(), "Incorrect hash");

            MockApiClient.setAPIResponse(
                new ApiResponse(
                    200,
                    "{\"stream\":[{\"interaction\":{\"source\":\"Snaptu\",\"author\":{\"username\":\"nittolexia\",\"name\":\"nittosoetreznoe\",\"id\":172192091,\"avatar\":\"http://a0.twimg.com/profile_images/1429378181/gendowor_normal.jpg\",\"link\":\"http://twitter.com/nittolexia\"},\"type\":\"twitter\",\"link\":\"http://twitter.com/nittolexia/statuses/89571192838684672\",\"created_at\":\"Sat, 09 Jul 2011 05:46:51 +0000\",\"content\":\"RT @ayyuchadel: Haha RT @nittolexia: Mending gak ush maen twitter dehh..RT @sansan_arie:\",\"id\":\"1e0a9eedc207acc0e074ea8aecb2c5ea\"},\"twitter\":{\"user\":{\"name\":\"nittosoetreznoe\",\"description\":\"f**k all\",\"location\":\"denpasar, bali\",\"statuses_count\":6830,\"followers_count\":88,\"friends_count\":111,\"screen_name\":\"nittolexia\",\"lang\":\"en\",\"time_zone\":\"Alaska\",\"id\":172192091,\"geo_enabled\":true},\"mentions\":[\"ayyuchadel\",\"nittolexia\",\"sansan_arie\"],\"id\":\"89571192838684672\",\"text\":\"RT @ayyuchadel: Haha RT @nittolexia: Mending gak ush maen twitter dehh..RT @sansan_arie:\",\"source\":\"<a href=\\\"http://www.snaptu.com\\\" rel=\\\"nofollow\\\">Snaptu</a>\",\"created_at\":\"Sat, 09 Jul 2011 05:46:51 +0000\"},\"klout\":{\"score\":45,\"network\":55,\"amplification\":17,\"true_reach\":31,\"slope\":0,\"class\":\"Networker\"},\"peerindex\":{\"score\":30},\"language\":{\"tag\":\"da\"}}]}",
                    200, 150));

            Interaction[] interactions = def.getBuffered();
            Assert.AreEqual("nittosoetreznoe", interactions[0].getStringVal("twitter.user.name"), "The Twitter username is incorrect");
            Assert.AreEqual(89571192838684672, interactions[0].getLongVal("twitter.id"), "The Twitter ID is incorrect");
            Assert.AreEqual("http://a0.twimg.com/profile_images/1429378181/gendowor_normal.jpg", interactions[0].getStringVal("interaction.author.avatar"), "The author avatar is incorrect");
        }
コード例 #11
0
        public void Test_GetDpuBreakdown()
        {
            MockApiClient.setAPIResponse(
                new ApiResponse(
                    200,
                    "{\"hash\":\"" + TestData.definition_hash + "\",\"created_at\":\"2011-12-13 14:15:16\",\"dpu\":10}",
                    200, 150));

            Definition def = new Definition(m_user, TestData.definition);
            Assert.AreEqual(TestData.definition, def.get(), "Definition CSDL not set correctly");
            Assert.AreEqual(TestData.definition_hash, def.getHash(), "Incorrect hash");

            MockApiClient.setAPIResponse(
                new ApiResponse(
                    200,
                    "{\"detail\":{\"contains\":{\"count\":1,\"dpu\":4,\"targets\":{\"interaction.content\":{\"count\":1,\"dpu\":4}}}},\"dpu\":4}",
                    200, 150));

            Dpu dpu = def.getDpuBreakdown();

            Assert.AreEqual(4, dpu.getTotal(), "The total DPU is incorrect");
            Assert.AreEqual(1, dpu.getDpu().Count, "Incorrect number of detail items");
            Assert.AreEqual(1, dpu.getDpu()["contains"].getCount(), "Incorrect count for contains");
            Assert.AreEqual(4, dpu.getDpu()["contains"].getDpu(), "Incorrect DPU for contains");
            Assert.AreEqual(1, dpu.getDpu()["contains"].getTargets()["interaction.content"].getCount(), "Incorrect count for interaction.content");
            Assert.AreEqual(4, dpu.getDpu()["contains"].getTargets()["interaction.content"].getDpu(), "Incorrect DPU for interaction.content");
        }