OSDN Git Service

HttpTwitter.DirectMessage/DirectMessageSentを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.Linq;
25 using System.Net.Http;
26 using System.Reflection;
27 using System.Runtime.InteropServices;
28 using System.Text;
29 using System.Threading.Tasks;
30 using Moq;
31 using OpenTween.Api.DataModel;
32 using OpenTween.Connection;
33 using Xunit;
34
35 namespace OpenTween.Api
36 {
37     public class TwitterApiTest
38     {
39         public TwitterApiTest()
40         {
41             this.MyCommonSetup();
42         }
43
44         public void MyCommonSetup()
45         {
46             var mockAssembly = new Mock<_Assembly>();
47             mockAssembly.Setup(m => m.GetName()).Returns(new AssemblyName("OpenTween"));
48
49             MyCommon.EntryAssembly = mockAssembly.Object;
50         }
51
52         [Fact]
53         public void Initialize_Test()
54         {
55             using (var twitterApi = new TwitterApi())
56             {
57                 Assert.Null(twitterApi.apiConnection);
58
59                 twitterApi.Initialize("*** AccessToken ***", "*** AccessSecret ***", userId: 100L, screenName: "hogehoge");
60
61                 Assert.IsType<TwitterApiConnection>(twitterApi.apiConnection);
62
63                 var apiConnection = (TwitterApiConnection)twitterApi.apiConnection;
64                 Assert.Equal("*** AccessToken ***", apiConnection.AccessToken);
65                 Assert.Equal("*** AccessSecret ***", apiConnection.AccessSecret);
66
67                 Assert.Equal(100L, twitterApi.CurrentUserId);
68                 Assert.Equal("hogehoge", twitterApi.CurrentScreenName);
69
70                 // 複数回 Initialize を実行した場合は新たに TwitterApiConnection が生成される
71                 twitterApi.Initialize("*** AccessToken2 ***", "*** AccessSecret2 ***", userId: 200L, screenName: "foobar");
72
73                 var oldApiConnection = apiConnection;
74                 Assert.True(oldApiConnection.IsDisposed);
75
76                 Assert.IsType<TwitterApiConnection>(twitterApi.apiConnection);
77
78                 apiConnection = (TwitterApiConnection)twitterApi.apiConnection;
79                 Assert.Equal("*** AccessToken2 ***", apiConnection.AccessToken);
80                 Assert.Equal("*** AccessSecret2 ***", apiConnection.AccessSecret);
81
82                 Assert.Equal(200L, twitterApi.CurrentUserId);
83                 Assert.Equal("foobar", twitterApi.CurrentScreenName);
84             }
85         }
86
87         [Fact]
88         public async Task StatusesHomeTimeline_Test()
89         {
90             using (var twitterApi = new TwitterApi())
91             {
92                 var mock = new Mock<IApiConnection>();
93                 mock.Setup(x =>
94                     x.GetAsync<TwitterStatus[]>(
95                         new Uri("statuses/home_timeline.json", UriKind.Relative),
96                         new Dictionary<string, string> {
97                             { "include_entities", "true" },
98                             { "include_ext_alt_text", "true" },
99                             { "count", "200" },
100                             { "max_id", "900" },
101                             { "since_id", "100" },
102                         },
103                         "/statuses/home_timeline")
104                 )
105                 .ReturnsAsync(new TwitterStatus[0]);
106
107                 twitterApi.apiConnection = mock.Object;
108
109                 await twitterApi.StatusesHomeTimeline(200, maxId: 900L, sinceId: 100L)
110                     .ConfigureAwait(false);
111
112                 mock.VerifyAll();
113             }
114         }
115
116         [Fact]
117         public async Task StatusesMentionsTimeline_Test()
118         {
119             using (var twitterApi = new TwitterApi())
120             {
121                 var mock = new Mock<IApiConnection>();
122                 mock.Setup(x =>
123                     x.GetAsync<TwitterStatus[]>(
124                         new Uri("statuses/mentions_timeline.json", UriKind.Relative),
125                         new Dictionary<string, string> {
126                             { "include_entities", "true" },
127                             { "include_ext_alt_text", "true" },
128                             { "count", "200" },
129                             { "max_id", "900" },
130                             { "since_id", "100" },
131                         },
132                         "/statuses/mentions_timeline")
133                 )
134                 .ReturnsAsync(new TwitterStatus[0]);
135
136                 twitterApi.apiConnection = mock.Object;
137
138                 await twitterApi.StatusesMentionsTimeline(200, maxId: 900L, sinceId: 100L)
139                     .ConfigureAwait(false);
140
141                 mock.VerifyAll();
142             }
143         }
144
145         [Fact]
146         public async Task StatusesUserTimeline_Test()
147         {
148             using (var twitterApi = new TwitterApi())
149             {
150                 var mock = new Mock<IApiConnection>();
151                 mock.Setup(x =>
152                     x.GetAsync<TwitterStatus[]>(
153                         new Uri("statuses/user_timeline.json", UriKind.Relative),
154                         new Dictionary<string, string> {
155                             { "screen_name", "twitterapi" },
156                             { "include_rts", "true" },
157                             { "include_entities", "true" },
158                             { "include_ext_alt_text", "true" },
159                             { "count", "200" },
160                             { "max_id", "900" },
161                             { "since_id", "100" },
162                         },
163                         "/statuses/user_timeline")
164                 )
165                 .ReturnsAsync(new TwitterStatus[0]);
166
167                 twitterApi.apiConnection = mock.Object;
168
169                 await twitterApi.StatusesUserTimeline("twitterapi", count: 200, maxId: 900L, sinceId: 100L)
170                     .ConfigureAwait(false);
171
172                 mock.VerifyAll();
173             }
174         }
175
176         [Fact]
177         public async Task StatusesShow_Test()
178         {
179             using (var twitterApi = new TwitterApi())
180             {
181                 var mock = new Mock<IApiConnection>();
182                 mock.Setup(x =>
183                     x.GetAsync<TwitterStatus>(
184                         new Uri("statuses/show.json", UriKind.Relative),
185                         new Dictionary<string, string> {
186                             { "id", "100" },
187                             { "include_entities", "true" },
188                             { "include_ext_alt_text", "true" },
189                         },
190                         "/statuses/show/:id")
191                 )
192                 .ReturnsAsync(new TwitterStatus { Id = 100L });
193
194                 twitterApi.apiConnection = mock.Object;
195
196                 await twitterApi.StatusesShow(statusId: 100L)
197                     .ConfigureAwait(false);
198
199                 mock.VerifyAll();
200             }
201         }
202
203         [Fact]
204         public async Task StatusesUpdate_Test()
205         {
206             using (var twitterApi = new TwitterApi())
207             {
208                 var mock = new Mock<IApiConnection>();
209                 mock.Setup(x =>
210                     x.PostLazyAsync<TwitterStatus>(
211                         new Uri("statuses/update.json", UriKind.Relative),
212                         new Dictionary<string, string> {
213                             { "status", "hogehoge" },
214                             { "include_entities", "true" },
215                             { "include_ext_alt_text", "true" },
216                             { "in_reply_to_status_id", "100" },
217                             { "media_ids", "10,20" },
218                         })
219                 )
220                 .ReturnsAsync(LazyJson.Create(new TwitterStatus()));
221
222                 twitterApi.apiConnection = mock.Object;
223
224                 await twitterApi.StatusesUpdate("hogehoge", replyToId: 100L, mediaIds: new[] { 10L, 20L })
225                     .IgnoreResponse()
226                     .ConfigureAwait(false);
227
228                 mock.VerifyAll();
229             }
230         }
231
232         [Fact]
233         public async Task StatusesDestroy_Test()
234         {
235             using (var twitterApi = new TwitterApi())
236             {
237                 var mock = new Mock<IApiConnection>();
238                 mock.Setup(x =>
239                     x.PostLazyAsync<TwitterStatus>(
240                         new Uri("statuses/destroy.json", UriKind.Relative),
241                         new Dictionary<string, string> { { "id", "100" } })
242                 )
243                 .ReturnsAsync(LazyJson.Create(new TwitterStatus { Id = 100L }));
244
245                 twitterApi.apiConnection = mock.Object;
246
247                 await twitterApi.StatusesDestroy(statusId: 100L)
248                     .IgnoreResponse()
249                     .ConfigureAwait(false);
250
251                 mock.VerifyAll();
252             }
253         }
254
255         [Fact]
256         public async Task StatusesRetweet_Test()
257         {
258             using (var twitterApi = new TwitterApi())
259             {
260                 var mock = new Mock<IApiConnection>();
261                 mock.Setup(x =>
262                     x.PostLazyAsync<TwitterStatus>(
263                         new Uri("statuses/retweet.json", UriKind.Relative),
264                         new Dictionary<string, string> {
265                             { "id", "100" },
266                             { "include_entities", "true" },
267                             { "include_ext_alt_text", "true" },
268                         })
269                 )
270                 .ReturnsAsync(LazyJson.Create(new TwitterStatus()));
271
272                 twitterApi.apiConnection = mock.Object;
273
274                 await twitterApi.StatusesRetweet(100L)
275                     .IgnoreResponse()
276                     .ConfigureAwait(false);
277
278                 mock.VerifyAll();
279             }
280         }
281
282         [Fact]
283         public async Task ListsStatuses_Test()
284         {
285             using (var twitterApi = new TwitterApi())
286             {
287                 var mock = new Mock<IApiConnection>();
288                 mock.Setup(x =>
289                     x.GetAsync<TwitterStatus[]>(
290                         new Uri("lists/statuses.json", UriKind.Relative),
291                         new Dictionary<string, string> {
292                             { "list_id", "12345" },
293                             { "include_entities", "true" },
294                             { "include_ext_alt_text", "true" },
295                             { "count", "200" },
296                             { "max_id", "900" },
297                             { "since_id", "100" },
298                             { "include_rts", "true" },
299                         },
300                         "/lists/statuses")
301                 )
302                 .ReturnsAsync(new TwitterStatus[0]);
303
304                 twitterApi.apiConnection = mock.Object;
305
306                 await twitterApi.ListsStatuses(12345L, count: 200, maxId: 900L, sinceId: 100L, includeRTs: true)
307                     .ConfigureAwait(false);
308
309                 mock.VerifyAll();
310             }
311         }
312
313         [Fact]
314         public async Task DirectMessagesRecv_Test()
315         {
316             using (var twitterApi = new TwitterApi())
317             {
318                 var mock = new Mock<IApiConnection>();
319                 mock.Setup(x =>
320                     x.GetAsync<TwitterDirectMessage[]>(
321                         new Uri("direct_messages.json", UriKind.Relative),
322                         new Dictionary<string, string> {
323                             { "full_text", "true" },
324                             { "include_entities", "true" },
325                             { "include_ext_alt_text", "true" },
326                             { "count", "200" },
327                             { "max_id", "900" },
328                             { "since_id", "100" },
329                         },
330                         "/direct_messages")
331                 )
332                 .ReturnsAsync(new TwitterDirectMessage[0]);
333
334                 twitterApi.apiConnection = mock.Object;
335
336                 await twitterApi.DirectMessagesRecv(count: 200, maxId: 900L, sinceId: 100L)
337                     .ConfigureAwait(false);
338
339                 mock.VerifyAll();
340             }
341         }
342
343         [Fact]
344         public async Task DirectMessagesSent_Test()
345         {
346             using (var twitterApi = new TwitterApi())
347             {
348                 var mock = new Mock<IApiConnection>();
349                 mock.Setup(x =>
350                     x.GetAsync<TwitterDirectMessage[]>(
351                         new Uri("direct_messages/sent.json", UriKind.Relative),
352                         new Dictionary<string, string> {
353                             { "full_text", "true" },
354                             { "include_entities", "true" },
355                             { "include_ext_alt_text", "true" },
356                             { "count", "200" },
357                             { "max_id", "900" },
358                             { "since_id", "100" },
359                         },
360                         "/direct_messages/sent")
361                 )
362                 .ReturnsAsync(new TwitterDirectMessage[0]);
363
364                 twitterApi.apiConnection = mock.Object;
365
366                 await twitterApi.DirectMessagesSent(count: 200, maxId: 900L, sinceId: 100L)
367                     .ConfigureAwait(false);
368
369                 mock.VerifyAll();
370             }
371         }
372
373         [Fact]
374         public async Task DirectMessagesNew_Test()
375         {
376             using (var twitterApi = new TwitterApi())
377             {
378                 var mock = new Mock<IApiConnection>();
379                 mock.Setup(x =>
380                     x.PostLazyAsync<TwitterDirectMessage>(
381                         new Uri("direct_messages/new.json", UriKind.Relative),
382                         new Dictionary<string, string> {
383                             { "text", "hogehoge" },
384                             { "screen_name", "opentween" },
385                         })
386                 )
387                 .ReturnsAsync(LazyJson.Create(new TwitterDirectMessage()));
388
389                 twitterApi.apiConnection = mock.Object;
390
391                 await twitterApi.DirectMessagesNew("hogehoge", "opentween")
392                     .IgnoreResponse()
393                     .ConfigureAwait(false);
394
395                 mock.VerifyAll();
396             }
397         }
398
399         [Fact]
400         public async Task DirectMessagesDestroy_Test()
401         {
402             using (var twitterApi = new TwitterApi())
403             {
404                 var mock = new Mock<IApiConnection>();
405                 mock.Setup(x =>
406                     x.PostLazyAsync<TwitterDirectMessage>(
407                         new Uri("direct_messages/destroy.json", UriKind.Relative),
408                         new Dictionary<string, string> { { "id", "100" } })
409                 )
410                 .ReturnsAsync(LazyJson.Create(new TwitterDirectMessage { Id = 100L }));
411
412                 twitterApi.apiConnection = mock.Object;
413
414                 await twitterApi.DirectMessagesDestroy(statusId: 100L)
415                     .IgnoreResponse()
416                     .ConfigureAwait(false);
417
418                 mock.VerifyAll();
419             }
420         }
421
422         [Fact]
423         public async Task UsersShow_Test()
424         {
425             using (var twitterApi = new TwitterApi())
426             {
427                 var mock = new Mock<IApiConnection>();
428                 mock.Setup(x =>
429                     x.GetAsync<TwitterUser>(
430                         new Uri("users/show.json", UriKind.Relative),
431                         new Dictionary<string, string> {
432                             { "screen_name", "twitterapi" },
433                             { "include_entities", "true" },
434                             { "include_ext_alt_text", "true" },
435                         },
436                         "/users/show/:id")
437                 )
438                 .ReturnsAsync(new TwitterUser { ScreenName = "twitterapi" });
439
440                 twitterApi.apiConnection = mock.Object;
441
442                 await twitterApi.UsersShow(screenName: "twitterapi")
443                     .ConfigureAwait(false);
444
445                 mock.VerifyAll();
446             }
447         }
448
449         [Fact]
450         public async Task UsersReportSpam_Test()
451         {
452             using (var twitterApi = new TwitterApi())
453             {
454                 var mock = new Mock<IApiConnection>();
455                 mock.Setup(x =>
456                     x.PostLazyAsync<TwitterUser>(
457                         new Uri("users/report_spam.json", UriKind.Relative),
458                         new Dictionary<string, string> { { "screen_name", "twitterapi" } })
459                 )
460                 .ReturnsAsync(LazyJson.Create(new TwitterUser { ScreenName = "twitterapi" }));
461
462                 twitterApi.apiConnection = mock.Object;
463
464                 await twitterApi.UsersReportSpam(screenName: "twitterapi")
465                     .IgnoreResponse()
466                     .ConfigureAwait(false);
467
468                 mock.VerifyAll();
469             }
470         }
471
472         [Fact]
473         public async Task FavoritesCreate_Test()
474         {
475             using (var twitterApi = new TwitterApi())
476             {
477                 var mock = new Mock<IApiConnection>();
478                 mock.Setup(x =>
479                     x.PostLazyAsync<TwitterStatus>(
480                         new Uri("favorites/create.json", UriKind.Relative),
481                         new Dictionary<string, string> { { "id", "100" } })
482                 )
483                 .ReturnsAsync(LazyJson.Create(new TwitterStatus { Id = 100L }));
484
485                 twitterApi.apiConnection = mock.Object;
486
487                 await twitterApi.FavoritesCreate(statusId: 100L)
488                     .IgnoreResponse()
489                     .ConfigureAwait(false);
490
491                 mock.VerifyAll();
492             }
493         }
494
495         [Fact]
496         public async Task FavoritesDestroy_Test()
497         {
498             using (var twitterApi = new TwitterApi())
499             {
500                 var mock = new Mock<IApiConnection>();
501                 mock.Setup(x =>
502                     x.PostLazyAsync<TwitterStatus>(
503                         new Uri("favorites/destroy.json", UriKind.Relative),
504                         new Dictionary<string, string> { { "id", "100" } })
505                 )
506                 .ReturnsAsync(LazyJson.Create(new TwitterStatus { Id = 100L }));
507
508                 twitterApi.apiConnection = mock.Object;
509
510                 await twitterApi.FavoritesDestroy(statusId: 100L)
511                     .IgnoreResponse()
512                     .ConfigureAwait(false);
513
514                 mock.VerifyAll();
515             }
516         }
517
518         [Fact]
519         public async Task FriendshipsShow_Test()
520         {
521             using (var twitterApi = new TwitterApi())
522             {
523                 var mock = new Mock<IApiConnection>();
524                 mock.Setup(x =>
525                     x.GetAsync<TwitterFriendship>(
526                         new Uri("friendships/show.json", UriKind.Relative),
527                         new Dictionary<string, string> { { "source_screen_name", "twitter" }, { "target_screen_name", "twitterapi" } },
528                         "/friendships/show")
529                 )
530                 .ReturnsAsync(new TwitterFriendship());
531
532                 twitterApi.apiConnection = mock.Object;
533
534                 await twitterApi.FriendshipsShow(sourceScreenName: "twitter", targetScreenName: "twitterapi")
535                     .ConfigureAwait(false);
536
537                 mock.VerifyAll();
538             }
539         }
540
541         [Fact]
542         public async Task FriendshipsCreate_Test()
543         {
544             using (var twitterApi = new TwitterApi())
545             {
546                 var mock = new Mock<IApiConnection>();
547                 mock.Setup(x =>
548                     x.PostLazyAsync<TwitterFriendship>(
549                         new Uri("friendships/create.json", UriKind.Relative),
550                         new Dictionary<string, string> { { "screen_name", "twitterapi" } })
551                 )
552                 .ReturnsAsync(LazyJson.Create(new TwitterFriendship()));
553
554                 twitterApi.apiConnection = mock.Object;
555
556                 await twitterApi.FriendshipsCreate(screenName: "twitterapi")
557                     .IgnoreResponse()
558                     .ConfigureAwait(false);
559
560                 mock.VerifyAll();
561             }
562         }
563
564         [Fact]
565         public async Task FriendshipsDestroy_Test()
566         {
567             using (var twitterApi = new TwitterApi())
568             {
569                 var mock = new Mock<IApiConnection>();
570                 mock.Setup(x =>
571                     x.PostLazyAsync<TwitterFriendship>(
572                         new Uri("friendships/destroy.json", UriKind.Relative),
573                         new Dictionary<string, string> { { "screen_name", "twitterapi" } })
574                 )
575                 .ReturnsAsync(LazyJson.Create(new TwitterFriendship()));
576
577                 twitterApi.apiConnection = mock.Object;
578
579                 await twitterApi.FriendshipsDestroy(screenName: "twitterapi")
580                     .IgnoreResponse()
581                     .ConfigureAwait(false);
582
583                 mock.VerifyAll();
584             }
585         }
586
587         [Fact]
588         public async Task NoRetweetIds_Test()
589         {
590             using (var twitterApi = new TwitterApi())
591             {
592                 var mock = new Mock<IApiConnection>();
593                 mock.Setup(x =>
594                     x.GetAsync<long[]>(
595                         new Uri("friendships/no_retweets/ids.json", UriKind.Relative),
596                         null,
597                         "/friendships/no_retweets/ids")
598                 )
599                 .ReturnsAsync(new long[0]);
600
601                 twitterApi.apiConnection = mock.Object;
602
603                 await twitterApi.NoRetweetIds()
604                     .ConfigureAwait(false);
605
606                 mock.VerifyAll();
607             }
608         }
609
610         [Fact]
611         public async Task FollowersIds_Test()
612         {
613             using (var twitterApi = new TwitterApi())
614             {
615                 var mock = new Mock<IApiConnection>();
616                 mock.Setup(x =>
617                     x.GetAsync<TwitterIds>(
618                         new Uri("followers/ids.json", UriKind.Relative),
619                         new Dictionary<string, string> { { "cursor", "-1" } },
620                         "/followers/ids")
621                 )
622                 .ReturnsAsync(new TwitterIds());
623
624                 twitterApi.apiConnection = mock.Object;
625
626                 await twitterApi.FollowersIds(cursor: -1L)
627                     .ConfigureAwait(false);
628
629                 mock.VerifyAll();
630             }
631         }
632
633         [Fact]
634         public async Task MutesUsersIds_Test()
635         {
636             using (var twitterApi = new TwitterApi())
637             {
638                 var mock = new Mock<IApiConnection>();
639                 mock.Setup(x =>
640                     x.GetAsync<TwitterIds>(
641                         new Uri("mutes/users/ids.json", UriKind.Relative),
642                         new Dictionary<string, string> { { "cursor", "-1" } },
643                         "/mutes/users/ids")
644                 )
645                 .ReturnsAsync(new TwitterIds());
646
647                 twitterApi.apiConnection = mock.Object;
648
649                 await twitterApi.MutesUsersIds(cursor: -1L)
650                     .ConfigureAwait(false);
651
652                 mock.VerifyAll();
653             }
654         }
655
656         [Fact]
657         public async Task BlocksIds_Test()
658         {
659             using (var twitterApi = new TwitterApi())
660             {
661                 var mock = new Mock<IApiConnection>();
662                 mock.Setup(x =>
663                     x.GetAsync<TwitterIds>(
664                         new Uri("blocks/ids.json", UriKind.Relative),
665                         new Dictionary<string, string> { { "cursor", "-1" } },
666                         "/blocks/ids")
667                 )
668                 .ReturnsAsync(new TwitterIds());
669
670                 twitterApi.apiConnection = mock.Object;
671
672                 await twitterApi.BlocksIds(cursor: -1L)
673                     .ConfigureAwait(false);
674
675                 mock.VerifyAll();
676             }
677         }
678
679         [Fact]
680         public async Task BlocksCreate_Test()
681         {
682             using (var twitterApi = new TwitterApi())
683             {
684                 var mock = new Mock<IApiConnection>();
685                 mock.Setup(x =>
686                     x.PostLazyAsync<TwitterUser>(
687                         new Uri("blocks/create.json", UriKind.Relative),
688                         new Dictionary<string, string> { { "screen_name", "twitterapi" } })
689                 )
690                 .ReturnsAsync(LazyJson.Create(new TwitterUser()));
691
692                 twitterApi.apiConnection = mock.Object;
693
694                 await twitterApi.BlocksCreate(screenName: "twitterapi")
695                     .IgnoreResponse()
696                     .ConfigureAwait(false);
697
698                 mock.VerifyAll();
699             }
700         }
701
702         [Fact]
703         public async Task BlocksDestroy_Test()
704         {
705             using (var twitterApi = new TwitterApi())
706             {
707                 var mock = new Mock<IApiConnection>();
708                 mock.Setup(x =>
709                     x.PostLazyAsync<TwitterUser>(
710                         new Uri("blocks/destroy.json", UriKind.Relative),
711                         new Dictionary<string, string> { { "screen_name", "twitterapi" } })
712                 )
713                 .ReturnsAsync(LazyJson.Create(new TwitterUser()));
714
715                 twitterApi.apiConnection = mock.Object;
716
717                 await twitterApi.BlocksDestroy(screenName: "twitterapi")
718                     .IgnoreResponse()
719                     .ConfigureAwait(false);
720
721                 mock.VerifyAll();
722             }
723         }
724
725         [Fact]
726         public async Task AccountUpdateProfile_Test()
727         {
728             using (var twitterApi = new TwitterApi())
729             {
730                 var mock = new Mock<IApiConnection>();
731                 mock.Setup(x =>
732                     x.PostLazyAsync<TwitterUser>(
733                         new Uri("account/update_profile.json", UriKind.Relative),
734                         new Dictionary<string, string> {
735                             { "include_entities", "true" },
736                             { "include_ext_alt_text", "true" },
737                             { "name", "Name" },
738                             { "url", "http://example.com/" },
739                             { "location", "Location" },
740                             { "description", "&lt;script&gt;alert(1)&lt;/script&gt;" },
741                         })
742                 )
743                 .ReturnsAsync(LazyJson.Create(new TwitterUser()));
744
745                 twitterApi.apiConnection = mock.Object;
746
747                 await twitterApi.AccountUpdateProfile(name: "Name", url: "http://example.com/", location: "Location", description: "<script>alert(1)</script>")
748                     .IgnoreResponse()
749                     .ConfigureAwait(false);
750
751                 mock.VerifyAll();
752             }
753         }
754
755         [Fact]
756         public async Task AccountUpdateProfileImage_Test()
757         {
758             using (var twitterApi = new TwitterApi())
759             using (var image = TestUtils.CreateDummyImage())
760             using (var media = new MemoryImageMediaItem(image))
761             {
762                 var mock = new Mock<IApiConnection>();
763                 mock.Setup(x =>
764                     x.PostLazyAsync<TwitterUser>(
765                         new Uri("account/update_profile_image.json", UriKind.Relative),
766                         new Dictionary<string, string> {
767                             { "include_entities", "true" },
768                             { "include_ext_alt_text", "true" },
769                         },
770                         new Dictionary<string, IMediaItem> { { "image", media } })
771                 )
772                 .ReturnsAsync(LazyJson.Create(new TwitterUser()));
773
774                 twitterApi.apiConnection = mock.Object;
775
776                 await twitterApi.AccountUpdateProfileImage(media)
777                     .IgnoreResponse()
778                     .ConfigureAwait(false);
779
780                 mock.VerifyAll();
781             }
782         }
783
784         [Fact]
785         public async Task Configuration_Test()
786         {
787             using (var twitterApi = new TwitterApi())
788             {
789                 var mock = new Mock<IApiConnection>();
790                 mock.Setup(x =>
791                     x.GetAsync<TwitterConfiguration>(
792                         new Uri("help/configuration.json", UriKind.Relative),
793                         null,
794                         "/help/configuration")
795                 )
796                 .ReturnsAsync(new TwitterConfiguration());
797
798                 twitterApi.apiConnection = mock.Object;
799
800                 await twitterApi.Configuration()
801                     .ConfigureAwait(false);
802
803                 mock.VerifyAll();
804             }
805         }
806
807         [Fact]
808         public async Task MediaUpload_Test()
809         {
810             using (var twitterApi = new TwitterApi())
811             using (var image = TestUtils.CreateDummyImage())
812             using (var media = new MemoryImageMediaItem(image))
813             {
814                 var mock = new Mock<IApiConnection>();
815                 mock.Setup(x =>
816                     x.PostLazyAsync<TwitterUploadMediaResult>(
817                         new Uri("https://upload.twitter.com/1.1/media/upload.json", UriKind.Absolute),
818                         null,
819                         new Dictionary<string, IMediaItem> { { "media", media } })
820                 )
821                 .ReturnsAsync(LazyJson.Create(new TwitterUploadMediaResult()));
822
823                 twitterApi.apiConnection = mock.Object;
824
825                 await twitterApi.MediaUpload(media)
826                     .IgnoreResponse()
827                     .ConfigureAwait(false);
828
829                 mock.VerifyAll();
830             }
831         }
832     }
833 }