public async Task <bool> DoCombosTest(IUserSession session, List <int> testSeq)
        {
            var successStatus = true;
            var trendToFollow = "";

            try
            {
                // 1
                if (testSeq.Contains(1))
                {
                    //-33.884097,151.134796
                    ConsoleOutput.PrintMessage("11.1 Combo\\GetTrendsByLocation then Searchstream for 2 minutes", ConsoleColor.Gray);
                    var combo1 = await session.GetTrendsByLocation(latitude : -33.884097, longitude : 151.134796);

                    if (combo1.OK)
                    {
                        trendToFollow = combo1[0].Name; // grab the first
                        foreach (var trnd in combo1)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("Trend Test: {0}", trnd.Name));
                        }
                    }
                    else
                    {
                        successStatus = false;
                        throw new Exception("cannot trends");
                    }

                    var searchstream = session.StartSearchStream(track: trendToFollow);
                    searchstream.FoundTweets.Subscribe(t => ConsoleOutput.PrintTweet(t));
                    searchstream.Start();

                    Thread.Sleep(TimeSpan.FromMinutes(2));
                    searchstream.CancelStream.Cancel();
                    searchstream.Stop();
                }


                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("11.2 Combo\\GetFriendshipRequestsOutgoing, then hydrate User Details", ConsoleColor.Gray);

                    long nextcursor   = -1;
                    var  ff5ListCount = 0;
                    var  userids2     = new List <long>();

                    do
                    {
                        var ff2List = await session.GetFriendshipRequestsOutgoing(cursor : nextcursor);

                        if (ff2List.twitterFaulted)
                        {
                            successStatus = false;
                            break;
                        }
                        ;
                        nextcursor = ff2List.next_cursor;
                        ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}",
                                                                 ff2List.previous_cursor, ff2List.next_cursor));
                        foreach (var l in ff2List.UserIDs)
                        {
                            userids2.Add(l);
                            ff5ListCount++;
                            ConsoleOutput.PrintMessage(String.Format("User ID: {0}", l));
                        }
                    } while (nextcursor != 0);

                    ConsoleOutput.PrintMessage(String.Format("Total Outstanding Outgoing Friend Requests Count: {0}",
                                                             ff5ListCount));

                    if (userids2.Any())
                    {
                        var userlist2 = await session.GetUsersDetailsFull(userIds : userids2);

                        if (userlist2.OK)
                        {
                            foreach (var requsers in userlist2)
                            {
                                ConsoleOutput.PrintMessage(
                                    String.Format("UserID: {0} // ScreenName: {1}", requsers.UserId, requsers.ScreenName));
                            }
                        }
                        else
                        {
                            successStatus = false;
                        }
                    }
                }

                // 3
                if (testSeq.Contains(3))
                {
                    ConsoleOutput.PrintMessage("11.3 Combo\\GetFriendshipRequestsIncoming, then hydrate User Details", ConsoleColor.Gray);

                    long nextcursor   = -1;
                    var  ff5ListCount = 0;
                    var  userids3     = new List <long>();

                    do
                    {
                        var ff3List = await session.GetFriendshipRequestsIncoming(cursor : nextcursor);

                        if (ff3List.twitterFaulted)
                        {
                            successStatus = false;
                            break;
                        }
                        ;
                        nextcursor = ff3List.next_cursor;
                        ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}",
                                                                 ff3List.previous_cursor, ff3List.next_cursor));
                        foreach (var l in ff3List.UserIDs)
                        {
                            userids3.Add(l);
                            ff5ListCount++;
                            ConsoleOutput.PrintMessage(String.Format("User ID: {0}", l));
                        }
                    } while (nextcursor != 0);

                    ConsoleOutput.PrintMessage(String.Format("Total Outstanding Incoming Friend Requests Count: {0}",
                                                             ff5ListCount));

                    if (userids3.Any())
                    {
                        var userlist3 = await session.GetUsersDetailsFull(userIds : userids3);

                        if (userlist3.OK)
                        {
                            foreach (var requsers in userlist3)
                            {
                                ConsoleOutput.PrintMessage(
                                    String.Format("UserID: {0} // ScreenName: {1}", requsers.UserId, requsers.ScreenName));
                            }
                        }
                        else
                        {
                            successStatus = false;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }
Example #2
0
        public async Task <bool> DoFriendsFollowersTest(IUserSession session, List <int> testSeq)
        {
            var successStatus = true;

            try
            {
                // 1
                if (testSeq.Contains(1))
                {
                    ConsoleOutput.PrintMessage("6.1 FriendsFollowers\\GetFriendsIDs", ConsoleColor.Gray);

                    long nextcursor  = -1;
                    var  ffListCount = 0;

                    do
                    {
                        var ff1List = await session.GetFriendsIDs(cursor : nextcursor);

                        if (ff1List.twitterFaulted)
                        {
                            successStatus = false;
                            break;
                        }
                        ;
                        nextcursor = ff1List.next_cursor;
                        ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}",
                                                                 ff1List.previous_cursor, ff1List.next_cursor));
                        foreach (var l in ff1List.UserIDs)
                        {
                            ffListCount++;
                            ConsoleOutput.PrintMessage(String.Format("User ID: {0}", l));
                        }
                    } while (nextcursor != 0);

                    ConsoleOutput.PrintMessage(String.Format("Total Friends List Count: {0}",
                                                             ffListCount));
                }

                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("6.2 FriendsFollowers\\GetFollowersIDs", ConsoleColor.Gray);

                    long nextcursor   = -1;
                    var  ff2ListCount = 0;

                    do
                    {
                        var ff2List = await session.GetFollowersIDs(cursor : nextcursor);

                        if (ff2List.twitterFaulted)
                        {
                            successStatus = false;
                            break;
                        }
                        ;
                        nextcursor = ff2List.next_cursor;
                        ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}",
                                                                 ff2List.previous_cursor, ff2List.next_cursor));
                        foreach (var l in ff2List.UserIDs)
                        {
                            ff2ListCount++;
                            ConsoleOutput.PrintMessage(String.Format("User ID: {0}", l));
                        }
                    } while (nextcursor != 0);

                    ConsoleOutput.PrintMessage(String.Format("Total Followers List Count: {0}",
                                                             ff2ListCount));
                }

                // 3
                if (testSeq.Contains(3))
                {
                    ConsoleOutput.PrintMessage("6.3 FriendsFollowers\\GetFriendships", ConsoleColor.Gray);
                    var ff3 = await session.GetFriendships(new List <string> {
                        "katyperry", "shiftkey"
                    });

                    if (ff3.OK)
                    {
                        foreach (var t in ff3)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("Name: {0} // UserID: {1}", t.ScreenName, t.UserId));
                            foreach (var c in t.Connections)
                            {
                                ConsoleOutput.PrintMessage(
                                    String.Format("Connection: {0}", c.ToString()));
                            }
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }


                // 4
                if (testSeq.Contains(4))
                {
                    ConsoleOutput.PrintMessage("6.4 FriendsFollowers\\GetFriendshipRequestsIncoming", ConsoleColor.Gray);

                    long nextcursor   = -1;
                    var  ff4ListCount = 0;

                    do
                    {
                        var ff4List = await session.GetFriendshipRequestsIncoming(cursor : nextcursor);

                        if (ff4List.twitterFaulted)
                        {
                            successStatus = false;
                            break;
                        }
                        ;
                        nextcursor = ff4List.next_cursor;
                        ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}",
                                                                 ff4List.previous_cursor, ff4List.next_cursor));
                        foreach (var l in ff4List.UserIDs)
                        {
                            ff4ListCount++;
                            ConsoleOutput.PrintMessage(String.Format("User ID: {0}", l));
                        }
                    } while (nextcursor != 0);

                    ConsoleOutput.PrintMessage(String.Format("Total Followers List Count: {0}",
                                                             ff4ListCount));
                }

                // 5
                if (testSeq.Contains(5))
                {
                    ConsoleOutput.PrintMessage("6.5 FriendsFollowers\\GetFriendshipRequestsOutgoing", ConsoleColor.Gray);

                    long nextcursor   = -1;
                    var  ff5ListCount = 0;

                    do
                    {
                        var ff5List = await session.GetFriendshipRequestsOutgoing(cursor : nextcursor);

                        if (ff5List.twitterFaulted)
                        {
                            successStatus = false;
                            break;
                        }
                        ;
                        nextcursor = ff5List.next_cursor;
                        ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}",
                                                                 ff5List.previous_cursor, ff5List.next_cursor));
                        foreach (var l in ff5List.UserIDs)
                        {
                            ff5ListCount++;
                            ConsoleOutput.PrintMessage(String.Format("User ID: {0}", l));
                        }
                    } while (nextcursor != 0);

                    ConsoleOutput.PrintMessage(String.Format("Total Followers List Count: {0}",
                                                             ff5ListCount));
                }

                // 6
                if (testSeq.Contains(6))
                {
                    ConsoleOutput.PrintMessage("6.6 FriendsFollowers\\CreateFriendship", ConsoleColor.Gray);
                    var ff6 = await session.CreateFriendship("katyperry");

                    if (ff6.OK)
                    {
                        ConsoleOutput.PrintMessage(String.Format("Name: {0}", ff6.Name));
                        ConsoleOutput.PrintMessage(String.Format("User ID: {0}", ff6.UserId));
                        ConsoleOutput.PrintMessage(String.Format("Avatar URL: {0}", ff6.Avatar));
                        ConsoleOutput.PrintMessage(String.Format("Followers: {0}", ff6.Followers));
                        ConsoleOutput.PrintMessage(String.Format("Friends: {0}", ff6.Friends));
                        ConsoleOutput.PrintMessage(String.Format("Description: {0}", ff6.Description));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 7
                if (testSeq.Contains(7))
                {
                    ConsoleOutput.PrintMessage("6.7 FriendsFollowers\\DeleteFriendship", ConsoleColor.Gray);
                    var ff7 = await session.DeleteFriendship(user_id : 21447363);

                    if (ff7.OK)
                    {
                        ConsoleOutput.PrintMessage(String.Format("Name: {0}", ff7.Name));
                        ConsoleOutput.PrintMessage(String.Format("User ID: {0}", ff7.UserId));
                        ConsoleOutput.PrintMessage(String.Format("Avatar URL: {0}", ff7.Avatar));
                        ConsoleOutput.PrintMessage(String.Format("Followers: {0}", ff7.Followers));
                        ConsoleOutput.PrintMessage(String.Format("Friends: {0}", ff7.Friends));
                        ConsoleOutput.PrintMessage(String.Format("Description: {0}", ff7.Description));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }
        public async Task <bool> DoUserAccountTest(IUserSession session, List <int> testSeq)
        {
            var successStatus = true;

            try
            {
                // 1
                if (testSeq.Contains(1))
                {
                    ConsoleOutput.PrintMessage("1.1 UsersExtensions\\GetAccountSettings", ConsoleColor.Gray);
                    var accountSettings = await session.GetAccountSettings();

                    testScreenName = accountSettings.ScreenName;
                    if (accountSettings.OK && !string.IsNullOrWhiteSpace(testScreenName))
                    {
                        ConsoleOutput.PrintMessage(String.Format("Screen Name: {0}", testScreenName));
                        ConsoleOutput.PrintMessage(String.Format("Time Zone: {0}", accountSettings.TimeZone.name));
                        ConsoleOutput.PrintMessage(String.Format("Trend Location: {0}",
                                                                 accountSettings.TrendLocation.ToList()[0].name));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }
                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("1.2 UsersExtensions\\GetVerifyCredentials", ConsoleColor.Gray);
                    loggedInUserProfile = await session.GetVerifyCredentials();

                    if (loggedInUserProfile.OK)
                    {
                        ConsoleOutput.PrintMessage("Credentials Verified OK.");
                        ConsoleOutput.PrintMessage(String.Format("User ID Verified OK: {0}", loggedInUserProfile.UserId));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }
                // 3
                if (testSeq.Contains(3))
                {
                    ConsoleOutput.PrintMessage("1.3 UsersExtensions\\GetUserProfile", ConsoleColor.Gray);
                    var getProfile = await session.GetUserProfile(testScreenName);

                    if (getProfile.OK)
                    {
                        ConsoleOutput.PrintMessage(String.Format("Name: {0}", getProfile.Name));
                        ConsoleOutput.PrintMessage(String.Format("User ID: {0}", getProfile.UserId));
                        ConsoleOutput.PrintMessage(String.Format("Avatar URL: {0}", getProfile.Avatar));
                        ConsoleOutput.PrintMessage(String.Format("Followers: {0}", getProfile.Followers));
                        ConsoleOutput.PrintMessage(String.Format("Friends: {0}", getProfile.Friends));
                        ConsoleOutput.PrintMessage(String.Format("Description: {0}", getProfile.Description));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }
                // 4
                if (testSeq.Contains(4))
                {
                    ConsoleOutput.PrintMessage("1.4 UsersExtensions\\ChangeAccountSettings", ConsoleColor.Gray);
                    var changeSettings = await session.ChangeAccountSettings(trendLocationWoeid : "1");

                    if (changeSettings.OK)
                    {
                        ConsoleOutput.PrintMessage(String.Format("Trend Location: {0}",
                                                                 changeSettings.TrendLocation.ToList()[0].name));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }
                // 5
                if (testSeq.Contains(5))
                {
                    ConsoleOutput.PrintMessage("1.5 UsersExtensions\\GetBlockList - Cursored", ConsoleColor.Gray);
                    long nextcursor     = -1;
                    var  blockListCount = 0;

                    do
                    {
                        var blockList = await session.GetBlockList(cursor : nextcursor);

                        if (blockList.twitterFaulted)
                        {
                            continue;
                        }
                        nextcursor = blockList.next_cursor;
                        ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}",
                                                                 blockList.previous_cursor, blockList.next_cursor));
                        foreach (var l in blockList.users)
                        {
                            blockListCount++;
                            ConsoleOutput.PrintMessage(String.Format("ScreenName: {0} User ID: {1} Description: {2}",
                                                                     l.Name, l.UserId, l.Description));
                        }
                    } while (nextcursor != 0);

                    ConsoleOutput.PrintMessage(String.Format("Block List Count: {0}",
                                                             blockListCount));
                }
                // 6
                if (testSeq.Contains(6))
                {
                    ConsoleOutput.PrintMessage("1.6 UsersExtensions\\DeleteUserBlock", ConsoleColor.Gray);
                    var deleteUserBlock = await session.DeleteUserBlock(screenName : "NickHodgeMSFT");

                    if (deleteUserBlock.OK)
                    {
                        ConsoleOutput.PrintMessage(String.Format("ScreenName: {0}", deleteUserBlock.ScreenName));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }
                // 7
                if (testSeq.Contains(7))
                {
                    ConsoleOutput.PrintMessage("1.7 UsersExtensions\\GetUsersDetailsFull From Screennames ",
                                               ConsoleColor.Gray);
                    var screennames = new List <string> {
                        "shiftkey", "katyperry"
                    };
                    var getUserDetailsFullFromScreenNames = await session.GetUsersDetailsFull(screenNames : screennames);

                    if (getUserDetailsFullFromScreenNames.OK)
                    {
                        ConsoleOutput.PrintMessage(String.Format("Returned: {0}",
                                                                 getUserDetailsFullFromScreenNames.Count()));
                        foreach (var u in getUserDetailsFullFromScreenNames)
                        {
                            ConsoleOutput.PrintMessage(String.Format("User ID: {1} // ScreenName: {0} // Description: {2}",
                                                                     u.Name, u.UserId, u.Description));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }
                // 8
                if (testSeq.Contains(8))
                {
                    ConsoleOutput.PrintMessage("1.8 UsersExtensions\\GetUsersDetailsFull From IDs", ConsoleColor.Gray);
                    var usersids = new List <long> {
                        21447363, 14671135, 4503599627370241
                    };
                    var getUserDetailsFullFromIDs = await session.GetUsersDetailsFull(userIds : usersids);

                    if (getUserDetailsFullFromIDs.OK)
                    {
                        ConsoleOutput.PrintMessage(String.Format("Returned: {0}", getUserDetailsFullFromIDs.Count()));
                        foreach (var u in getUserDetailsFullFromIDs)
                        {
                            ConsoleOutput.PrintMessage(String.Format(
                                                           "ScreenName: {0} User ID: {1} Description: {2}",
                                                           u.Name, u.UserId, u.Description));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }
                // 9
                if (testSeq.Contains(9))
                {
                    ConsoleOutput.PrintMessage("1.9 UsersExtensions\\SearchForUsers", ConsoleColor.Gray);
                    var q = "troll";
                    var searchForUsers = await session.SearchForUsers(q, 200, 1);

                    if (searchForUsers.OK)
                    {
                        ConsoleOutput.PrintMessage(String.Format("Returned: {0}", searchForUsers.Count()));
                        foreach (var u in searchForUsers)
                        {
                            ConsoleOutput.PrintMessage(String.Format(
                                                           "ScreenName: {0} User ID: {1} Description: {2}",
                                                           u.Name, u.UserId, u.Description));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 10
                if (testSeq.Contains(10))
                {
                    ConsoleOutput.PrintMessage("1.10 Get GetConfiguration", ConsoleColor.Gray);
                    var configUser = await session.GetConfiguration();

                    if (configUser.OK)
                    {
                        ConsoleOutput.PrintMessage(String.Format("Returned for Max Media Per Upload: {0}", configUser.MaxMediaPerUpload));
                        ConsoleOutput.PrintMessage(String.Format("Returned for Max Chars for DM: {0}", configUser.DirectMessageCharacterLimit));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 11
                if (testSeq.Contains(11))
                {
                    ConsoleOutput.PrintMessage("1.11 Start ApplicationOnlyAuth", ConsoleColor.Gray);
                    var getAuthToken = await session.StartApplicationOnlyAuth();

                    if (getAuthToken)
                    {
                        ConsoleOutput.PrintMessage(String.Format("Returned: {0}", getAuthToken));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }
Example #4
0
        public async Task <bool> DoDMTest(IUserSession session, List <int> testSeq)
        {
            var successStatus = true;

            try
            {
                // 1
                long dmid = 0;
                if (testSeq.Contains(1))
                {
                    ConsoleOutput.PrintMessage("3.1 DirectMessages\\GetDirectMessages", ConsoleColor.Gray);
                    var directmessages1 = await session.GetDirectMessages();

                    if (directmessages1.OK)
                    {
                        dmid = directmessages1.ToList()[0].Id;
                        foreach (var x in directmessages1)
                        {
                            ConsoleOutput.PrintMessage(
                                string.Format("ID: {2} // From: {0} // Message: {1}", x.SenderScreenName, x.Text, x.Id));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("3.2 DirectMessages\\GetDirectMessagesSent", ConsoleColor.Gray);
                    var directmessages2 = await session.GetDirectMessagesSent();

                    if (directmessages2.OK)
                    {
                        foreach (var x in directmessages2)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("To: {0} // Message: {1}", x.Recipient.ScreenName, x.Text));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 3
                if (testSeq.Contains(3))
                {
                    ConsoleOutput.PrintMessage("3.3 DirectMessages\\GetDirectMessageSingle", ConsoleColor.Gray);
                    var directmessages3 = await session.GetDirectMessageSingle(dmid);

                    if (directmessages3.OK)
                    {
                        ConsoleOutput.PrintMessage(
                            String.Format("From: {0} // Message: {1}", directmessages3.SenderScreenName, directmessages3.Text));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 4
                if (testSeq.Contains(4))
                {
                    ConsoleOutput.PrintMessage("3.4 DirectMessages\\SendDirectMessage", ConsoleColor.Gray);
                    var directmessages4 =
                        await session.SendDirectMessage("livefire test of boxkite.twitter please ignore", "nickhodgeau");

                    if (directmessages4.OK)
                    {
                        ConsoleOutput.PrintMessage(
                            String.Format("From: {0} // Message: {1}", directmessages4.SenderScreenName, directmessages4.Text));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 5
                if (testSeq.Contains(5))
                {
                    ConsoleOutput.PrintMessage("3.5 DirectMessages\\SendDirectMessage > 140 chars", ConsoleColor.Gray);

                    var directmessage5contents = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";

                    var directmessages5 =
                        await session.SendDirectMessage("realnickhodge", directmessage5contents);

                    if (directmessages5.OK)
                    {
                        ConsoleOutput.PrintMessage(
                            String.Format("From: {0} // Length: {1} // Message: {2}", directmessages5.SenderScreenName,
                                          directmessage5contents.Length, directmessages5.Text));
                    }
                    else
                    {
                        ConsoleOutput.PrintError(
                            String.Format("Error: {0}", directmessages5.twitterControlMessage.twitter_error_message));
                        successStatus = false;
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }
        public async Task <bool> DoFavouritesTest(IUserSession session, List <int> testSeq)
        {
            var successStatus = true;

            try
            {
                // 1
                if (testSeq.Contains(1))
                {
                    ConsoleOutput.PrintMessage("5.1 Favourites\\GetFavourites", ConsoleColor.Gray);
                    var favourites1 = await session.GetFavourites(count : 50);

                    if (favourites1.OK)
                    {
                        foreach (var t in favourites1)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", t.User.ScreenName, t.Text));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("4.2 Favourites\\CreateFavourite", ConsoleColor.Gray);

                    var tweettofav = await session.GetTweet(336452534531137537);

                    var favourites2 = await session.CreateFavourite(tweettofav);

                    if (favourites2.OK)
                    {
                        ConsoleOutput.PrintMessage(
                            String.Format("From: {0} // Favourited Status: {1}", favourites2.User.ScreenName, favourites2.Favourited));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 3
                if (testSeq.Contains(3))
                {
                    ConsoleOutput.PrintMessage("4.3 Favourites\\DeleteFavourite", ConsoleColor.Gray);

                    var tweettofav = await session.GetTweet(336452534531137537);

                    var favourites3 = await session.DeleteFavourite(tweettofav);

                    if (favourites3.OK)
                    {
                        ConsoleOutput.PrintMessage(
                            String.Format("From: {0} // Favourited Status: {1}", favourites3.User.ScreenName, favourites3.Favourited));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }
        public async Task <bool> DoTimelineTest(IUserSession session, List <int> testSeq)
        {
            var successStatus = true;

            try
            {
                // 1
                if (testSeq.Contains(1))
                {
                    ConsoleOutput.PrintMessage("7.1 Timeline\\GetMentions", ConsoleColor.Gray);
                    var timeline1 = await session.GetMentions(count : 100);

                    if (timeline1.OK)
                    {
                        foreach (var tweet in timeline1)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweet.User.ScreenName, tweet.Text));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("7.2 Timeline\\GetUserTimeline", ConsoleColor.Gray);
                    var timeline2 = await session.GetUserTimeline(screenName : "shiftkey", count : 20);

                    if (timeline2.OK)
                    {
                        foreach (var tweet in timeline2)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweet.User.ScreenName, tweet.Text));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }


                // 3
                if (testSeq.Contains(3))
                {
                    ConsoleOutput.PrintMessage("7.3 Timeline\\GetHomeTimeline", ConsoleColor.Gray);
                    var timeline3 = await session.GetHomeTimeline(count : 30);

                    if (timeline3.OK)
                    {
                        foreach (var tweet in timeline3)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweet.User.ScreenName, tweet.Text));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }


                // 4
                if (testSeq.Contains(4))
                {
                    ConsoleOutput.PrintMessage(
                        "7.4 Timeline\\GetHomeTimeline - Paging Forward, getting new tweets, with ID mechanism",
                        ConsoleColor.Gray);
                    var timeline4 = await session.GetHomeTimeline(count : 10);

                    long largestid  = 0;
                    long smallestid = 0;

                    if (timeline4.OK)
                    {
                        smallestid = timeline4.ToList()[0].Id;
                        foreach (var tweet in timeline4)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("ID: {0} // From: {1} // Message: {2}", tweet.Id, tweet.User.ScreenName,
                                              tweet.Text));
                            if (tweet.Id > largestid)
                            {
                                largestid = tweet.Id;
                            }
                            if (tweet.Id < smallestid)
                            {
                                smallestid = tweet.Id;
                            }
                        }
                        ConsoleOutput.PrintMessage(
                            String.Format(" LargestID: {0} // SmallestID: {1}", largestid, smallestid));

                        ConsoleOutput.PrintMessage("Waiting 20 seconds");
                        await Task.Delay(TimeSpan.FromSeconds(20));

                        ConsoleOutput.PrintMessage("Now Updating Home Timeline, should add newer messages");
                        var timeline41 = await session.GetHomeTimeline(sinceId : largestid, count : 10);

                        if (timeline41.OK)
                        {
                            foreach (var tweet in timeline41)
                            {
                                ConsoleOutput.PrintMessage(
                                    String.Format("ID: {0} // From: {1} // Message: {2}", tweet.Id,
                                                  tweet.User.ScreenName, tweet.Text));
                                if (tweet.Id > largestid)
                                {
                                    largestid = tweet.Id;
                                }
                                if (tweet.Id < smallestid)
                                {
                                    smallestid = tweet.Id;
                                }
                            }
                        }

                        ConsoleOutput.PrintMessage(
                            String.Format(" LargestID: {0} // SmallestID: {1}", largestid, smallestid));


                        ConsoleOutput.PrintMessage("Now Updating Home Timeline, should show older messages");
                        var timeline42 = await session.GetHomeTimeline(maxId : smallestid, count : 10);

                        if (timeline42.OK)
                        {
                            foreach (var tweet in timeline42)
                            {
                                ConsoleOutput.PrintMessage(
                                    String.Format("ID: {0} // From: {1} // Message: {2}", tweet.Id,
                                                  tweet.User.ScreenName, tweet.Text));
                                if (tweet.Id > largestid)
                                {
                                    largestid = tweet.Id;
                                }
                                if (tweet.Id < smallestid)
                                {
                                    smallestid = tweet.Id;
                                }
                            }
                        }

                        else
                        {
                            successStatus = false;
                        }
                    }
                }
                // 5
                if (testSeq.Contains(5))
                {
                    ConsoleOutput.PrintMessage("7.5 Timeline\\GetRetweetsOfMe", ConsoleColor.Gray);
                    var timeline5 = await session.GetRetweetsOfMe(count : 30);

                    if (timeline5.OK)
                    {
                        foreach (var tweet in timeline5)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweet.User.ScreenName, tweet.Text));
                        }
                    }

                    else
                    {
                        successStatus = false;
                    }
                }


                // 6
                if (testSeq.Contains(6))
                {
                    ConsoleOutput.PrintMessage(
                        "7.6 Timeline\\GetHomeTimeline - Paging Backward, getting older tweets with ID mechanism",
                        ConsoleColor.Gray);

                    long smallestid   = 0;
                    long largestid    = 0;
                    int  howManyToGet = 100;
                    int  pagingSize   = 10;

                    do
                    {
                        var timeline6 = await session.GetHomeTimeline(count : pagingSize, maxId : smallestid);

                        if (timeline6.OK)
                        {
                            smallestid = timeline6.ToList()[0].Id; // grab the first for comparator
                            foreach (var tweet in timeline6)
                            {
                                ConsoleOutput.PrintMessage(
                                    String.Format("ID: {0} // From: {1} // Message: {2}", tweet.Id,
                                                  tweet.User.ScreenName,
                                                  tweet.Text));
                                if (tweet.Id < smallestid)
                                {
                                    smallestid = tweet.Id;
                                }
                                if (tweet.Id > largestid)
                                {
                                    largestid = tweet.Id;
                                }
                                howManyToGet--;
                            }
                            ConsoleOutput.PrintMessage(
                                String.Format("SmallestID: {0}", smallestid),
                                ConsoleColor.Cyan);
                        }
                        else
                        {
                            successStatus = false;
                            TwitterLiveFireUserAuth.PrintTwitterErrors(timeline6.twitterControlMessage);
                            break;
                        }
                    } while (howManyToGet > 0);
                }
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }
        public async Task <bool> DoListsTest(IUserSession session, List <int> testSeq)
        {
            var successStatus = true;
            var twList        = new TwitterList();

            try
            {
                // 1
                if (testSeq.Contains(1))
                {
                    ConsoleOutput.PrintMessage("10.1 Lists\\GetLists", ConsoleColor.Gray);

                    var lists1 = await session.GetLists(screenName : "NickHodgeMSFT");

                    if (lists1.OK)
                    {
                        foreach (var lst in lists1)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("ID: {5} // Slug: {0} // Name: {1} // {2} // {3} // {4}", lst.Slug, lst.Name, lst.CreatedTime, lst.MemberCount, lst.Mode, lst.Id));
                            twList = lst;
                        }
                    }
                    else
                    {
                        TwitterLiveFireUserAuth.PrintTwitterErrors(lists1.twitterControlMessage);
                        successStatus = false;
                    }
                }

                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("10.2 Lists\\GetListTimeline", ConsoleColor.Gray);

                    var lists2 = await session.GetListTimeline(listId : twList.Id, slug : twList.Slug);

                    if (lists2.OK)
                    {
                        foreach (var tweet in lists2)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweet.User.ScreenName, tweet.Text));
                        }
                    }
                    else
                    {
                        TwitterLiveFireUserAuth.PrintTwitterErrors(lists2.twitterControlMessage);
                        successStatus = false;
                    }
                }

                // 3
                if (testSeq.Contains(3))
                {
                    ConsoleOutput.PrintMessage("10.3 Lists\\GetMyListsUserIsMemberOf - Cursored", ConsoleColor.Gray);

                    long nextcursor = -1;
                    var  listCount  = 0;

                    do
                    {
                        var lists3 =
                            await session.GetMyListsUserIsMemberOf(screenName : "shiftkey", cursor : nextcursor);

                        if (lists3.twitterFaulted)
                        {
                            TwitterLiveFireUserAuth.PrintTwitterErrors(lists3.twitterControlMessage);
                            successStatus = false;
                            break;
                        }
                        nextcursor = lists3.next_cursor;
                        ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}",
                                                                 lists3.previous_cursor, lists3.next_cursor), ConsoleColor.Magenta);
                        foreach (var lst in lists3.lists)
                        {
                            listCount++;
                            ConsoleOutput.PrintMessage(
                                String.Format("ID: {5} // Slug: {0} // Name: {1} // {2} // {3} // {4}", lst.Slug, lst.Name, lst.CreatedTime, lst.MemberCount, lst.Mode, lst.Id));
                        }
                    } while (nextcursor != 0);

                    ConsoleOutput.PrintMessage(String.Format("List Membership Count: {0}",
                                                             listCount));
                }


                // 4
                if (testSeq.Contains(4))
                {
                    ConsoleOutput.PrintMessage("10.4 Lists\\GetMembersOnList - Cursored", ConsoleColor.Gray);

                    long nextcursor = -1;

                    do
                    {
                        var lists4 =
                            await session.GetMembersOnList(listId : 52908745, slug : "autechheads", ownerId : 800364, ownerScreenName : "NickHodgeMSFT", cursor : nextcursor);

                        if (lists4.twitterFaulted)
                        {
                            successStatus = false;
                            TwitterLiveFireUserAuth.PrintTwitterErrors(lists4.twitterControlMessage);
                            break;
                        }
                        nextcursor = lists4.next_cursor;
                        ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}",
                                                                 lists4.previous_cursor, lists4.next_cursor), ConsoleColor.Magenta);
                        foreach (var lusr in lists4.users)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("UserID: {0} // ScreenName: {1}", lusr.UserId, lusr.ScreenName));
                        }
                    } while (nextcursor != 0);
                }


                // 5
                if (testSeq.Contains(5))
                {
                    ConsoleOutput.PrintMessage("10.5 Lists\\IsUserOnList", ConsoleColor.Gray);
                    var testScreenName = "coatsy";
                    var lists5         =
                        await session.IsUserOnList(screenName : testScreenName, listId : 52908745, ownerId : 800364, ownerScreenName : "NickHodgeMSFT");

                    if (lists5.OK)
                    {
                        if (lists5.ScreenName == null)
                        {
                            ConsoleOutput.PrintMessage(String.Format("UserID: {0} is NOT ON the list", testScreenName));
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("ScreenName: {0} is on the list", lists5.ScreenName));
                        }
                    }
                    else
                    {
                        TwitterLiveFireUserAuth.PrintTwitterErrors(lists5.twitterControlMessage);
                        successStatus = false;
                    }
                }

                // 6
                if (testSeq.Contains(6))
                {
                    ConsoleOutput.PrintMessage("10.6 Lists\\AddUserToMyList", ConsoleColor.Gray);
                    var testScreenName = "shiftkey";
                    var lists6         =
                        await session.AddUserToMyList(listId : 52908745, userIdToAdd : 14671135, screenNameToAdd : "shiftkey");

                    if (lists6.Status)
                    {
                        ConsoleOutput.PrintMessage(String.Format("ScreenName: {0} is added the list", testScreenName));
                    }
                }


                // 7
                if (testSeq.Contains(7))
                {
                    ConsoleOutput.PrintMessage("10.7 Lists\\DeleteUsersFromList", ConsoleColor.Gray);
                    var testScreenName  = "coatsy";
                    var testScreenNames = new List <string> {
                        testScreenName
                    };

                    var lists7 =
                        await session.DeleteUsersFromList(listId : 52908745, ownerId : 800364, ownerScreenName : "NickHodgeMSFT", screenNames : testScreenNames);

                    if (lists7.Status)
                    {
                        ConsoleOutput.PrintMessage(String.Format("ScreenName: {0} is added the list", testScreenName));
                    }
                    else
                    {
                        TwitterLiveFireUserAuth.PrintTwitterErrors(lists7.twitterControlMessage);
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }
Example #8
0
        public static void Main(string[] args)
        {
            ConsoleOutput.PrintMessage("BoxKite.Twitter Live Fire Tests (User Auth)");
            ConsoleOutput.PrintMessage("(control-c ends at anytime)");

            var twittercredentials = ManageTwitterCredentials.GetTwitterCredentialsFromFile();

            if (twittercredentials.Valid)
            {
                System.Console.CancelKeyPress += cancelStreamHandler;
                var session   = new UserSession(twittercredentials, new DesktopPlatformAdaptor());
                var checkUser = session.GetVerifyCredentials().Result;
                if (checkUser.OK)
                {
                    ConsoleOutput.PrintMessage(twittercredentials.ScreenName + " is authorised to use BoxKite.Twitter.");

                    // put the test series number you wish to run into the init of the array
                    // then in each test group, put the numbers of the tests you would like to run
                    // NOTE: some tests require a previous test to work successfully
                    // NOTE: some tests post/delete items. This *is* a live fire test!

                    var testSeriesToRun = new List <int> {
                        1
                    };

                    // Calls tested by Test Series
                    // series 1 => 11 (UserAccounts & Auth)
                    // series 2 => 1 (API Management)
                    // series 3 => 5 (Direct Messages)
                    // series 4 => 5 (Tweets)
                    // series 5 => 3 (Favourites)
                    // series 6 => 8 (Friends/Followers)
                    // series 7 => 6 (TimeLine)
                    // series 8 => 3 (Trends)
                    // series 9 => 2 (SuggestedUsers)
                    // series 10=> 7 (Lists)
                    // series 11=> 3 (Combos)
                    // =============
                    // TOTAL      54

                    // Test Series 1
                    if (testSeriesToRun.Contains(1))
                    {
                        var ualft       = new UserAccountLiveFireTests();
                        var testResult1 = ualft.DoUserAccountTest(session, new List <int> {
                            10
                        }).Result;

                        if (testResult1)
                        {
                            ConsoleOutput.PrintMessage(String.Format("1.0 User Account Tests Status: {0}", testResult1),
                                                       ConsoleColor.White);
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("1.0 User Account Tests Status: {0}", testResult1),
                                                       ConsoleColor.Red);
                        }
                    }


                    // Test Series 2
                    if (testSeriesToRun.Contains(2))
                    {
                        var doit        = new ApiManagementLiveFireTests();
                        var testResult2 = doit.DoApiTest(session, new List <int> {
                            1, 2
                        }).Result;

                        if (testResult2)
                        {
                            ConsoleOutput.PrintMessage(String.Format("2.0 API Management Tests Status: {0}", testResult2),
                                                       ConsoleColor.White);
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("2.0 API Management Tests Status: {0}", testResult2),
                                                       ConsoleColor.Red);
                        }
                    }

                    // Test Series 3
                    if (testSeriesToRun.Contains(3))
                    {
                        var dms         = new DirectMessagesLiveFireTests();
                        var testResult3 = dms.DoDMTest(session, new List <int> {
                            5
                        }).Result;

                        if (testResult3)
                        {
                            ConsoleOutput.PrintMessage(String.Format("3.0 Direct Messages Tests Status: {0}", testResult3),
                                                       ConsoleColor.White);
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("3.0 Direct Messages Tests Status: {0}", testResult3),
                                                       ConsoleColor.Red);
                        }
                    }


                    // Test Series 4
                    if (testSeriesToRun.Contains(4))
                    {
                        var tws         = new TweetsLiveFireTests();
                        var testResult4 = tws.DoTweetTest(session, new List <int> {
                            5
                        }).Result;

                        if (testResult4)
                        {
                            ConsoleOutput.PrintMessage(String.Format("4.0 Tweet Tests Status: {0}", testResult4),
                                                       ConsoleColor.White);
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("4.0 Tweet Tests Status: {0}", testResult4),
                                                       ConsoleColor.Red);
                        }
                    }

                    // Test Series 5
                    if (testSeriesToRun.Contains(5))
                    {
                        var fvs         = new FavouritesLiveFireTests();
                        var testResult5 = fvs.DoFavouritesTest(session, new List <int> {
                            1, 2, 3
                        }).Result;

                        if (testResult5)
                        {
                            ConsoleOutput.PrintMessage(String.Format("5.0 Favourite Tests Status: {0}", testResult5),
                                                       ConsoleColor.White);
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("5.0 Favourite Tests Status: {0}", testResult5),
                                                       ConsoleColor.Red);
                        }
                    }


                    // Test Series 6
                    if (testSeriesToRun.Contains(6))
                    {
                        var ffvs        = new FriendsFollowersLiveFireTests();
                        var testResult6 = ffvs.DoFriendsFollowersTest(session, new List <int> {
                            4, 5
                        }).Result;

                        if (testResult6)
                        {
                            ConsoleOutput.PrintMessage(String.Format("6.0 FriendsFollowers Tests Status: {0}", testResult6),
                                                       ConsoleColor.White);
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("6.0 FriendsFollowers Tests Status: {0}", testResult6),
                                                       ConsoleColor.Red);
                        }
                    }

                    // Test Series 7
                    if (testSeriesToRun.Contains(7))
                    {
                        var tmln        = new TimelineLiveFireTests();
                        var testResult7 = tmln.DoTimelineTest(session, new List <int> {
                            6
                        }).Result;

                        if (testResult7)
                        {
                            ConsoleOutput.PrintMessage(String.Format("7.0 Timeline Tests Status: {0}", testResult7),
                                                       ConsoleColor.White);
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("7.0 Timeline Tests Status: {0}", testResult7),
                                                       ConsoleColor.Red);
                        }
                    }


                    // Test Series 8(also tests SearchFor in SearchExtensions)
                    if (testSeriesToRun.Contains(8))
                    {
                        var trln        = new TrendsLiveFireTests();
                        var testResult8 = trln.DoTrendsTest(session, new List <int> {
                            4, 5
                        }).Result;

                        if (testResult8)
                        {
                            ConsoleOutput.PrintMessage(String.Format("8.0 Trends (and SearchFor) Tests Status: {0}", testResult8),
                                                       ConsoleColor.White);
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("8.0 Trends (and SearchFor) Tests Status: {0}", testResult8),
                                                       ConsoleColor.Red);
                        }
                    }


                    // Test Series 9(also tests SearchFor in SearchExtensions)
                    if (testSeriesToRun.Contains(9))
                    {
                        var trln        = new SuggestedUsersLiveFireTests();
                        var testResult9 = trln.DoSuggestedUsersTest(session, new List <int> {
                            1, 2
                        }).Result;

                        if (testResult9)
                        {
                            ConsoleOutput.PrintMessage(String.Format("9.0 SuggestedUsers Tests Status: {0}", testResult9),
                                                       ConsoleColor.White);
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("9.0 SuggestedUsers Tests Status: {0}", testResult9),
                                                       ConsoleColor.Red);
                        }
                    }


                    // Test Series 10 Lists
                    if (testSeriesToRun.Contains(10))
                    {
                        var lsts         = new ListsLiveFireTests();
                        var testResult10 = lsts.DoListsTest(session, new List <int> {
                            1, 5, 7
                        }).Result;

                        if (testResult10)
                        {
                            ConsoleOutput.PrintMessage(String.Format("10.0 Lists Tests Status: {0}", testResult10),
                                                       ConsoleColor.White);
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("10.0 Lists Tests Status: {0}", testResult10),
                                                       ConsoleColor.Red);
                        }
                    }


                    // Test Series 11 Lists
                    if (testSeriesToRun.Contains(11))
                    {
                        var cmbs         = new CombosFireTests();
                        var testResult11 = cmbs.DoCombosTest(session, new List <int> {
                            2, 3
                        }).Result;

                        if (testResult11)
                        {
                            ConsoleOutput.PrintMessage(String.Format("11.0 Combos Tests Status: {0}", testResult11),
                                                       ConsoleColor.White);
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("11.0 Combos Tests Status: {0}", testResult11),
                                                       ConsoleColor.Red);
                        }
                    }
                }
                else
                {
                    ConsoleOutput.PrintError("Unable to Authorise.");
                }
            }
            ConsoleOutput.PrintMessage("Press Return to close window");
            System.Console.ReadLine();
        }
Example #9
0
        public async Task <bool> DoTrendsTest(IUserSession session, List <int> testSeq)
        {
            var successStatus = true;
            var trendToSearch = "";
            int woeidToSearch = 1;

            try
            {
                // 1
                if (testSeq.Contains(1))
                {
                    //-33.884097,151.134796
                    ConsoleOutput.PrintMessage("8.1 Trends\\GetTrendsByLocation", ConsoleColor.Gray);
                    var trends1 = await session.GetTrendsByLocation(latitude : -33.884097, longitude : 151.134796);

                    if (trends1.OK)
                    {
                        foreach (var trnd in trends1)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("Name: {0} // Url: {1}", trnd.Name, trnd.Url));
                            woeidToSearch = trnd.WOEID;
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }


                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("8.2 Trends\\GetTrendsForPlace as specified in location", ConsoleColor.Gray);
                    var trends2 = await session.GetTrendsForPlace(placeId : woeidToSearch);

                    if (trends2.OK)
                    {
                        foreach (var trnd in trends2.ToList()[0].trends)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("Trend: {0} // Query: {1}", trnd.name, trnd.query));
                            trendToSearch = trnd.query;
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }

                    ConsoleOutput.PrintMessage("8.2.1 Search\\SearchFor from Trend", ConsoleColor.Gray);
                    var trends21 = await session.SearchFor(trendToSearch, SearchResultType.Popular, count : 20);

                    if (trends21.OK)
                    {
                        foreach (var tweet in trends21.Tweets)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweet.User.ScreenName, tweet.Text));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }
        public async Task <bool> DoTweetTest(IUserSession session, List <int> testSeq)
        {
            var successStatus = true;

            try
            {
                // 1
                long tweetid = 0;
                if (testSeq.Contains(1))
                {
                    ConsoleOutput.PrintMessage("4.1 Tweets\\SendTweet", ConsoleColor.Gray);
                    var tweets1 = await session.SendTweet("Live Fire Test only, please ignore");

                    if (tweets1.OK)
                    {
                        tweetid = tweets1.Id;
                        ConsoleOutput.PrintMessage(
                            String.Format("From: {0} // Message: {1}", tweets1.User.ScreenName, tweets1.Text));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                var tweets2 = new Tweet();

                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("4.2 Tweets\\GetTweet", ConsoleColor.Gray);
                    tweets2 = await session.GetTweet(336377569098207233);

                    if (tweets2.OK)
                    {
                        ConsoleOutput.PrintMessage(
                            String.Format("From: {0} // Message: {1}", tweets2.User.ScreenName, tweets2.Text));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 3
                if (testSeq.Contains(3))
                {
                    ConsoleOutput.PrintMessage("4.3 Tweets\\GetRetweets", ConsoleColor.Gray);
                    var tweets3 = await session.GetRetweets(tweets2);

                    if (tweets3.OK)
                    {
                        foreach (var t in tweets3)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", t.User.ScreenName, t.Text));
                        }
                    }
                    else
                    {
                        successStatus = false;
                    }
                }

                // 4
                if (testSeq.Contains(4))
                {
                    ConsoleOutput.PrintMessage("4.4 Tweets\\SendTweetWithImage", ConsoleColor.Gray);

                    var sr = FilesHelper.FromFile("sampleimage\\Boxkite-Logo-github.jpg");

                    using (var fs = new FileStream(sr, FileMode.Open, FileAccess.Read))
                    {
                        var tweets4 =
                            await
                            session.SendTweetWithImage("Live Fire Test only, please ignore", Path.GetFileName(sr), fs);

                        if (tweets4.OK)
                        {
                            tweetid = tweets4.Id;
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweets4.User.ScreenName, tweets4.Text));
                        }
                        else
                        {
                            TwitterLiveFireUserAuth.PrintTwitterErrors(tweets4.twitterControlMessage);
                            successStatus = false;
                        }
                    }
                }

                // 5
                if (testSeq.Contains(5))
                {
                    ConsoleOutput.PrintMessage("4.5 Tweets\\GetTweet - with Extended Entities", ConsoleColor.Gray);
                    var tweets5 = await session.GetTweet(560049149836808192);

                    if (tweets5.OK)
                    {
                        ConsoleOutput.PrintMessage(
                            String.Format("From: {0} // Message: {1}", tweets5.User.ScreenName, tweets5.Text));
                        ConsoleOutput.PrintMessage(
                            String.Format("Extended Entities Count: {0}", tweets5.ExtendedEntities.Urls.Count()));
                    }
                    else
                    {
                        successStatus = false;
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }
Example #11
0
 private static void cancelStreamHandler(object sender, ConsoleCancelEventArgs e)
 {
     ConsoleOutput.PrintMessage("All finished.", ConsoleColor.Blue);
     Thread.Sleep(TimeSpan.FromSeconds(1.3));
 }
Example #12
0
        private static void Main(string[] args)
        {
            ConsoleOutput.PrintMessage("Welcome to BoxKite.Twitter Console");
            ConsoleOutput.PrintMessage("(control-c ends)");
            System.Console.CancelKeyPress += cancelStreamHandler;

            var twittercredentials = ManageTwitterCredentials.GetTwitterCredentialsFromFile();

            if (twittercredentials == null)
            {
                // there are no Credentials on file, so create a new set
                // first, get the Twitter Client (also known as Consumer) Key and Secret from my service
                var twitterClientKeys = ClientKeyManager.GetTwitterClientKeys().Result;

                // make a new connection
                twitterConnection = new TwitterConnection(twitterClientKeys.Item1, twitterClientKeys.Item2);

                // PIN based authentication
                var oauth = twitterConnection.BeginUserAuthentication().Result;

                // if the response is null, something is wrong with the initial request to OAuth
                if (!string.IsNullOrWhiteSpace(oauth))
                {
                    ConsoleOutput.PrintMessage("Pin: ");
                    var pin = System.Console.ReadLine();
                    twittercredentials = twitterConnection.CompleteUserAuthentication(pin, oauth).Result;

                    ManageTwitterCredentials.SaveTwitterCredentialsToFile(twittercredentials);
                }
                else
                {
                    ConsoleOutput.PrintError("Cannot OAuth with Twitter");
                }
            }


            if (twittercredentials != null)
            {
                twitterConnection = new TwitterConnection(twittercredentials);

                twitterConnection.StartUserStreaming();

                ConsoleOutput.PrintMessage(twitterConnection.TwitterCredentials.ScreenName +
                                           " is authorised to use BoxKite.Twitter.");

                var usersession        = twitterConnection.UserSession;
                var userstream         = twitterConnection.UserStream;
                var applicationsession = twitterConnection.ApplicationSession;
                var searchstream       = twitterConnection.SearchStream;

                // userstream.Tweets.Subscribe( t => ConsoleOutput.PrintTweet(t));

                //userstream.Events.Subscribe(e => ConsoleOutput.PrintEvent(e, ConsoleColor.Yellow));
                //userstream.DirectMessages.Subscribe(C:\Users\nhodge\Documents\GitHub\BoxKite.Twitter\src\BoxKite.Twitter\SearchStream.cs
                //    d => ConsoleOutput.PrintDirect(d, ConsoleColor.Magenta, ConsoleColor.Black));
                //userstream.Start();

                //while (userstream.IsActive)
                //{
                //    Thread.Sleep(TimeSpan.FromSeconds(0.5));
                //}



                /*var x = session.SendTweet("d realnickhodge testing & ampersands");
                 *
                 *      if (x.IsFaulted)
                 *      {
                 *          ConsoleOutput.PrintMessage("bugger");
                 *      }
                 *
                 */



                //var locations = new List<string> { "150.700493", "-34.081953", "151.284828", "-33.593316" };
                // var locations = new List<string> { "-180", "-90", "180", "90" };
                // var track = new List<string> { "mh370" };


                twitterConnection.TimeLine.Subscribe(t =>
                {
                    ConsoleOutput.PrintTweet(t, ConsoleColor.Green);
                });
                twitterConnection.Mentions.Subscribe(
                    t => ConsoleOutput.PrintTweet(t, ConsoleColor.White, ConsoleColor.DarkGray));

                //twitterConnection.SearchTimeLine.Subscribe(t => { ConsoleOutput.PrintTweet(t, ConsoleColor.Cyan); });

                //twitterConnection.StartSearchStreaming("angeles");

                while (true)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(0.5));
                }

                /*
                 * twitterConnection.StartSearch("mh370");
                 * var xx = session.GetUserProfile(screen_name:"nickhodgemsft").Result;
                 *
                 * if (xx.twitterFaulted)
                 * {
                 * PrintTwitterErrors(xx.twitterControlMessage);
                 * }
                 * else
                 * {
                 * ConsoleOutput.PrintMessage(xx.ToString());
                 * }
                 *
                 *
                 *
                 * var fileName = "sampleimage\\boxkite1500x500.png";
                 *
                 * if (File.Exists(fileName))
                 * {
                 * // var newImage = File.ReadAllBytes(fileName);
                 *
                 * var sr = FilesHelper.FromFile(fileName);
                 *
                 * // var x = session.SendTweetWithImage("Testing Image Upload. You can Ignore", Path.GetFileName(fileName),newImage).Result;
                 *
                 * using (var fs = new FileStream(sr, FileMode.Open, FileAccess.Read))
                 * {
                 *
                 *     var x = session.ChangeProfileBanner("sampleimage\\boxkite1500x500.png", fs).Result;
                 *
                 *     // var x = session.SendTweetWithImage("Maggies Rules", "maggie.jpg", fs).Result;
                 *
                 *     if (x.twitterFaulted)
                 *     {
                 *         PrintTwitterErrors(x.twitterControlMessage);
                 *     }
                 *     else
                 *     {
                 *         ConsoleOutput.PrintMessage("OK");
                 *     }
                 *
                 * }
                 *
                 * }
                 */
                /*
                 * mainTwitterAccount.TimeLine.Subscribe(t => ConsoleOutput.PrintTweet(t));
                 * mainTwitterAccount.Mentions.Subscribe(
                 *  t => ConsoleOutput.PrintTweet(t, ConsoleColor.White, ConsoleColor.DarkGray));
                 *
                 * while (true)
                 * {
                 *  Thread.Sleep(TimeSpan.FromSeconds(0.5));
                 * }
                 *
                 * Console.ConsoleOutput.PrintMessage("Event stream has stoppped.");
                 *
                 *       var locations = new List<string> { "-34.081953", "150.700493", "-33.593316", "151.284828" };
                 *          searchstream = session.StartSearchStream(locations: locations);
                 *          searchstream = session.StartSearchStream(track: "hazel");
                 *          searchstream.FoundTweets.Subscribe(t => ConsoleOutput.PrintTweet(t, ConsoleColor.Green));
                 *          searchstream.Start();
                 *
                 *          while (searchstream.IsActive)
                 *          {
                 *              Thread.Sleep(TimeSpan.FromMinutes(1));
                 *              var sr = new StreamSearchRequest();
                 *              sr.tracks.Add("xbox");
                 *              searchstream.SearchRequests.Publish(sr);
                 *          }
                 *
                 */


                /*
                 *      var x = session.GetMentions(count:100).Result;
                 *
                 *      foreach (var tweet in x)
                 *      {
                 *          ConsoleOutputPrintTweet(tweet);
                 *      }
                 *
                 *
                 *       session.GetFavourites(count: 10)
                 *          .Subscribe(t => ConsoleOutputPrintTweet(t, ConsoleColor.White, ConsoleColor.Black));
                 */
            }

            ConsoleOutput.PrintMessage("All Finished");
            System.Console.ReadLine();
        }
        public async Task <bool> DoApplicationOnlyAuthFireTests(TwitterConnection twitterConnection, List <int> testSeq)
        {
            var successStatus = true;

            try
            {
                // 1
                if (testSeq.Contains(1))
                {
                    ConsoleOutput.PrintMessage("12.1 User Time Line//Application Auth Only", ConsoleColor.Gray);

                    var combo1 = await twitterConnection.TwitterSession.GetUserTimeline("KatyPerry");

                    if (combo1.OK)
                    {
                        foreach (var trnd in combo1)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("App Auth Timeline Test: {0}", trnd.Text));
                        }
                    }
                    else
                    {
                        successStatus = false;
                        throw new Exception("cannot user time line (app only auth)");
                    }
                } // end test 1

                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("12.2 API Management//Rate limits", ConsoleColor.Gray);

                    var combo2 = await twitterConnection.TwitterSession.GetCurrentApiStatus();

                    if (combo2.OK)
                    {
                        foreach (var apir in combo2.APIRateStatuses)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("API: {0} Limit: {1} Remaining: {2}", apir.Value.APIPath, apir.Value.Limit, apir.Value.Remaining));
                        }
                    }
                    else
                    {
                        successStatus = false;
                        throw new Exception("cannot api management (app only auth)");
                    }
                } // end test 2

                // 3
                if (testSeq.Contains(3))
                {
                    ConsoleOutput.PrintMessage("12.3 Get a Tweet//", ConsoleColor.Gray);

                    var combo3 = await twitterConnection.TwitterSession.GetTweet(464717579861258242);

                    if (combo3.OK)
                    {
                        ConsoleOutput.PrintMessage(combo3.Text);
                    }
                    else
                    {
                        successStatus = false;
                        throw new Exception("cannot get tweet (app only auth)");
                    }
                } // end test 3


                // 4
                if (testSeq.Contains(4))
                {
                    ConsoleOutput.PrintMessage("12.4 Get a Retweet//", ConsoleColor.Gray);

                    var oldtweet = new Tweet()
                    {
                        Id = 453310114796412928
                    };

                    var combo4 = await twitterConnection.TwitterSession.GetRetweets(oldtweet);

                    if (combo4.OK)
                    {
                        ConsoleOutput.PrintMessage(String.Format("Retweeted {0} times", combo4.Count));
                    }
                    else
                    {
                        successStatus = false;
                        throw new Exception("cannot get retweet (app only auth)");
                    }
                } // end test 4


                // 5
                if (testSeq.Contains(5))
                {
                    ConsoleOutput.PrintMessage("12.5 Get friendships//", ConsoleColor.Gray);

                    var combo5 = await twitterConnection.TwitterSession.GetFriendship(sourceScreenName : "shiftkey", targetScreenName : "nickhodgemsft");

                    if (combo5.OK)
                    {
                    }
                    else
                    {
                        successStatus = false;
                        throw new Exception("cannot get friendships (app only auth)");
                    }
                } // end test 5
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }