Inheritance: IDisposable
Exemple #1
0
        public async Task ListsStatuses_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.GetAsync <TwitterStatus[]>(
                               new Uri("lists/statuses.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "list_id", "12345" },
                    { "include_entities", "true" },
                    { "include_ext_alt_text", "true" },
                    { "tweet_mode", "extended" },
                    { "count", "200" },
                    { "max_id", "900" },
                    { "since_id", "100" },
                    { "include_rts", "true" },
                },
                               "/lists/statuses")
                           )
                .ReturnsAsync(new TwitterStatus[0]);

                twitterApi.apiConnection = mock.Object;

                await twitterApi.ListsStatuses(12345L, count : 200, maxId : 900L, sinceId : 100L, includeRTs : true)
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
        public async Task AccountUpdateProfile_Test()
        {
            var mock = new Mock <IApiConnection>();

            mock.Setup(x =>
                       x.PostLazyAsync <TwitterUser>(
                           new Uri("account/update_profile.json", UriKind.Relative),
                           new Dictionary <string, string> {
                { "include_entities", "true" },
                { "include_ext_alt_text", "true" },
                { "tweet_mode", "extended" },
                { "name", "Name" },
                { "url", "http://example.com/" },
                { "location", "Location" },
                { "description", "&lt;script&gt;alert(1)&lt;/script&gt;" },
            })
                       )
            .ReturnsAsync(LazyJson.Create(new TwitterUser()));

            using var twitterApi     = new TwitterApi();
            twitterApi.apiConnection = mock.Object;

            await twitterApi.AccountUpdateProfile(name : "Name", url : "http://example.com/", location : "Location", description : "<script>alert(1)</script>")
            .IgnoreResponse()
            .ConfigureAwait(false);

            mock.VerifyAll();
        }
Exemple #3
0
        public async Task MediaUploadAppend_Test()
        {
            using var image = TestUtils.CreateDummyImage();
            using var media = new MemoryImageMediaItem(image);
            var mock = new Mock <IApiConnection>();

            mock.Setup(x =>
                       x.PostAsync(
                           new Uri("https://upload.twitter.com/1.1/media/upload.json", UriKind.Absolute),
                           new Dictionary <string, string> {
                { "command", "APPEND" },
                { "media_id", "11111" },
                { "segment_index", "1" },
            },
                           new Dictionary <string, IMediaItem> {
                { "media", media }
            })
                       )
            .Returns(Task.CompletedTask);

            using var twitterApi     = new TwitterApi();
            twitterApi.apiConnection = mock.Object;

            await twitterApi.MediaUploadAppend(mediaId : 11111L, segmentIndex : 1, media : media)
            .ConfigureAwait(false);

            mock.VerifyAll();
        }
Exemple #4
0
        public async Task UsersReportSpam_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.PostLazyAsync <TwitterUser>(
                               new Uri("users/report_spam.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "screen_name", "twitterapi" },
                    { "tweet_mode", "extended" },
                })
                           )
                .ReturnsAsync(LazyJson.Create(new TwitterUser {
                    ScreenName = "twitterapi"
                }));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.UsersReportSpam(screenName : "twitterapi")
                .IgnoreResponse()
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #5
0
        public async Task FavoritesDestroy_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.PostLazyAsync <TwitterStatus>(
                               new Uri("favorites/destroy.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "id", "100" },
                    { "tweet_mode", "extended" },
                })
                           )
                .ReturnsAsync(LazyJson.Create(new TwitterStatus {
                    Id = 100L
                }));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.FavoritesDestroy(statusId : 100L)
                .IgnoreResponse()
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #6
0
        public async Task ListsMembersDestroy_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.PostLazyAsync <TwitterUser>(
                               new Uri("lists/members/destroy.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "list_id", "12345" },
                    { "screen_name", "twitterapi" },
                    { "include_entities", "true" },
                    { "include_ext_alt_text", "true" },
                    { "tweet_mode", "extended" },
                })
                           )
                .ReturnsAsync(LazyJson.Create(new TwitterUser()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.ListsMembersDestroy(12345L, "twitterapi")
                .IgnoreResponse()
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #7
0
        public async Task DirectMessagesDestroy_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.PostLazyAsync <TwitterDirectMessage>(
                               new Uri("direct_messages/destroy.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "id", "100" }
                })
                           )
                .ReturnsAsync(LazyJson.Create(new TwitterDirectMessage {
                    Id = 100L
                }));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.DirectMessagesDestroy(statusId : 100L)
                .IgnoreResponse()
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #8
0
        public async Task UserStreams_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.GetStreamingStreamAsync(
                               new Uri("https://userstream.twitter.com/1.1/user.json", UriKind.Absolute),
                               new Dictionary <string, string> {
                    { "replies", "all" },
                    { "track", "OpenTween" },
                })
                           )
                .ReturnsAsync(new MemoryStream());

                twitterApi.apiConnection = mock.Object;

                var stream = await twitterApi.UserStreams(replies : "all", track : "OpenTween")
                             .ConfigureAwait(false);

                stream.Dispose();

                mock.VerifyAll();
            }
        }
Exemple #9
0
        public async Task StatusesShow_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.GetAsync <TwitterStatus>(
                               new Uri("statuses/show.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "id", "100" },
                    { "include_entities", "true" },
                    { "include_ext_alt_text", "true" },
                    { "tweet_mode", "extended" },
                },
                               "/statuses/show/:id")
                           )
                .ReturnsAsync(new TwitterStatus {
                    Id = 100L
                });

                twitterApi.apiConnection = mock.Object;

                await twitterApi.StatusesShow(statusId : 100L)
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #10
0
        public async Task AccountUpdateProfileImage_Test()
        {
            using (var twitterApi = new TwitterApi())
                using (var image = TestUtils.CreateDummyImage())
                    using (var media = new MemoryImageMediaItem(image))
                    {
                        var mock = new Mock <IApiConnection>();
                        mock.Setup(x =>
                                   x.PostLazyAsync <TwitterUser>(
                                       new Uri("account/update_profile_image.json", UriKind.Relative),
                                       new Dictionary <string, string> {
                            { "include_entities", "true" },
                            { "include_ext_alt_text", "true" },
                            { "tweet_mode", "extended" },
                        },
                                       new Dictionary <string, IMediaItem> {
                            { "image", media }
                        })
                                   )
                        .ReturnsAsync(LazyJson.Create(new TwitterUser()));

                        twitterApi.apiConnection = mock.Object;

                        await twitterApi.AccountUpdateProfileImage(media)
                        .IgnoreResponse()
                        .ConfigureAwait(false);

                        mock.VerifyAll();
                    }
        }
Exemple #11
0
        public async Task MediaUpload_Test()
        {
            using (var twitterApi = new TwitterApi())
                using (var image = TestUtils.CreateDummyImage())
                    using (var media = new MemoryImageMediaItem(image))
                    {
                        var mock = new Mock <IApiConnection>();
                        mock.Setup(x =>
                                   x.PostLazyAsync <TwitterUploadMediaResult>(
                                       new Uri("https://upload.twitter.com/1.1/media/upload.json", UriKind.Absolute),
                                       null,
                                       new Dictionary <string, IMediaItem> {
                            { "media", media }
                        })
                                   )
                        .ReturnsAsync(LazyJson.Create(new TwitterUploadMediaResult()));

                        twitterApi.apiConnection = mock.Object;

                        await twitterApi.MediaUpload(media)
                        .IgnoreResponse()
                        .ConfigureAwait(false);

                        mock.VerifyAll();
                    }
        }
Exemple #12
0
        public async Task FavoritesList_Test()
        {
            var mock = new Mock <IApiConnection>();

            mock.Setup(x =>
                       x.GetAsync <TwitterStatus[]>(
                           new Uri("favorites/list.json", UriKind.Relative),
                           new Dictionary <string, string> {
                { "include_entities", "true" },
                { "include_ext_alt_text", "true" },
                { "tweet_mode", "extended" },
                { "count", "200" },
                { "max_id", "900" },
                { "since_id", "100" },
            },
                           "/favorites/list")
                       )
            .ReturnsAsync(Array.Empty <TwitterStatus>());

            using var twitterApi     = new TwitterApi();
            twitterApi.apiConnection = mock.Object;

            await twitterApi.FavoritesList(200, maxId : 900L, sinceId : 100L)
            .ConfigureAwait(false);

            mock.VerifyAll();
        }
Exemple #13
0
        public async Task UsersLookup_Test()
        {
            var mock = new Mock <IApiConnection>();

            mock.Setup(x =>
                       x.GetAsync <TwitterUser[]>(
                           new Uri("users/lookup.json", UriKind.Relative),
                           new Dictionary <string, string> {
                { "user_id", "11111,22222" },
                { "include_entities", "true" },
                { "include_ext_alt_text", "true" },
                { "tweet_mode", "extended" },
            },
                           "/users/lookup")
                       )
            .ReturnsAsync(Array.Empty <TwitterUser>());

            using var twitterApi     = new TwitterApi();
            twitterApi.apiConnection = mock.Object;

            await twitterApi.UsersLookup(userIds : new[] { "11111", "22222" })
            .ConfigureAwait(false);

            mock.VerifyAll();
        }
Exemple #14
0
        public async Task ListsMembersShow_Test()
        {
            var mock = new Mock <IApiConnection>();

            mock.Setup(x =>
                       x.GetAsync <TwitterUser>(
                           new Uri("lists/members/show.json", UriKind.Relative),
                           new Dictionary <string, string> {
                { "list_id", "12345" },
                { "screen_name", "twitterapi" },
                { "include_entities", "true" },
                { "include_ext_alt_text", "true" },
                { "tweet_mode", "extended" },
            },
                           "/lists/members/show")
                       )
            .ReturnsAsync(new TwitterUser());

            using var twitterApi     = new TwitterApi();
            twitterApi.apiConnection = mock.Object;

            await twitterApi.ListsMembersShow(12345L, "twitterapi")
            .ConfigureAwait(false);

            mock.VerifyAll();
        }
Exemple #15
0
        public void Initialize_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                Assert.Null(twitterApi.apiConnection);

                twitterApi.Initialize("*** AccessToken ***", "*** AccessSecret ***", userId: 100L, screenName: "hogehoge");

                Assert.IsType <TwitterApiConnection>(twitterApi.apiConnection);

                var apiConnection = (TwitterApiConnection)twitterApi.apiConnection;
                Assert.Equal("*** AccessToken ***", apiConnection.AccessToken);
                Assert.Equal("*** AccessSecret ***", apiConnection.AccessSecret);

                Assert.Equal(100L, twitterApi.CurrentUserId);
                Assert.Equal("hogehoge", twitterApi.CurrentScreenName);

                // 複数回 Initialize を実行した場合は新たに TwitterApiConnection が生成される
                twitterApi.Initialize("*** AccessToken2 ***", "*** AccessSecret2 ***", userId: 200L, screenName: "foobar");

                var oldApiConnection = apiConnection;
                Assert.True(oldApiConnection.IsDisposed);

                Assert.IsType <TwitterApiConnection>(twitterApi.apiConnection);

                apiConnection = (TwitterApiConnection)twitterApi.apiConnection;
                Assert.Equal("*** AccessToken2 ***", apiConnection.AccessToken);
                Assert.Equal("*** AccessSecret2 ***", apiConnection.AccessSecret);

                Assert.Equal(200L, twitterApi.CurrentUserId);
                Assert.Equal("foobar", twitterApi.CurrentScreenName);
            }
        }
Exemple #16
0
        public async Task StatusesUpdate_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.PostLazyAsync <TwitterStatus>(
                               new Uri("statuses/update.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "status", "hogehoge" },
                    { "include_entities", "true" },
                    { "include_ext_alt_text", "true" },
                    { "tweet_mode", "extended" },
                    { "in_reply_to_status_id", "100" },
                    { "media_ids", "10,20" },
                    { "auto_populate_reply_metadata", "true" },
                    { "exclude_reply_user_ids", "100,200" },
                    { "attachment_url", "https://twitter.com/twitterapi/status/22634515958" },
                })
                           )
                .ReturnsAsync(LazyJson.Create(new TwitterStatus()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.StatusesUpdate("hogehoge", replyToId : 100L, mediaIds : new[] { 10L, 20L },
                                                autoPopulateReplyMetadata : true, excludeReplyUserIds : new[] { 100L, 200L },
                                                attachmentUrl : "https://twitter.com/twitterapi/status/22634515958")
                .IgnoreResponse()
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #17
0
        public async Task ListsMembers_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.GetAsync <TwitterUsers>(
                               new Uri("lists/members.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "list_id", "12345" },
                    { "include_entities", "true" },
                    { "include_ext_alt_text", "true" },
                    { "tweet_mode", "extended" },
                    { "cursor", "-1" },
                },
                               "/lists/members")
                           )
                .ReturnsAsync(new TwitterUsers());

                twitterApi.apiConnection = mock.Object;

                await twitterApi.ListsMembers(12345L, cursor : -1)
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #18
0
        public async Task StatusesUpdate_ExcludeReplyUserIdsEmptyTest()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.PostLazyAsync <TwitterStatus>(
                               new Uri("statuses/update.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "status", "hogehoge" },
                    { "include_entities", "true" },
                    { "include_ext_alt_text", "true" },
                    { "tweet_mode", "extended" },
                    // exclude_reply_user_ids は空の場合には送信されない
                })
                           )
                .ReturnsAsync(LazyJson.Create(new TwitterStatus()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.StatusesUpdate("hogehoge", replyToId : null, mediaIds : null, excludeReplyUserIds : new long[0])
                .IgnoreResponse()
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #19
0
        public async Task DirectMessagesSent_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.GetAsync <TwitterDirectMessage[]>(
                               new Uri("direct_messages/sent.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "full_text", "true" },
                    { "include_entities", "true" },
                    { "include_ext_alt_text", "true" },
                    { "count", "200" },
                    { "max_id", "900" },
                    { "since_id", "100" },
                },
                               "/direct_messages/sent")
                           )
                .ReturnsAsync(new TwitterDirectMessage[0]);

                twitterApi.apiConnection = mock.Object;

                await twitterApi.DirectMessagesSent(count : 200, maxId : 900L, sinceId : 100L)
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #20
0
        public async Task StatusesRetweet_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.PostLazyAsync <TwitterStatus>(
                               new Uri("statuses/retweet.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "id", "100" },
                    { "include_entities", "true" },
                    { "include_ext_alt_text", "true" },
                    { "tweet_mode", "extended" },
                })
                           )
                .ReturnsAsync(LazyJson.Create(new TwitterStatus()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.StatusesRetweet(100L)
                .IgnoreResponse()
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #21
0
        public async Task UsersShow_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.GetAsync <TwitterUser>(
                               new Uri("users/show.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "screen_name", "twitterapi" },
                    { "include_entities", "true" },
                    { "include_ext_alt_text", "true" },
                    { "tweet_mode", "extended" },
                },
                               "/users/show/:id")
                           )
                .ReturnsAsync(new TwitterUser {
                    ScreenName = "twitterapi"
                });

                twitterApi.apiConnection = mock.Object;

                await twitterApi.UsersShow(screenName : "twitterapi")
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #22
0
        public async Task SearchTweets_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.GetAsync <TwitterSearchResult>(
                               new Uri("search/tweets.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "q", "from:twitterapi" },
                    { "result_type", "recent" },
                    { "include_entities", "true" },
                    { "include_ext_alt_text", "true" },
                    { "tweet_mode", "extended" },
                    { "lang", "en" },
                    { "count", "200" },
                    { "max_id", "900" },
                    { "since_id", "100" },
                },
                               "/search/tweets")
                           )
                .ReturnsAsync(new TwitterSearchResult());

                twitterApi.apiConnection = mock.Object;

                await twitterApi.SearchTweets("from:twitterapi", "en", count : 200, maxId : 900L, sinceId : 100L)
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #23
0
        public async Task StatusesHomeTimeline_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.GetAsync <TwitterStatus[]>(
                               new Uri("statuses/home_timeline.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "include_entities", "true" },
                    { "include_ext_alt_text", "true" },
                    { "tweet_mode", "extended" },
                    { "count", "200" },
                    { "max_id", "900" },
                    { "since_id", "100" },
                },
                               "/statuses/home_timeline")
                           )
                .ReturnsAsync(new TwitterStatus[0]);

                twitterApi.apiConnection = mock.Object;

                await twitterApi.StatusesHomeTimeline(200, maxId : 900L, sinceId : 100L)
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #24
0
        public async Task ListsMemberships_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.GetAsync <TwitterLists>(
                               new Uri("lists/memberships.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "screen_name", "twitterapi" },
                    { "cursor", "-1" },
                    { "count", "100" },
                    { "filter_to_owned_lists", "true" },
                },
                               "/lists/memberships")
                           )
                .ReturnsAsync(new TwitterLists());

                twitterApi.apiConnection = mock.Object;

                await twitterApi.ListsMemberships("twitterapi", cursor : -1L, count : 100, filterToOwnedLists : true)
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #25
0
        public async Task AccountVerifyCredentials_Test()
        {
            var mock = new Mock <IApiConnection>();

            mock.Setup(x =>
                       x.GetAsync <TwitterUser>(
                           new Uri("account/verify_credentials.json", UriKind.Relative),
                           new Dictionary <string, string> {
                { "include_entities", "true" },
                { "include_ext_alt_text", "true" },
                { "tweet_mode", "extended" },
            },
                           "/account/verify_credentials")
                       )
            .ReturnsAsync(new TwitterUser
            {
                Id         = 100L,
                ScreenName = "opentween",
            });

            using var twitterApi     = new TwitterApi();
            twitterApi.apiConnection = mock.Object;

            await twitterApi.AccountVerifyCredentials()
            .ConfigureAwait(false);

            Assert.Equal(100L, twitterApi.CurrentUserId);
            Assert.Equal("opentween", twitterApi.CurrentScreenName);

            mock.VerifyAll();
        }
Exemple #26
0
        public async Task ListsUpdate_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock <IApiConnection>();
                mock.Setup(x =>
                           x.PostLazyAsync <TwitterList>(
                               new Uri("lists/update.json", UriKind.Relative),
                               new Dictionary <string, string> {
                    { "list_id", "12345" },
                    { "name", "hogehoge" },
                    { "description", "aaaa" },
                    { "mode", "private" },
                })
                           )
                .ReturnsAsync(LazyJson.Create(new TwitterList()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.ListsUpdate(12345L, name : "hogehoge", description : "aaaa", @private : true)
                .IgnoreResponse()
                .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #27
0
        public void Initialize_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                Assert.Null(twitterApi.apiConnection);

                twitterApi.Initialize("*** AccessToken ***", "*** AccessSecret ***", userId: 100L, screenName: "hogehoge");

                Assert.IsType<TwitterApiConnection>(twitterApi.apiConnection);

                var apiConnection = (TwitterApiConnection)twitterApi.apiConnection;
                Assert.Equal("*** AccessToken ***", apiConnection.AccessToken);
                Assert.Equal("*** AccessSecret ***", apiConnection.AccessSecret);

                Assert.Equal(100L, twitterApi.CurrentUserId);
                Assert.Equal("hogehoge", twitterApi.CurrentScreenName);

                // 複数回 Initialize を実行した場合は新たに TwitterApiConnection が生成される
                twitterApi.Initialize("*** AccessToken2 ***", "*** AccessSecret2 ***", userId: 200L, screenName: "foobar");

                var oldApiConnection = apiConnection;
                Assert.True(oldApiConnection.IsDisposed);

                Assert.IsType<TwitterApiConnection>(twitterApi.apiConnection);

                apiConnection = (TwitterApiConnection)twitterApi.apiConnection;
                Assert.Equal("*** AccessToken2 ***", apiConnection.AccessToken);
                Assert.Equal("*** AccessSecret2 ***", apiConnection.AccessSecret);

                Assert.Equal(200L, twitterApi.CurrentUserId);
                Assert.Equal("foobar", twitterApi.CurrentScreenName);
            }
        }
Exemple #28
0
        public async Task MediaUploadInit_Test()
        {
            var mock = new Mock <IApiConnection>();

            mock.Setup(x =>
                       x.PostLazyAsync <TwitterUploadMediaInit>(
                           new Uri("https://upload.twitter.com/1.1/media/upload.json", UriKind.Absolute),
                           new Dictionary <string, string> {
                { "command", "INIT" },
                { "total_bytes", "123456" },
                { "media_type", "image/png" },
                { "media_category", "dm_image" },
            })
                       )
            .ReturnsAsync(LazyJson.Create(new TwitterUploadMediaInit()));

            using var twitterApi     = new TwitterApi();
            twitterApi.apiConnection = mock.Object;

            await twitterApi.MediaUploadInit(totalBytes : 123456L, mediaType : "image/png", mediaCategory : "dm_image")
            .IgnoreResponse()
            .ConfigureAwait(false);

            mock.VerifyAll();
        }
Exemple #29
0
        public MyLists(string screenName, TwitterApi twitterApi)
        {
            this.InitializeComponent();

            this.twitterApi = twitterApi;
            this.contextScreenName = screenName;

            this.Text = screenName + Properties.Resources.MyLists1;
        }
Exemple #30
0
        public async Task DirectMessagesEventsDestroy_Test()
        {
            var mock = new Mock <IApiConnection>();

            mock.Setup(x =>
                       x.DeleteAsync(
                           new Uri("direct_messages/events/destroy.json?id=100", UriKind.Relative))
                       )
            .Returns(Task.CompletedTask);

            using var twitterApi     = new TwitterApi();
            twitterApi.apiConnection = mock.Object;

            await twitterApi.DirectMessagesEventsDestroy(eventId : "100")
            .ConfigureAwait(false);

            mock.VerifyAll();
        }
Exemple #31
0
        public async Task MediaMetadataCreate_Test()
        {
            var mock = new Mock <IApiConnection>();

            mock.Setup(x =>
                       x.PostJsonAsync(
                           new Uri("https://upload.twitter.com/1.1/media/metadata/create.json", UriKind.Absolute),
                           "{\"media_id\": \"12345\", \"alt_text\": {\"text\": \"hogehoge\"}}")
                       )
            .Returns(Task.CompletedTask);

            using var twitterApi     = new TwitterApi();
            twitterApi.apiConnection = mock.Object;

            await twitterApi.MediaMetadataCreate(mediaId : 12345L, altText : "hogehoge")
            .ConfigureAwait(false);

            mock.VerifyAll();
        }
Exemple #32
0
        public async Task NoRetweetIds_Test()
        {
            var mock = new Mock <IApiConnection>();

            mock.Setup(x =>
                       x.GetAsync <long[]>(
                           new Uri("friendships/no_retweets/ids.json", UriKind.Relative),
                           null,
                           "/friendships/no_retweets/ids")
                       )
            .ReturnsAsync(Array.Empty <long>());

            using var twitterApi     = new TwitterApi();
            twitterApi.apiConnection = mock.Object;

            await twitterApi.NoRetweetIds()
            .ConfigureAwait(false);

            mock.VerifyAll();
        }
Exemple #33
0
        public async Task MutesUsersIds_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetAsync<TwitterIds>(
                        new Uri("mutes/users/ids.json", UriKind.Relative),
                        new Dictionary<string, string> { { "cursor", "-1" } },
                        "/mutes/users/ids")
                )
                .ReturnsAsync(new TwitterIds());

                twitterApi.apiConnection = mock.Object;

                await twitterApi.MutesUsersIds(cursor: -1L)
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #34
0
        public async Task FriendshipsDestroy_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostLazyAsync<TwitterFriendship>(
                        new Uri("friendships/destroy.json", UriKind.Relative),
                        new Dictionary<string, string> { { "screen_name", "twitterapi" } })
                )
                .ReturnsAsync(LazyJson.Create(new TwitterFriendship()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.FriendshipsDestroy(screenName: "twitterapi")
                    .IgnoreResponse()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #35
0
        public async Task FriendshipsShow_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetAsync<TwitterFriendship>(
                        new Uri("friendships/show.json", UriKind.Relative),
                        new Dictionary<string, string> { { "source_screen_name", "twitter" }, { "target_screen_name", "twitterapi" } },
                        "/friendships/show")
                )
                .ReturnsAsync(new TwitterFriendship());

                twitterApi.apiConnection = mock.Object;

                await twitterApi.FriendshipsShow(sourceScreenName: "twitter", targetScreenName: "twitterapi")
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #36
0
        public async Task UsersReportSpam_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostLazyAsync<TwitterUser>(
                        new Uri("users/report_spam.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "screen_name", "twitterapi" },
                            { "tweet_mode", "extended" },
                        })
                )
                .ReturnsAsync(LazyJson.Create(new TwitterUser { ScreenName = "twitterapi" }));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.UsersReportSpam(screenName: "twitterapi")
                    .IgnoreResponse()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #37
0
        public async Task DirectMessagesDestroy_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostLazyAsync<TwitterDirectMessage>(
                        new Uri("direct_messages/destroy.json", UriKind.Relative),
                        new Dictionary<string, string> { { "id", "100" } })
                )
                .ReturnsAsync(LazyJson.Create(new TwitterDirectMessage { Id = 100L }));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.DirectMessagesDestroy(statusId: 100L)
                    .IgnoreResponse()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #38
0
        public async Task DirectMessagesSent_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetAsync<TwitterDirectMessage[]>(
                        new Uri("direct_messages/sent.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "full_text", "true" },
                            { "include_entities", "true" },
                            { "include_ext_alt_text", "true" },
                            { "count", "200" },
                            { "max_id", "900" },
                            { "since_id", "100" },
                        },
                        "/direct_messages/sent")
                )
                .ReturnsAsync(new TwitterDirectMessage[0]);

                twitterApi.apiConnection = mock.Object;

                await twitterApi.DirectMessagesSent(count: 200, maxId: 900L, sinceId: 100L)
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #39
0
        public async Task UserStreams_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetStreamingStreamAsync(
                        new Uri("https://userstream.twitter.com/1.1/user.json", UriKind.Absolute),
                        new Dictionary<string, string> {
                            { "replies", "all" },
                            { "track", "OpenTween" },
                        })
                )
                .ReturnsAsync(new MemoryStream());

                twitterApi.apiConnection = mock.Object;

                var stream = await twitterApi.UserStreams(replies: "all", track: "OpenTween")
                    .ConfigureAwait(false);

                stream.Dispose();

                mock.VerifyAll();
            }
        }
Exemple #40
0
        public async Task MediaMetadataCreate_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostJsonAsync(
                        new Uri("https://upload.twitter.com/1.1/media/metadata/create.json", UriKind.Absolute),
                        "{\"media_id\": \"12345\", \"alt_text\": {\"text\": \"hogehoge\"}}")
                )
                .Returns(Task.FromResult(0));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.MediaMetadataCreate(mediaId: 12345L, altText: "hogehoge")
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #41
0
        public async Task MediaUpload_Test()
        {
            using (var twitterApi = new TwitterApi())
            using (var image = TestUtils.CreateDummyImage())
            using (var media = new MemoryImageMediaItem(image))
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostLazyAsync<TwitterUploadMediaResult>(
                        new Uri("https://upload.twitter.com/1.1/media/upload.json", UriKind.Absolute),
                        null,
                        new Dictionary<string, IMediaItem> { { "media", media } })
                )
                .ReturnsAsync(LazyJson.Create(new TwitterUploadMediaResult()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.MediaUpload(media)
                    .IgnoreResponse()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #42
0
        public async Task Configuration_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetAsync<TwitterConfiguration>(
                        new Uri("help/configuration.json", UriKind.Relative),
                        null,
                        "/help/configuration")
                )
                .ReturnsAsync(new TwitterConfiguration());

                twitterApi.apiConnection = mock.Object;

                await twitterApi.Configuration()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #43
0
        public async Task ApplicationRateLimitStatus_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetAsync<TwitterRateLimits>(
                        new Uri("application/rate_limit_status.json", UriKind.Relative),
                        null,
                        "/application/rate_limit_status")
                )
                .ReturnsAsync(new TwitterRateLimits());

                twitterApi.apiConnection = mock.Object;

                await twitterApi.ApplicationRateLimitStatus()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #44
0
        public async Task AccountUpdateProfileImage_Test()
        {
            using (var twitterApi = new TwitterApi())
            using (var image = TestUtils.CreateDummyImage())
            using (var media = new MemoryImageMediaItem(image))
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostLazyAsync<TwitterUser>(
                        new Uri("account/update_profile_image.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "include_entities", "true" },
                            { "include_ext_alt_text", "true" },
                            { "tweet_mode", "extended" },
                        },
                        new Dictionary<string, IMediaItem> { { "image", media } })
                )
                .ReturnsAsync(LazyJson.Create(new TwitterUser()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.AccountUpdateProfileImage(media)
                    .IgnoreResponse()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #45
0
        public async Task ListsMembers_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetAsync<TwitterUsers>(
                        new Uri("lists/members.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "list_id", "12345" },
                            { "include_entities", "true" },
                            { "include_ext_alt_text", "true" },
                            { "tweet_mode", "extended" },
                            { "cursor", "-1" },
                        },
                        "/lists/members")
                )
                .ReturnsAsync(new TwitterUsers());

                twitterApi.apiConnection = mock.Object;

                await twitterApi.ListsMembers(12345L, cursor: -1)
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #46
0
        public async Task StatusesShow_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetAsync<TwitterStatus>(
                        new Uri("statuses/show.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "id", "100" },
                            { "include_entities", "true" },
                            { "include_ext_alt_text", "true" },
                            { "tweet_mode", "extended" },
                        },
                        "/statuses/show/:id")
                )
                .ReturnsAsync(new TwitterStatus { Id = 100L });

                twitterApi.apiConnection = mock.Object;

                await twitterApi.StatusesShow(statusId: 100L)
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #47
0
        public async Task ListsMembersDestroy_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostLazyAsync<TwitterUser>(
                        new Uri("lists/members/destroy.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "list_id", "12345" },
                            { "screen_name", "twitterapi" },
                            { "include_entities", "true" },
                            { "include_ext_alt_text", "true" },
                            { "tweet_mode", "extended" },
                        })
                )
                .ReturnsAsync(LazyJson.Create(new TwitterUser()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.ListsMembersDestroy(12345L, "twitterapi")
                    .IgnoreResponse()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #48
0
        public async Task StatusesUpdate_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostLazyAsync<TwitterStatus>(
                        new Uri("statuses/update.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "status", "hogehoge" },
                            { "include_entities", "true" },
                            { "include_ext_alt_text", "true" },
                            { "tweet_mode", "extended" },
                            { "in_reply_to_status_id", "100" },
                            { "media_ids", "10,20" },
                        })
                )
                .ReturnsAsync(LazyJson.Create(new TwitterStatus()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.StatusesUpdate("hogehoge", replyToId: 100L, mediaIds: new[] { 10L, 20L })
                    .IgnoreResponse()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #49
0
        public async Task DirectMessagesNew_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostLazyAsync<TwitterDirectMessage>(
                        new Uri("direct_messages/new.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "text", "hogehoge" },
                            { "screen_name", "opentween" },
                        })
                )
                .ReturnsAsync(LazyJson.Create(new TwitterDirectMessage()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.DirectMessagesNew("hogehoge", "opentween")
                    .IgnoreResponse()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #50
0
        public async Task StatusesRetweet_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostLazyAsync<TwitterStatus>(
                        new Uri("statuses/retweet.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "id", "100" },
                            { "include_entities", "true" },
                            { "include_ext_alt_text", "true" },
                            { "tweet_mode", "extended" },
                        })
                )
                .ReturnsAsync(LazyJson.Create(new TwitterStatus()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.StatusesRetweet(100L)
                    .IgnoreResponse()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #51
0
        public async Task UsersShow_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetAsync<TwitterUser>(
                        new Uri("users/show.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "screen_name", "twitterapi" },
                            { "include_entities", "true" },
                            { "include_ext_alt_text", "true" },
                            { "tweet_mode", "extended" },
                        },
                        "/users/show/:id")
                )
                .ReturnsAsync(new TwitterUser { ScreenName = "twitterapi" });

                twitterApi.apiConnection = mock.Object;

                await twitterApi.UsersShow(screenName: "twitterapi")
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #52
0
        public async Task SearchTweets_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetAsync<TwitterSearchResult>(
                        new Uri("search/tweets.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "q", "from:twitterapi" },
                            { "result_type", "recent" },
                            { "include_entities", "true" },
                            { "include_ext_alt_text", "true" },
                            { "tweet_mode", "extended" },
                            { "lang", "en" },
                            { "count", "200" },
                            { "max_id", "900" },
                            { "since_id", "100" },
                        },
                        "/search/tweets")
                )
                .ReturnsAsync(new TwitterSearchResult());

                twitterApi.apiConnection = mock.Object;

                await twitterApi.SearchTweets("from:twitterapi", "en", count: 200, maxId: 900L, sinceId: 100L)
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #53
0
        public async Task FavoritesDestroy_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostLazyAsync<TwitterStatus>(
                        new Uri("favorites/destroy.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "id", "100" },
                            { "tweet_mode", "extended" },
                        })
                )
                .ReturnsAsync(LazyJson.Create(new TwitterStatus { Id = 100L }));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.FavoritesDestroy(statusId: 100L)
                    .IgnoreResponse()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #54
0
        public async Task ListsMemberships_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetAsync<TwitterLists>(
                        new Uri("lists/memberships.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "screen_name", "twitterapi" },
                            { "cursor", "-1" },
                            { "count", "100" },
                            { "filter_to_owned_lists", "true" },
                        },
                        "/lists/memberships")
                )
                .ReturnsAsync(new TwitterLists());

                twitterApi.apiConnection = mock.Object;

                await twitterApi.ListsMemberships("twitterapi", cursor: -1L, count: 100, filterToOwnedLists: true)
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #55
0
        public async Task StatusesHomeTimeline_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetAsync<TwitterStatus[]>(
                        new Uri("statuses/home_timeline.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "include_entities", "true" },
                            { "include_ext_alt_text", "true" },
                            { "tweet_mode", "extended" },
                            { "count", "200" },
                            { "max_id", "900" },
                            { "since_id", "100" },
                        },
                        "/statuses/home_timeline")
                )
                .ReturnsAsync(new TwitterStatus[0]);

                twitterApi.apiConnection = mock.Object;

                await twitterApi.StatusesHomeTimeline(200, maxId: 900L, sinceId: 100L)
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #56
0
        public async Task ListsUpdate_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostLazyAsync<TwitterList>(
                        new Uri("lists/update.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "list_id", "12345" },
                            { "name", "hogehoge" },
                            { "description", "aaaa" },
                            { "mode", "private" },
                        })
                )
                .ReturnsAsync(LazyJson.Create(new TwitterList()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.ListsUpdate(12345L, name: "hogehoge", description: "aaaa", @private: true)
                    .IgnoreResponse()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #57
0
        public async Task NoRetweetIds_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetAsync<long[]>(
                        new Uri("friendships/no_retweets/ids.json", UriKind.Relative),
                        null,
                        "/friendships/no_retweets/ids")
                )
                .ReturnsAsync(new long[0]);

                twitterApi.apiConnection = mock.Object;

                await twitterApi.NoRetweetIds()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #58
0
        public async Task ListsDestroy_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostLazyAsync<TwitterList>(
                        new Uri("lists/destroy.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "list_id", "12345" },
                        })
                )
                .ReturnsAsync(LazyJson.Create(new TwitterList()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.ListsDestroy(12345L)
                    .IgnoreResponse()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #59
0
        public async Task AccountUpdateProfile_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.PostLazyAsync<TwitterUser>(
                        new Uri("account/update_profile.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "include_entities", "true" },
                            { "include_ext_alt_text", "true" },
                            { "tweet_mode", "extended" },
                            { "name", "Name" },
                            { "url", "http://example.com/" },
                            { "location", "Location" },
                            { "description", "&lt;script&gt;alert(1)&lt;/script&gt;" },
                        })
                )
                .ReturnsAsync(LazyJson.Create(new TwitterUser()));

                twitterApi.apiConnection = mock.Object;

                await twitterApi.AccountUpdateProfile(name: "Name", url: "http://example.com/", location: "Location", description: "<script>alert(1)</script>")
                    .IgnoreResponse()
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }
Exemple #60
0
        public async Task ListsStatuses_Test()
        {
            using (var twitterApi = new TwitterApi())
            {
                var mock = new Mock<IApiConnection>();
                mock.Setup(x =>
                    x.GetAsync<TwitterStatus[]>(
                        new Uri("lists/statuses.json", UriKind.Relative),
                        new Dictionary<string, string> {
                            { "list_id", "12345" },
                            { "include_entities", "true" },
                            { "include_ext_alt_text", "true" },
                            { "tweet_mode", "extended" },
                            { "count", "200" },
                            { "max_id", "900" },
                            { "since_id", "100" },
                            { "include_rts", "true" },
                        },
                        "/lists/statuses")
                )
                .ReturnsAsync(new TwitterStatus[0]);

                twitterApi.apiConnection = mock.Object;

                await twitterApi.ListsStatuses(12345L, count: 200, maxId: 900L, sinceId: 100L, includeRTs: true)
                    .ConfigureAwait(false);

                mock.VerifyAll();
            }
        }