Exemple #1
0
        public void ProcessResults_WithEmptyResults_ReturnsEmptyCollection()
        {
            var dmReqProc = new DirectMessageEventsRequestProcessor <DirectMessageEvents> {
                BaseUrl = "https://api.twitter.com/1.1/"
            };

            List <DirectMessageEvents> dms = dmReqProc.ProcessResults(string.Empty);

            Assert.IsFalse(dms.Any());
        }
Exemple #2
0
        public void ProcessResults_WithShowQuery_ReplacesInputParams()
        {
            const ulong ID = 5;

            var dmReqProc = new DirectMessageEventsRequestProcessor <DirectMessageEvents>
            {
                BaseUrl = "https://api.twitter.com/1.1/",
                Type    = DirectMessageEventsType.Show,
                ID      = ID
            };

            List <DirectMessageEvents> dms = dmReqProc.ProcessResults(TestQuerySingleResponse);

            DirectMessageEvents dm = dms.First();

            Assert.AreEqual(ID, dm.ID);
        }
Exemple #3
0
        public void ProcessResults_WithListQuery_ReplacesInputParams()
        {
            const int    Count  = 4;
            const string Cursor = "ABC123";

            var dmReqProc = new DirectMessageEventsRequestProcessor <DirectMessageEvents>
            {
                BaseUrl = "https://api.twitter.com/1.1/",
                Type    = DirectMessageEventsType.List,
                Count   = Count,
                Cursor  = Cursor
            };

            List <DirectMessageEvents> dms = dmReqProc.ProcessResults(TestQueryMultipleResponses);

            DirectMessageEvents dm = dms.First();

            Assert.AreEqual(Count, dm.Count);
            Assert.AreEqual(Cursor, dm.Cursor);
        }
Exemple #4
0
        public void ProcessResults_ForList_HandlesMultipleResults()
        {
            var dmReqProc = new DirectMessageEventsRequestProcessor <DirectMessageEvents>
            {
                BaseUrl = "https://api.twitter.com/1.1/",
                Type    = DirectMessageEventsType.List
            };

            List <DirectMessageEvents> dms = dmReqProc.ProcessResults(TestQueryMultipleResponses);

            Assert.IsNotNull(dms?.SingleOrDefault());

            DirectMessageEvents dmEvt = dms.First();

            Assert.IsNotNull(dmEvt);
            DirectMessageEventsValue dmVal = dmEvt.Value;

            Assert.IsNotNull(dmVal);
            List <DMEvent> evts = dmVal.DMEvents;

            Assert.IsNotNull(evts);
            Assert.AreEqual(2, evts.Count);
            Assert.AreEqual("OTE3ODE0NTUzMzExOTMyNDIy", dmVal.NextCursor);
        }
Exemple #5
0
        public void ProcessResults_ForShow_HandlesSingleResult()
        {
            var dmReqProc = new DirectMessageEventsRequestProcessor <DirectMessageEvents>
            {
                BaseUrl = "https://api.twitter.com/1.1/",
                Type    = DirectMessageEventsType.Show
            };

            List <DirectMessageEvents> dms = dmReqProc.ProcessResults(TestQuerySingleResponse);

            Assert.IsNotNull(dms?.SingleOrDefault());

            DirectMessageEvents dmEvt = dms.First();

            Assert.IsNotNull(dmEvt);
            DirectMessageEventsValue dmVal = dmEvt.Value;

            Assert.IsNotNull(dmVal);
            DMEvent evt = dmVal.DMEvent;

            Assert.IsNotNull(evt);
            Assert.AreEqual("message_create", evt.Type);
            Assert.AreEqual("917929712638246916", evt.ID);
            Assert.AreEqual("1507686472459", evt.CreatedTimestamp);
            Assert.AreEqual(new DateTime(2017, 10, 11, 01, 47, 52, 459), evt.CreatedAt);
            DirectMessageCreate mc = evt.MessageCreate;

            Assert.IsNotNull(mc);
            Assert.AreEqual("15411837", mc.SenderID);
            Assert.AreEqual("472356", mc.SourceAppID);
            DirectMessageTarget tgt = mc.Target;

            Assert.IsNotNull(tgt);
            Assert.AreEqual("16761255", tgt.RecipientID);
            DirectMessageData md = mc.MessageData;

            Assert.IsNotNull(md);
            Assert.AreEqual(
                "DM from @JoeMayo to @Linq2Twitr of $MSFT &amp; $TSLA with #TwitterAPI #chatbot at https://t.co/ikGq2AnAir and https://t.co/nLvwwjz40q on 10/10/2017 6:47:46 PM!'",
                md.Text);
            Entities ent = md.Entities;

            Assert.IsNotNull(ent);
            List <HashTagEntity> hashtags = ent.HashTagEntities;

            Assert.IsNotNull(hashtags);
            Assert.AreEqual(2, hashtags.Count);
            HashTagEntity ht1 = hashtags[0];

            Assert.IsNotNull(ht1);
            Assert.AreEqual("TwitterAPI", ht1.Text);
            int[] ht1i = ht1.Indices;
            Assert.IsNotNull(ht1i);
            Assert.AreEqual(58, ht1i[0]);
            Assert.AreEqual(69, ht1i[1]);
            HashTagEntity ht2 = hashtags[1];

            Assert.IsNotNull(ht2);
            Assert.AreEqual("chatbot", ht2.Text);
            int[] ht2i = ht2.Indices;
            Assert.IsNotNull(ht2i);
            Assert.AreEqual(70, ht2i[0]);
            Assert.AreEqual(78, ht2i[1]);
            List <SymbolEntity> syms = ent.SymbolEntities;

            Assert.IsNotNull(syms);
            Assert.AreEqual(2, syms.Count);
            SymbolEntity sym1 = syms[0];

            Assert.IsNotNull(sym1);
            Assert.AreEqual("MSFT", sym1.Text);
            int[] sym1i = sym1.Indices;
            Assert.IsNotNull(sym1i);
            Assert.AreEqual(35, sym1i[0]);
            Assert.AreEqual(40, sym1i[1]);
            SymbolEntity sym2 = syms[1];

            Assert.IsNotNull(sym2);
            Assert.AreEqual("TSLA", sym2.Text);
            int[] sym2i = sym2.Indices;
            Assert.IsNotNull(sym2i);
            Assert.AreEqual(47, sym2i[0]);
            Assert.AreEqual(52, sym2i[1]);
            List <UserMentionEntity> usrs = ent.UserMentionEntities;

            Assert.IsNotNull(usrs);
            Assert.AreEqual(2, usrs.Count);
            UserMentionEntity um1 = usrs[0];

            Assert.IsNotNull(um1);
            Assert.AreEqual("JoeMayo", um1.ScreenName);
            Assert.AreEqual("Joe Mayo", um1.Name);
            Assert.AreEqual(15411837ul, um1.Id);
            Assert.AreEqual("15411837", um1.IdStr);
            int[] um1i = um1.Indices;
            Assert.IsNotNull(um1i);
            Assert.AreEqual(2, um1i.Length);
            Assert.AreEqual(8, um1i[0]);
            Assert.AreEqual(16, um1i[1]);
            UserMentionEntity um2 = usrs[1];

            Assert.IsNotNull(um2);
            Assert.AreEqual("Linq2Twitr", um2.ScreenName);
            Assert.AreEqual("LINQ to Twitr", um2.Name);
            Assert.AreEqual(16761255ul, um2.Id);
            Assert.AreEqual("16761255", um2.IdStr);
            int[] um2i = um2.Indices;
            Assert.IsNotNull(um2i);
            Assert.AreEqual(2, um2i.Length);
            Assert.AreEqual(20, um2i[0]);
            Assert.AreEqual(31, um2i[1]);
            List <UrlEntity> urls = ent.UrlEntities;

            Assert.IsNotNull(urls);
            Assert.AreEqual(2, urls.Count);
            UrlEntity url1 = urls[0];

            Assert.IsNotNull(url1);
            Assert.AreEqual("https://t.co/ikGq2AnAir", url1.Url);
            Assert.AreEqual("http://bit.ly/2xSJWJk", url1.ExpandedUrl);
            Assert.AreEqual("bit.ly/2xSJWJk", url1.DisplayUrl);
            int[] url1i = url1.Indices;
            Assert.IsNotNull(url1i);
            Assert.AreEqual(2, url1i.Length);
            Assert.AreEqual(82, url1i[0]);
            Assert.AreEqual(105, url1i[1]);
            UrlEntity url2 = urls[1];

            Assert.IsNotNull(url2);
            Assert.AreEqual("https://t.co/nLvwwjz40q", url2.Url);
            Assert.AreEqual("http://amzn.to/2gD09X6", url2.ExpandedUrl);
            Assert.AreEqual("amzn.to/2gD09X6", url2.DisplayUrl);
            int[] url2i = url2.Indices;
            Assert.IsNotNull(url2i);
            Assert.AreEqual(2, url2i.Length);
            Assert.AreEqual(110, url2i[0]);
            Assert.AreEqual(133, url2i[1]);
            JsonElement app       = dmVal.Apps;
            JsonElement appDetail = app.GetProperty("472356");

            Assert.AreEqual("472356", appDetail.GetString("id"));
            Assert.AreEqual("LINQ to Tweeter", appDetail.GetString("name"));
            Assert.AreEqual("https://github.com/JoeMayo/LinqToTwitter", appDetail.GetString("url"));
        }