Skip to content

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
upsilon committed Jul 4, 2023
2 parents c2c366c + 37f061f commit 99a98e4
Show file tree
Hide file tree
Showing 67 changed files with 6,111 additions and 1,480 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ jobs:
- name: Run tests
shell: pwsh
run: |
$altCoverVersion = '8.2.837'
$xunitVersion = '2.4.1'
$altCoverVersion = '8.6.61'
$xunitVersion = '2.4.2'
$targetFramework = 'net48'
$altCoverPath = "$($env:NUGET_PACKAGES)\altcover\$($altCoverVersion)\tools\net472\AltCover.exe"
$xunitPath = "$($env:NUGET_PACKAGES)\xunit.runner.console\$($xunitVersion)\tools\net472\xunit.console.exe"
Expand Down
4 changes: 2 additions & 2 deletions OpenTween.Tests/Api/BitlyApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public async Task GetAccessTokenAsync_Test()

return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent("{\"access_token\": \"abcdefg\"}"),
Content = new StringContent("""{"access_token": "abcdefg"}"""),
};
});

Expand All @@ -154,7 +154,7 @@ public async Task GetAccessTokenAsync_ErrorResponseTest()
{
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent("{\"status_code\": \"500\", \"status_txt\": \"MISSING_ARG_USERNAME\"}"),
Content = new StringContent("""{"status_code": "500", "status_txt": "MISSING_ARG_USERNAME"}"""),
};
});

Expand Down
22 changes: 12 additions & 10 deletions OpenTween.Tests/Api/DataModel/TwitterMessageEventListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ public class TwitterMessageEventListTest
[Fact]
public void Deserialize_AppsTest()
{
var json = @"{
""events"": [],
""apps"": {
""258901"": {
""id"": ""258901"",
""name"": ""Twitter for Android"",
""url"": ""http://twitter.com/download/android""
}
}
}";
var json = """
{
"events": [],
"apps": {
"258901": {
"id": "258901",
"name": "Twitter for Android",
"url": "http://twitter.com/download/android"
}
}
}
""";
var result = MyCommon.CreateDataFromJson<TwitterMessageEventList>(json);
Assert.Single(result.Apps);

Expand Down
94 changes: 48 additions & 46 deletions OpenTween.Tests/Api/DataModel/TwitterUser_20190520ChangesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,52 +32,54 @@ public void ParseJsonTest()
// (廃止されるフィールドに null がセットされる)
// https://twittercommunity.com/t/124732

var json = @"{
""id"": 6253282,
""id_str"": ""6253282"",
""name"": ""Twitter API"",
""screen_name"": ""TwitterAPI"",
""location"": ""San Francisco, CA"",
""profile_location"": null,
""description"": ""The Real Twitter API. Tweets about API changes, service issues and our Developer Platform. Don't get an answer? It's on my website."",
""url"": ""https:\/\/t.co\/8IkCzCDr19"",
""protected"": false,
""followers_count"": 6133601,
""friends_count"": 12,
""listed_count"": 12935,
""created_at"": ""Wed May 23 06:01:13 +0000 2007"",
""favourites_count"": 31,
""utc_offset"": null,
""time_zone"": null,
""geo_enabled"": null,
""verified"": true,
""statuses_count"": 3657,
""lang"": null,
""contributors_enabled"": null,
""is_translator"": null,
""is_translation_enabled"": null,
""profile_background_color"": null,
""profile_background_image_url"": null,
""profile_background_image_url_https"": null,
""profile_background_tile"": null,
""profile_image_url"": null,
""profile_image_url_https"": ""https:\/\/pbs.twimg.com\/profile_images\/942858479592554497\/BbazLO9L_normal.jpg"",
""profile_banner_url"": ""https:\/\/pbs.twimg.com\/profile_banners\/6253282\/1497491515"",
""profile_image_extensions_alt_text"": null,
""profile_banner_extensions_alt_text"": null,
""profile_link_color"": null,
""profile_sidebar_border_color"": null,
""profile_sidebar_fill_color"": null,
""profile_text_color"": null,
""profile_use_background_image"": null,
""has_extended_profile"": null,
""default_profile"": false,
""default_profile_image"": false,
""following"": null,
""follow_request_sent"": null,
""notifications"": null,
""translator_type"": null
}";
var json = """
{
"id": 6253282,
"id_str": "6253282",
"name": "Twitter API",
"screen_name": "TwitterAPI",
"location": "San Francisco, CA",
"profile_location": null,
"description": "The Real Twitter API. Tweets about API changes, service issues and our Developer Platform. Don't get an answer? It's on my website.",
"url": "https:\/\/t.co\/8IkCzCDr19",
"protected": false,
"followers_count": 6133601,
"friends_count": 12,
"listed_count": 12935,
"created_at": "Wed May 23 06:01:13 +0000 2007",
"favourites_count": 31,
"utc_offset": null,
"time_zone": null,
"geo_enabled": null,
"verified": true,
"statuses_count": 3657,
"lang": null,
"contributors_enabled": null,
"is_translator": null,
"is_translation_enabled": null,
"profile_background_color": null,
"profile_background_image_url": null,
"profile_background_image_url_https": null,
"profile_background_tile": null,
"profile_image_url": null,
"profile_image_url_https": "https:\/\/pbs.twimg.com\/profile_images\/942858479592554497\/BbazLO9L_normal.jpg",
"profile_banner_url": "https:\/\/pbs.twimg.com\/profile_banners\/6253282\/1497491515",
"profile_image_extensions_alt_text": null,
"profile_banner_extensions_alt_text": null,
"profile_link_color": null,
"profile_sidebar_border_color": null,
"profile_sidebar_fill_color": null,
"profile_text_color": null,
"profile_use_background_image": null,
"has_extended_profile": null,
"default_profile": false,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null,
"translator_type": null
}
""";
TwitterUser.ParseJson(json);
}
}
Expand Down
66 changes: 66 additions & 0 deletions OpenTween.Tests/Api/GraphQL/ListLatestTweetsTimelineRequestTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// OpenTween - Client of Twitter
// Copyright (c) 2023 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
// All rights reserved.
//
// This file is part of OpenTween.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Moq;
using OpenTween.Api.TwitterV2;
using OpenTween.Connection;
using Xunit;

namespace OpenTween.Api.GraphQL
{
public class ListLatestTweetsTimelineRequestTest
{
[Fact]
public async Task Send_Test()
{
using var responseStream = File.OpenRead("Resources/Responses/ListLatestTweetsTimeline_SimpleTweet.json");

var mock = new Mock<IApiConnection>();
mock.Setup(x =>
x.GetStreamAsync(It.IsAny<Uri>(), It.IsAny<IDictionary<string, string>>())
)
.Callback<Uri, IDictionary<string, string>>((url, param) =>
{
Assert.Equal(new("https://twitter.com/i/api/graphql/6ClPnsuzQJ1p7-g32GQw9Q/ListLatestTweetsTimeline"), url);
Assert.Equal(2, param.Count);
Assert.Equal("""{"listId":"1675863884757110790","count":20}""", param["variables"]);
Assert.True(param.ContainsKey("features"));
})
.ReturnsAsync(responseStream);

var request = new ListLatestTweetsTimelineRequest(listId: "1675863884757110790")
{
Count = 20,
};

var tweets = await request.Send(mock.Object).ConfigureAwait(false);
Assert.Single(tweets);

mock.VerifyAll();
}
}
}
114 changes: 114 additions & 0 deletions OpenTween.Tests/Api/GraphQL/TimelineTweetTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// OpenTween - Client of Twitter
// Copyright (c) 2023 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
// All rights reserved.
//
// This file is part of OpenTween.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using OpenTween.Models;
using Xunit;

namespace OpenTween.Api.GraphQL
{
public class TimelineTweetTest
{
private XElement LoadResponseDocument(string filename)
{
using var stream = File.OpenRead($"Resources/Responses/{filename}");
using var jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, XmlDictionaryReaderQuotas.Max);
return XElement.Load(jsonReader);
}

private TabInformations CreateTabInfo()
{
var tabinfo = new TabInformations();
tabinfo.AddDefaultTabs();
return tabinfo;
}

[Fact]
public void ExtractTimelineTweets_Single_Test()
{
var rootElm = this.LoadResponseDocument("ListLatestTweetsTimeline_SimpleTweet.json");
var timelineTweets = TimelineTweet.ExtractTimelineTweets(rootElm);
Assert.Single(timelineTweets);
}

[Fact]
public void ExtractTimelineTweets_Conversation_Test()
{
var rootElm = this.LoadResponseDocument("ListLatestTweetsTimeline_Conversation.json");
var timelineTweets = TimelineTweet.ExtractTimelineTweets(rootElm);
Assert.Equal(3, timelineTweets.Length);
}

[Fact]
public void ToStatus_WithTwitterPostFactory_SimpleTweet_Test()
{
var rootElm = this.LoadResponseDocument("TimelineTweet_SimpleTweet.json");
var timelineTweet = new TimelineTweet(rootElm);
var status = timelineTweet.ToTwitterStatus();
var postFactory = new TwitterPostFactory(this.CreateTabInfo());
var post = postFactory.CreateFromStatus(status, selfUserId: 1L, new HashSet<long>());

Assert.Equal("1613784711020826626", post.StatusId.Id);
Assert.Equal(40480664L, post.UserId);
}

[Fact]
public void ToStatus_WithTwitterPostFactory_TweetWithMedia_Test()
{
var rootElm = this.LoadResponseDocument("TimelineTweet_TweetWithMedia.json");
var timelineTweet = new TimelineTweet(rootElm);
var status = timelineTweet.ToTwitterStatus();
var postFactory = new TwitterPostFactory(this.CreateTabInfo());
var post = postFactory.CreateFromStatus(status, selfUserId: 1L, new HashSet<long>());

Assert.Equal("1614587968567783424", post.StatusId.Id);
Assert.Equal(40480664L, post.UserId);
Assert.Equal(2, post.Media.Count);
Assert.Equal("https://pbs.twimg.com/media/FmgrJiEaAAEU42G.png", post.Media[0].Url);
Assert.Equal("OpenTweenで @opentween のツイート一覧を表示しているスクショ", post.Media[0].AltText);
Assert.Equal("https://pbs.twimg.com/media/FmgrJiXaMAEu873.jpg", post.Media[1].Url);
Assert.Equal("OpenTweenの新しい画像投稿画面を動かしている様子のスクショ", post.Media[1].AltText);
}

[Fact]
public void ToStatus_WithTwitterPostFactory_RetweetedTweet_Test()
{
var rootElm = this.LoadResponseDocument("TimelineTweet_RetweetedTweet.json");
var timelineTweet = new TimelineTweet(rootElm);
var status = timelineTweet.ToTwitterStatus();
var postFactory = new TwitterPostFactory(this.CreateTabInfo());
var post = postFactory.CreateFromStatus(status, selfUserId: 1L, new HashSet<long>());

Assert.Equal("1617128268548964354", post.StatusId.Id);
Assert.Equal(40480664L, post.RetweetedByUserId);
Assert.Equal("1617126084138659840", post.RetweetedId!.Id);
Assert.Equal(514241801L, post.UserId);
}
}
}
Loading

0 comments on commit 99a98e4

Please sign in to comment.