OSDN Git Service

HttpTwitter.ShowListMemberメソッドをTwitterApiクラスに置き換え
[opentween/open-tween.git] / OpenTween.Tests / Api / TwitterApiTest.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2016 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
4 //
5 // This file is part of OpenTween.
6 //
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
10 // any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
21
22 using System;
23 using System.Collections.Generic;
24 using System.IO;
25 using System.Linq;
26 using System.Net.Http;
27 using System.Reflection;
28 using System.Runtime.InteropServices;
29 using System.Text;
30 using System.Threading.Tasks;
31 using Moq;
32 using OpenTween.Api.DataModel;
33 using OpenTween.Connection;
34 using Xunit;
35
36 namespace OpenTween.Api
37 {
38     public class TwitterApiTest
39     {
40         public TwitterApiTest()
41         {
42             this.MyCommonSetup();
43         }
44
45         public void MyCommonSetup()
46         {
47             var mockAssembly = new Mock<_Assembly>();
48             mockAssembly.Setup(m => m.GetName()).Returns(new AssemblyName("OpenTween"));
49
50             MyCommon.EntryAssembly = mockAssembly.Object;
51         }
52
53         [Fact]
54         public void Initialize_Test()
55         {
56             using (var twitterApi = new TwitterApi())
57             {
58                 Assert.Null(twitterApi.apiConnection);
59
60                 twitterApi.Initialize("*** AccessToken ***", "*** AccessSecret ***", userId: 100L, screenName: "hogehoge");
61
62                 Assert.IsType<TwitterApiConnection>(twitterApi.apiConnection);
63
64                 var apiConnection = (TwitterApiConnection)twitterApi.apiConnection;
65                 Assert.Equal("*** AccessToken ***", apiConnection.AccessToken);
66                 Assert.Equal("*** AccessSecret ***", apiConnection.AccessSecret);
67
68                 Assert.Equal(100L, twitterApi.CurrentUserId);
69                 Assert.Equal("hogehoge", twitterApi.CurrentScreenName);
70
71                 // 複数回 Initialize を実行した場合は新たに TwitterApiConnection が生成される
72                 twitterApi.Initialize("*** AccessToken2 ***", "*** AccessSecret2 ***", userId: 200L, screenName: "foobar");
73
74                 var oldApiConnection = apiConnection;
75                 Assert.True(oldApiConnection.IsDisposed);
76
77                 Assert.IsType<TwitterApiConnection>(twitterApi.apiConnection);
78
79                 apiConnection = (TwitterApiConnection)twitterApi.apiConnection;
80                 Assert.Equal("*** AccessToken2 ***", apiConnection.AccessToken);
81                 Assert.Equal("*** AccessSecret2 ***", apiConnection.AccessSecret);
82
83                 Assert.Equal(200L, twitterApi.CurrentUserId);
84                 Assert.Equal("foobar", twitterApi.CurrentScreenName);
85             }
86         }
87
88         [Fact]
89         public async Task StatusesHomeTimeline_Test()
90         {
91             using (var twitterApi = new TwitterApi())
92             {
93                 var mock = new Mock<IApiConnection>();
94                 mock.Setup(x =>
95                     x.GetAsync<TwitterStatus[]>(
96                         new Uri("statuses/home_timeline.json", UriKind.Relative),
97                         new Dictionary<string, string> {
98                             { "include_entities", "true" },
99                             { "include_ext_alt_text", "true" },
100                             { "count", "200" },
101                             { "max_id", "900" },
102                             { "since_id", "100" },
103                         },
104                         "/statuses/home_timeline")
105                 )
106                 .ReturnsAsync(new TwitterStatus[0]);
107
108                 twitterApi.apiConnection = mock.Object;
109
110                 await twitterApi.StatusesHomeTimeline(200, maxId: 900L, sinceId: 100L)
111                     .ConfigureAwait(false);
112
113                 mock.VerifyAll();
114             }
115         }
116
117         [Fact]
118         public async Task StatusesMentionsTimeline_Test()
119         {
120             using (var twitterApi = new TwitterApi())
121             {
122                 var mock = new Mock<IApiConnection>();
123                 mock.Setup(x =>
124                     x.GetAsync<TwitterStatus[]>(
125                         new Uri("statuses/mentions_timeline.json", UriKind.Relative),
126                         new Dictionary<string, string> {
127                             { "include_entities", "true" },
128                             { "include_ext_alt_text", "true" },
129                             { "count", "200" },
130                             { "max_id", "900" },
131                             { "since_id", "100" },
132                         },
133                         "/statuses/mentions_timeline")
134                 )
135                 .ReturnsAsync(new TwitterStatus[0]);
136
137                 twitterApi.apiConnection = mock.Object;
138
139                 await twitterApi.StatusesMentionsTimeline(200, maxId: 900L, sinceId: 100L)
140                     .ConfigureAwait(false);
141
142                 mock.VerifyAll();
143             }
144         }
145
146         [Fact]
147         public async Task StatusesUserTimeline_Test()
148         {
149             using (var twitterApi = new TwitterApi())
150             {
151                 var mock = new Mock<IApiConnection>();
152                 mock.Setup(x =>
153                     x.GetAsync<TwitterStatus[]>(
154                         new Uri("statuses/user_timeline.json", UriKind.Relative),
155                         new Dictionary<string, string> {
156                             { "screen_name", "twitterapi" },
157                             { "include_rts", "true" },
158                             { "include_entities", "true" },
159                             { "include_ext_alt_text", "true" },
160                             { "count", "200" },
161                             { "max_id", "900" },
162                             { "since_id", "100" },
163                         },
164                         "/statuses/user_timeline")
165                 )
166                 .ReturnsAsync(new TwitterStatus[0]);
167
168                 twitterApi.apiConnection = mock.Object;
169
170                 await twitterApi.StatusesUserTimeline("twitterapi", count: 200, maxId: 900L, sinceId: 100L)
171                     .ConfigureAwait(false);
172
173                 mock.VerifyAll();
174             }
175         }
176
177         [Fact]
178         public async Task StatusesShow_Test()
179         {
180             using (var twitterApi = new TwitterApi())
181             {
182                 var mock = new Mock<IApiConnection>();
183                 mock.Setup(x =>
184                     x.GetAsync<TwitterStatus>(
185                         new Uri("statuses/show.json", UriKind.Relative),
186                         new Dictionary<string, string> {
187                             { "id", "100" },
188                             { "include_entities", "true" },
189                             { "include_ext_alt_text", "true" },
190                         },
191                         "/statuses/show/:id")
192                 )
193                 .ReturnsAsync(new TwitterStatus { Id = 100L });
194
195                 twitterApi.apiConnection = mock.Object;
196
197                 await twitterApi.StatusesShow(statusId: 100L)
198                     .ConfigureAwait(false);
199
200                 mock.VerifyAll();
201             }
202         }
203
204         [Fact]
205         public async Task StatusesUpdate_Test()
206         {
207             using (var twitterApi = new TwitterApi())
208             {
209                 var mock = new Mock<IApiConnection>();
210                 mock.Setup(x =>
211                     x.PostLazyAsync<TwitterStatus>(
212                         new Uri("statuses/update.json", UriKind.Relative),
213                         new Dictionary<string, string> {
214                             { "status", "hogehoge" },
215                             { "include_entities", "true" },
216                             { "include_ext_alt_text", "true" },
217                             { "in_reply_to_status_id", "100" },
218                             { "media_ids", "10,20" },
219                         })
220                 )
221                 .ReturnsAsync(LazyJson.Create(new TwitterStatus()));
222
223                 twitterApi.apiConnection = mock.Object;
224
225                 await twitterApi.StatusesUpdate("hogehoge", replyToId: 100L, mediaIds: new[] { 10L, 20L })
226                     .IgnoreResponse()
227                     .ConfigureAwait(false);
228
229                 mock.VerifyAll();
230             }
231         }
232
233         [Fact]
234         public async Task StatusesDestroy_Test()
235         {
236             using (var twitterApi = new TwitterApi())
237             {
238                 var mock = new Mock<IApiConnection>();
239                 mock.Setup(x =>
240                     x.PostLazyAsync<TwitterStatus>(
241                         new Uri("statuses/destroy.json", UriKind.Relative),
242                         new Dictionary<string, string> { { "id", "100" } })
243                 )
244                 .ReturnsAsync(LazyJson.Create(new TwitterStatus { Id = 100L }));
245
246                 twitterApi.apiConnection = mock.Object;
247
248                 await twitterApi.StatusesDestroy(statusId: 100L)
249                     .IgnoreResponse()
250                     .ConfigureAwait(false);
251
252                 mock.VerifyAll();
253             }
254         }
255
256         [Fact]
257         public async Task StatusesRetweet_Test()
258         {
259             using (var twitterApi = new TwitterApi())
260             {
261                 var mock = new Mock<IApiConnection>();
262                 mock.Setup(x =>
263                     x.PostLazyAsync<TwitterStatus>(
264                         new Uri("statuses/retweet.json", UriKind.Relative),
265                         new Dictionary<string, string> {
266                             { "id", "100" },
267                             { "include_entities", "true" },
268                             { "include_ext_alt_text", "true" },
269                         })
270                 )
271                 .ReturnsAsync(LazyJson.Create(new TwitterStatus()));
272
273                 twitterApi.apiConnection = mock.Object;
274
275                 await twitterApi.StatusesRetweet(100L)
276                     .IgnoreResponse()
277                     .ConfigureAwait(false);
278
279                 mock.VerifyAll();
280             }
281         }
282
283         [Fact]
284         public async Task ListsOwnerships_Test()
285         {
286             using (var twitterApi = new TwitterApi())
287             {
288                 var mock = new Mock<IApiConnection>();
289                 mock.Setup(x =>
290                     x.GetAsync<TwitterLists>(
291                         new Uri("lists/ownerships.json", UriKind.Relative),
292                         new Dictionary<string, string> {
293                             { "screen_name", "twitterapi" },
294                             { "cursor", "-1" },
295                         },
296                         "/lists/ownerships")
297                 )
298                 .ReturnsAsync(new TwitterLists());
299
300                 twitterApi.apiConnection = mock.Object;
301
302                 await twitterApi.ListsOwnerships("twitterapi", cursor: -1L)
303                     .ConfigureAwait(false);
304
305                 mock.VerifyAll();
306             }
307         }
308
309         [Fact]
310         public async Task ListsSubscriptions_Test()
311         {
312             using (var twitterApi = new TwitterApi())
313             {
314                 var mock = new Mock<IApiConnection>();
315                 mock.Setup(x =>
316                     x.GetAsync<TwitterLists>(
317                         new Uri("lists/subscriptions.json", UriKind.Relative),
318                         new Dictionary<string, string> {
319                             { "screen_name", "twitterapi" },
320                             { "cursor", "-1" },
321                         },
322                         "/lists/subscriptions")
323                 )
324                 .ReturnsAsync(new TwitterLists());
325
326                 twitterApi.apiConnection = mock.Object;
327
328                 await twitterApi.ListsSubscriptions("twitterapi", cursor: -1L)
329                     .ConfigureAwait(false);
330
331                 mock.VerifyAll();
332             }
333         }
334
335         [Fact]
336         public async Task ListsCreate_Test()
337         {
338             using (var twitterApi = new TwitterApi())
339             {
340                 var mock = new Mock<IApiConnection>();
341                 mock.Setup(x =>
342                     x.PostLazyAsync<TwitterList>(
343                         new Uri("lists/create.json", UriKind.Relative),
344                         new Dictionary<string, string> {
345                             { "name", "hogehoge" },
346                             { "description", "aaaa" },
347                             { "mode", "private" },
348                         })
349                 )
350                 .ReturnsAsync(LazyJson.Create(new TwitterList()));
351
352                 twitterApi.apiConnection = mock.Object;
353
354                 await twitterApi.ListsCreate("hogehoge", description: "aaaa", @private: true)
355                     .IgnoreResponse()
356                     .ConfigureAwait(false);
357
358                 mock.VerifyAll();
359             }
360         }
361
362         [Fact]
363         public async Task ListsUpdate_Test()
364         {
365             using (var twitterApi = new TwitterApi())
366             {
367                 var mock = new Mock<IApiConnection>();
368                 mock.Setup(x =>
369                     x.PostLazyAsync<TwitterList>(
370                         new Uri("lists/update.json", UriKind.Relative),
371                         new Dictionary<string, string> {
372                             { "list_id", "12345" },
373                             { "name", "hogehoge" },
374                             { "description", "aaaa" },
375                             { "mode", "private" },
376                         })
377                 )
378                 .ReturnsAsync(LazyJson.Create(new TwitterList()));
379
380                 twitterApi.apiConnection = mock.Object;
381
382                 await twitterApi.ListsUpdate(12345L, name: "hogehoge", description: "aaaa", @private: true)
383                     .IgnoreResponse()
384                     .ConfigureAwait(false);
385
386                 mock.VerifyAll();
387             }
388         }
389
390         [Fact]
391         public async Task ListsDestroy_Test()
392         {
393             using (var twitterApi = new TwitterApi())
394             {
395                 var mock = new Mock<IApiConnection>();
396                 mock.Setup(x =>
397                     x.PostLazyAsync<TwitterList>(
398                         new Uri("lists/destroy.json", UriKind.Relative),
399                         new Dictionary<string, string> {
400                             { "list_id", "12345" },
401                         })
402                 )
403                 .ReturnsAsync(LazyJson.Create(new TwitterList()));
404
405                 twitterApi.apiConnection = mock.Object;
406
407                 await twitterApi.ListsDestroy(12345L)
408                     .IgnoreResponse()
409                     .ConfigureAwait(false);
410
411                 mock.VerifyAll();
412             }
413         }
414
415         [Fact]
416         public async Task ListsStatuses_Test()
417         {
418             using (var twitterApi = new TwitterApi())
419             {
420                 var mock = new Mock<IApiConnection>();
421                 mock.Setup(x =>
422                     x.GetAsync<TwitterStatus[]>(
423                         new Uri("lists/statuses.json", UriKind.Relative),
424                         new Dictionary<string, string> {
425                             { "list_id", "12345" },
426                             { "include_entities", "true" },
427                             { "include_ext_alt_text", "true" },
428                             { "count", "200" },
429                             { "max_id", "900" },
430                             { "since_id", "100" },
431                             { "include_rts", "true" },
432                         },
433                         "/lists/statuses")
434                 )
435                 .ReturnsAsync(new TwitterStatus[0]);
436
437                 twitterApi.apiConnection = mock.Object;
438
439                 await twitterApi.ListsStatuses(12345L, count: 200, maxId: 900L, sinceId: 100L, includeRTs: true)
440                     .ConfigureAwait(false);
441
442                 mock.VerifyAll();
443             }
444         }
445
446         [Fact]
447         public async Task ListsMembers_Test()
448         {
449             using (var twitterApi = new TwitterApi())
450             {
451                 var mock = new Mock<IApiConnection>();
452                 mock.Setup(x =>
453                     x.GetAsync<TwitterUsers>(
454                         new Uri("lists/members.json", UriKind.Relative),
455                         new Dictionary<string, string> {
456                             { "list_id", "12345" },
457                             { "include_entities", "true" },
458                             { "include_ext_alt_text", "true" },
459                             { "cursor", "-1" },
460                         },
461                         "/lists/members")
462                 )
463                 .ReturnsAsync(new TwitterUsers());
464
465                 twitterApi.apiConnection = mock.Object;
466
467                 await twitterApi.ListsMembers(12345L, cursor: -1)
468                     .ConfigureAwait(false);
469
470                 mock.VerifyAll();
471             }
472         }
473
474         [Fact]
475         public async Task ListsMembersShow_Test()
476         {
477             using (var twitterApi = new TwitterApi())
478             {
479                 var mock = new Mock<IApiConnection>();
480                 mock.Setup(x =>
481                     x.GetAsync<TwitterUser>(
482                         new Uri("lists/members/show.json", UriKind.Relative),
483                         new Dictionary<string, string> {
484                             { "list_id", "12345" },
485                             { "screen_name", "twitterapi" },
486                             { "include_entities", "true" },
487                             { "include_ext_alt_text", "true" },
488                         },
489                         "/lists/members/show")
490                 )
491                 .ReturnsAsync(new TwitterUser());
492
493                 twitterApi.apiConnection = mock.Object;
494
495                 await twitterApi.ListsMembersShow(12345L, "twitterapi")
496                     .ConfigureAwait(false);
497
498                 mock.VerifyAll();
499             }
500         }
501
502         [Fact]
503         public async Task DirectMessagesRecv_Test()
504         {
505             using (var twitterApi = new TwitterApi())
506             {
507                 var mock = new Mock<IApiConnection>();
508                 mock.Setup(x =>
509                     x.GetAsync<TwitterDirectMessage[]>(
510                         new Uri("direct_messages.json", UriKind.Relative),
511                         new Dictionary<string, string> {
512                             { "full_text", "true" },
513                             { "include_entities", "true" },
514                             { "include_ext_alt_text", "true" },
515                             { "count", "200" },
516                             { "max_id", "900" },
517                             { "since_id", "100" },
518                         },
519                         "/direct_messages")
520                 )
521                 .ReturnsAsync(new TwitterDirectMessage[0]);
522
523                 twitterApi.apiConnection = mock.Object;
524
525                 await twitterApi.DirectMessagesRecv(count: 200, maxId: 900L, sinceId: 100L)
526                     .ConfigureAwait(false);
527
528                 mock.VerifyAll();
529             }
530         }
531
532         [Fact]
533         public async Task DirectMessagesSent_Test()
534         {
535             using (var twitterApi = new TwitterApi())
536             {
537                 var mock = new Mock<IApiConnection>();
538                 mock.Setup(x =>
539                     x.GetAsync<TwitterDirectMessage[]>(
540                         new Uri("direct_messages/sent.json", UriKind.Relative),
541                         new Dictionary<string, string> {
542                             { "full_text", "true" },
543                             { "include_entities", "true" },
544                             { "include_ext_alt_text", "true" },
545                             { "count", "200" },
546                             { "max_id", "900" },
547                             { "since_id", "100" },
548                         },
549                         "/direct_messages/sent")
550                 )
551                 .ReturnsAsync(new TwitterDirectMessage[0]);
552
553                 twitterApi.apiConnection = mock.Object;
554
555                 await twitterApi.DirectMessagesSent(count: 200, maxId: 900L, sinceId: 100L)
556                     .ConfigureAwait(false);
557
558                 mock.VerifyAll();
559             }
560         }
561
562         [Fact]
563         public async Task DirectMessagesNew_Test()
564         {
565             using (var twitterApi = new TwitterApi())
566             {
567                 var mock = new Mock<IApiConnection>();
568                 mock.Setup(x =>
569                     x.PostLazyAsync<TwitterDirectMessage>(
570                         new Uri("direct_messages/new.json", UriKind.Relative),
571                         new Dictionary<string, string> {
572                             { "text", "hogehoge" },
573                             { "screen_name", "opentween" },
574                         })
575                 )
576                 .ReturnsAsync(LazyJson.Create(new TwitterDirectMessage()));
577
578                 twitterApi.apiConnection = mock.Object;
579
580                 await twitterApi.DirectMessagesNew("hogehoge", "opentween")
581                     .IgnoreResponse()
582                     .ConfigureAwait(false);
583
584                 mock.VerifyAll();
585             }
586         }
587
588         [Fact]
589         public async Task DirectMessagesDestroy_Test()
590         {
591             using (var twitterApi = new TwitterApi())
592             {
593                 var mock = new Mock<IApiConnection>();
594                 mock.Setup(x =>
595                     x.PostLazyAsync<TwitterDirectMessage>(
596                         new Uri("direct_messages/destroy.json", UriKind.Relative),
597                         new Dictionary<string, string> { { "id", "100" } })
598                 )
599                 .ReturnsAsync(LazyJson.Create(new TwitterDirectMessage { Id = 100L }));
600
601                 twitterApi.apiConnection = mock.Object;
602
603                 await twitterApi.DirectMessagesDestroy(statusId: 100L)
604                     .IgnoreResponse()
605                     .ConfigureAwait(false);
606
607                 mock.VerifyAll();
608             }
609         }
610
611         [Fact]
612         public async Task UsersShow_Test()
613         {
614             using (var twitterApi = new TwitterApi())
615             {
616                 var mock = new Mock<IApiConnection>();
617                 mock.Setup(x =>
618                     x.GetAsync<TwitterUser>(
619                         new Uri("users/show.json", UriKind.Relative),
620                         new Dictionary<string, string> {
621                             { "screen_name", "twitterapi" },
622                             { "include_entities", "true" },
623                             { "include_ext_alt_text", "true" },
624                         },
625                         "/users/show/:id")
626                 )
627                 .ReturnsAsync(new TwitterUser { ScreenName = "twitterapi" });
628
629                 twitterApi.apiConnection = mock.Object;
630
631                 await twitterApi.UsersShow(screenName: "twitterapi")
632                     .ConfigureAwait(false);
633
634                 mock.VerifyAll();
635             }
636         }
637
638         [Fact]
639         public async Task UsersReportSpam_Test()
640         {
641             using (var twitterApi = new TwitterApi())
642             {
643                 var mock = new Mock<IApiConnection>();
644                 mock.Setup(x =>
645                     x.PostLazyAsync<TwitterUser>(
646                         new Uri("users/report_spam.json", UriKind.Relative),
647                         new Dictionary<string, string> { { "screen_name", "twitterapi" } })
648                 )
649                 .ReturnsAsync(LazyJson.Create(new TwitterUser { ScreenName = "twitterapi" }));
650
651                 twitterApi.apiConnection = mock.Object;
652
653                 await twitterApi.UsersReportSpam(screenName: "twitterapi")
654                     .IgnoreResponse()
655                     .ConfigureAwait(false);
656
657                 mock.VerifyAll();
658             }
659         }
660
661         [Fact]
662         public async Task FavoritesCreate_Test()
663         {
664             using (var twitterApi = new TwitterApi())
665             {
666                 var mock = new Mock<IApiConnection>();
667                 mock.Setup(x =>
668                     x.PostLazyAsync<TwitterStatus>(
669                         new Uri("favorites/create.json", UriKind.Relative),
670                         new Dictionary<string, string> { { "id", "100" } })
671                 )
672                 .ReturnsAsync(LazyJson.Create(new TwitterStatus { Id = 100L }));
673
674                 twitterApi.apiConnection = mock.Object;
675
676                 await twitterApi.FavoritesCreate(statusId: 100L)
677                     .IgnoreResponse()
678                     .ConfigureAwait(false);
679
680                 mock.VerifyAll();
681             }
682         }
683
684         [Fact]
685         public async Task FavoritesDestroy_Test()
686         {
687             using (var twitterApi = new TwitterApi())
688             {
689                 var mock = new Mock<IApiConnection>();
690                 mock.Setup(x =>
691                     x.PostLazyAsync<TwitterStatus>(
692                         new Uri("favorites/destroy.json", UriKind.Relative),
693                         new Dictionary<string, string> { { "id", "100" } })
694                 )
695                 .ReturnsAsync(LazyJson.Create(new TwitterStatus { Id = 100L }));
696
697                 twitterApi.apiConnection = mock.Object;
698
699                 await twitterApi.FavoritesDestroy(statusId: 100L)
700                     .IgnoreResponse()
701                     .ConfigureAwait(false);
702
703                 mock.VerifyAll();
704             }
705         }
706
707         [Fact]
708         public async Task FriendshipsShow_Test()
709         {
710             using (var twitterApi = new TwitterApi())
711             {
712                 var mock = new Mock<IApiConnection>();
713                 mock.Setup(x =>
714                     x.GetAsync<TwitterFriendship>(
715                         new Uri("friendships/show.json", UriKind.Relative),
716                         new Dictionary<string, string> { { "source_screen_name", "twitter" }, { "target_screen_name", "twitterapi" } },
717                         "/friendships/show")
718                 )
719                 .ReturnsAsync(new TwitterFriendship());
720
721                 twitterApi.apiConnection = mock.Object;
722
723                 await twitterApi.FriendshipsShow(sourceScreenName: "twitter", targetScreenName: "twitterapi")
724                     .ConfigureAwait(false);
725
726                 mock.VerifyAll();
727             }
728         }
729
730         [Fact]
731         public async Task FriendshipsCreate_Test()
732         {
733             using (var twitterApi = new TwitterApi())
734             {
735                 var mock = new Mock<IApiConnection>();
736                 mock.Setup(x =>
737                     x.PostLazyAsync<TwitterFriendship>(
738                         new Uri("friendships/create.json", UriKind.Relative),
739                         new Dictionary<string, string> { { "screen_name", "twitterapi" } })
740                 )
741                 .ReturnsAsync(LazyJson.Create(new TwitterFriendship()));
742
743                 twitterApi.apiConnection = mock.Object;
744
745                 await twitterApi.FriendshipsCreate(screenName: "twitterapi")
746                     .IgnoreResponse()
747                     .ConfigureAwait(false);
748
749                 mock.VerifyAll();
750             }
751         }
752
753         [Fact]
754         public async Task FriendshipsDestroy_Test()
755         {
756             using (var twitterApi = new TwitterApi())
757             {
758                 var mock = new Mock<IApiConnection>();
759                 mock.Setup(x =>
760                     x.PostLazyAsync<TwitterFriendship>(
761                         new Uri("friendships/destroy.json", UriKind.Relative),
762                         new Dictionary<string, string> { { "screen_name", "twitterapi" } })
763                 )
764                 .ReturnsAsync(LazyJson.Create(new TwitterFriendship()));
765
766                 twitterApi.apiConnection = mock.Object;
767
768                 await twitterApi.FriendshipsDestroy(screenName: "twitterapi")
769                     .IgnoreResponse()
770                     .ConfigureAwait(false);
771
772                 mock.VerifyAll();
773             }
774         }
775
776         [Fact]
777         public async Task NoRetweetIds_Test()
778         {
779             using (var twitterApi = new TwitterApi())
780             {
781                 var mock = new Mock<IApiConnection>();
782                 mock.Setup(x =>
783                     x.GetAsync<long[]>(
784                         new Uri("friendships/no_retweets/ids.json", UriKind.Relative),
785                         null,
786                         "/friendships/no_retweets/ids")
787                 )
788                 .ReturnsAsync(new long[0]);
789
790                 twitterApi.apiConnection = mock.Object;
791
792                 await twitterApi.NoRetweetIds()
793                     .ConfigureAwait(false);
794
795                 mock.VerifyAll();
796             }
797         }
798
799         [Fact]
800         public async Task FollowersIds_Test()
801         {
802             using (var twitterApi = new TwitterApi())
803             {
804                 var mock = new Mock<IApiConnection>();
805                 mock.Setup(x =>
806                     x.GetAsync<TwitterIds>(
807                         new Uri("followers/ids.json", UriKind.Relative),
808                         new Dictionary<string, string> { { "cursor", "-1" } },
809                         "/followers/ids")
810                 )
811                 .ReturnsAsync(new TwitterIds());
812
813                 twitterApi.apiConnection = mock.Object;
814
815                 await twitterApi.FollowersIds(cursor: -1L)
816                     .ConfigureAwait(false);
817
818                 mock.VerifyAll();
819             }
820         }
821
822         [Fact]
823         public async Task MutesUsersIds_Test()
824         {
825             using (var twitterApi = new TwitterApi())
826             {
827                 var mock = new Mock<IApiConnection>();
828                 mock.Setup(x =>
829                     x.GetAsync<TwitterIds>(
830                         new Uri("mutes/users/ids.json", UriKind.Relative),
831                         new Dictionary<string, string> { { "cursor", "-1" } },
832                         "/mutes/users/ids")
833                 )
834                 .ReturnsAsync(new TwitterIds());
835
836                 twitterApi.apiConnection = mock.Object;
837
838                 await twitterApi.MutesUsersIds(cursor: -1L)
839                     .ConfigureAwait(false);
840
841                 mock.VerifyAll();
842             }
843         }
844
845         [Fact]
846         public async Task BlocksIds_Test()
847         {
848             using (var twitterApi = new TwitterApi())
849             {
850                 var mock = new Mock<IApiConnection>();
851                 mock.Setup(x =>
852                     x.GetAsync<TwitterIds>(
853                         new Uri("blocks/ids.json", UriKind.Relative),
854                         new Dictionary<string, string> { { "cursor", "-1" } },
855                         "/blocks/ids")
856                 )
857                 .ReturnsAsync(new TwitterIds());
858
859                 twitterApi.apiConnection = mock.Object;
860
861                 await twitterApi.BlocksIds(cursor: -1L)
862                     .ConfigureAwait(false);
863
864                 mock.VerifyAll();
865             }
866         }
867
868         [Fact]
869         public async Task BlocksCreate_Test()
870         {
871             using (var twitterApi = new TwitterApi())
872             {
873                 var mock = new Mock<IApiConnection>();
874                 mock.Setup(x =>
875                     x.PostLazyAsync<TwitterUser>(
876                         new Uri("blocks/create.json", UriKind.Relative),
877                         new Dictionary<string, string> { { "screen_name", "twitterapi" } })
878                 )
879                 .ReturnsAsync(LazyJson.Create(new TwitterUser()));
880
881                 twitterApi.apiConnection = mock.Object;
882
883                 await twitterApi.BlocksCreate(screenName: "twitterapi")
884                     .IgnoreResponse()
885                     .ConfigureAwait(false);
886
887                 mock.VerifyAll();
888             }
889         }
890
891         [Fact]
892         public async Task BlocksDestroy_Test()
893         {
894             using (var twitterApi = new TwitterApi())
895             {
896                 var mock = new Mock<IApiConnection>();
897                 mock.Setup(x =>
898                     x.PostLazyAsync<TwitterUser>(
899                         new Uri("blocks/destroy.json", UriKind.Relative),
900                         new Dictionary<string, string> { { "screen_name", "twitterapi" } })
901                 )
902                 .ReturnsAsync(LazyJson.Create(new TwitterUser()));
903
904                 twitterApi.apiConnection = mock.Object;
905
906                 await twitterApi.BlocksDestroy(screenName: "twitterapi")
907                     .IgnoreResponse()
908                     .ConfigureAwait(false);
909
910                 mock.VerifyAll();
911             }
912         }
913
914         [Fact]
915         public async Task AccountUpdateProfile_Test()
916         {
917             using (var twitterApi = new TwitterApi())
918             {
919                 var mock = new Mock<IApiConnection>();
920                 mock.Setup(x =>
921                     x.PostLazyAsync<TwitterUser>(
922                         new Uri("account/update_profile.json", UriKind.Relative),
923                         new Dictionary<string, string> {
924                             { "include_entities", "true" },
925                             { "include_ext_alt_text", "true" },
926                             { "name", "Name" },
927                             { "url", "http://example.com/" },
928                             { "location", "Location" },
929                             { "description", "&lt;script&gt;alert(1)&lt;/script&gt;" },
930                         })
931                 )
932                 .ReturnsAsync(LazyJson.Create(new TwitterUser()));
933
934                 twitterApi.apiConnection = mock.Object;
935
936                 await twitterApi.AccountUpdateProfile(name: "Name", url: "http://example.com/", location: "Location", description: "<script>alert(1)</script>")
937                     .IgnoreResponse()
938                     .ConfigureAwait(false);
939
940                 mock.VerifyAll();
941             }
942         }
943
944         [Fact]
945         public async Task AccountUpdateProfileImage_Test()
946         {
947             using (var twitterApi = new TwitterApi())
948             using (var image = TestUtils.CreateDummyImage())
949             using (var media = new MemoryImageMediaItem(image))
950             {
951                 var mock = new Mock<IApiConnection>();
952                 mock.Setup(x =>
953                     x.PostLazyAsync<TwitterUser>(
954                         new Uri("account/update_profile_image.json", UriKind.Relative),
955                         new Dictionary<string, string> {
956                             { "include_entities", "true" },
957                             { "include_ext_alt_text", "true" },
958                         },
959                         new Dictionary<string, IMediaItem> { { "image", media } })
960                 )
961                 .ReturnsAsync(LazyJson.Create(new TwitterUser()));
962
963                 twitterApi.apiConnection = mock.Object;
964
965                 await twitterApi.AccountUpdateProfileImage(media)
966                     .IgnoreResponse()
967                     .ConfigureAwait(false);
968
969                 mock.VerifyAll();
970             }
971         }
972
973         [Fact]
974         public async Task ApplicationRateLimitStatus_Test()
975         {
976             using (var twitterApi = new TwitterApi())
977             {
978                 var mock = new Mock<IApiConnection>();
979                 mock.Setup(x =>
980                     x.GetAsync<TwitterRateLimits>(
981                         new Uri("application/rate_limit_status.json", UriKind.Relative),
982                         null,
983                         "/application/rate_limit_status")
984                 )
985                 .ReturnsAsync(new TwitterRateLimits());
986
987                 twitterApi.apiConnection = mock.Object;
988
989                 await twitterApi.ApplicationRateLimitStatus()
990                     .ConfigureAwait(false);
991
992                 mock.VerifyAll();
993             }
994         }
995
996         [Fact]
997         public async Task Configuration_Test()
998         {
999             using (var twitterApi = new TwitterApi())
1000             {
1001                 var mock = new Mock<IApiConnection>();
1002                 mock.Setup(x =>
1003                     x.GetAsync<TwitterConfiguration>(
1004                         new Uri("help/configuration.json", UriKind.Relative),
1005                         null,
1006                         "/help/configuration")
1007                 )
1008                 .ReturnsAsync(new TwitterConfiguration());
1009
1010                 twitterApi.apiConnection = mock.Object;
1011
1012                 await twitterApi.Configuration()
1013                     .ConfigureAwait(false);
1014
1015                 mock.VerifyAll();
1016             }
1017         }
1018
1019         [Fact]
1020         public async Task MediaUpload_Test()
1021         {
1022             using (var twitterApi = new TwitterApi())
1023             using (var image = TestUtils.CreateDummyImage())
1024             using (var media = new MemoryImageMediaItem(image))
1025             {
1026                 var mock = new Mock<IApiConnection>();
1027                 mock.Setup(x =>
1028                     x.PostLazyAsync<TwitterUploadMediaResult>(
1029                         new Uri("https://upload.twitter.com/1.1/media/upload.json", UriKind.Absolute),
1030                         null,
1031                         new Dictionary<string, IMediaItem> { { "media", media } })
1032                 )
1033                 .ReturnsAsync(LazyJson.Create(new TwitterUploadMediaResult()));
1034
1035                 twitterApi.apiConnection = mock.Object;
1036
1037                 await twitterApi.MediaUpload(media)
1038                     .IgnoreResponse()
1039                     .ConfigureAwait(false);
1040
1041                 mock.VerifyAll();
1042             }
1043         }
1044
1045         [Fact]
1046         public async Task UserStreams_Test()
1047         {
1048             using (var twitterApi = new TwitterApi())
1049             {
1050                 var mock = new Mock<IApiConnection>();
1051                 mock.Setup(x =>
1052                     x.GetStreamAsync(
1053                         new Uri("https://userstream.twitter.com/1.1/user.json", UriKind.Absolute),
1054                         new Dictionary<string, string> {
1055                             { "replies", "all" },
1056                             { "track", "OpenTween" },
1057                         })
1058                 )
1059                 .ReturnsAsync(new MemoryStream());
1060
1061                 twitterApi.apiConnection = mock.Object;
1062
1063                 var stream = await twitterApi.UserStreams(replies: "all", track: "OpenTween")
1064                     .ConfigureAwait(false);
1065
1066                 stream.Dispose();
1067
1068                 mock.VerifyAll();
1069             }
1070         }
1071     }
1072 }