-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
3,197 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// 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.Connection; | ||
using Xunit; | ||
|
||
namespace OpenTween.Api.GraphQL | ||
{ | ||
public class SearchTimelineRequestTest | ||
{ | ||
[Fact] | ||
public async Task Send_Test() | ||
{ | ||
using var responseStream = File.OpenRead("Resources/Responses/SearchTimeline_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/lZ0GCEojmtQfiUQa5oJSEw/SearchTimeline"), url); | ||
Assert.Equal(2, param.Count); | ||
Assert.Equal("""{"rawQuery":"#OpenTween","count":20,"product":"Latest"}""", param["variables"]); | ||
Assert.True(param.ContainsKey("features")); | ||
}) | ||
.ReturnsAsync(responseStream); | ||
|
||
var request = new SearchTimelineRequest(rawQuery: "#OpenTween") | ||
{ | ||
Count = 20, | ||
}; | ||
|
||
var response = await request.Send(mock.Object).ConfigureAwait(false); | ||
Assert.Single(response.Tweets); | ||
Assert.Equal("DAADDAABCgABFnlh4hraMAYKAAIOTm0DEhTAAQAIAAIAAAACCAADAAAAAAgABAAAAAAKAAUX8j3ezIAnEAoABhfyPd7Mf9jwAAA", response.CursorBottom); | ||
|
||
mock.VerifyAll(); | ||
} | ||
|
||
[Fact] | ||
public async Task Send_RequestCursor_Test() | ||
{ | ||
using var responseStream = File.OpenRead("Resources/Responses/SearchTimeline_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/lZ0GCEojmtQfiUQa5oJSEw/SearchTimeline"), url); | ||
Assert.Equal(2, param.Count); | ||
Assert.Equal("""{"rawQuery":"#OpenTween","count":20,"product":"Latest","cursor":"aaa"}""", param["variables"]); | ||
Assert.True(param.ContainsKey("features")); | ||
}) | ||
.ReturnsAsync(responseStream); | ||
|
||
var request = new SearchTimelineRequest(rawQuery: "#OpenTween") | ||
{ | ||
Count = 20, | ||
Cursor = "aaa", | ||
}; | ||
|
||
await request.Send(mock.Object).ConfigureAwait(false); | ||
mock.VerifyAll(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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 Xunit; | ||
|
||
namespace OpenTween.Api.GraphQL | ||
{ | ||
public class TwitterGraphqlUserTest | ||
{ | ||
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); | ||
} | ||
|
||
[Fact] | ||
public void ToTwitterUser_Test() | ||
{ | ||
var userElm = this.LoadResponseDocument("User_Simple.json"); | ||
var graphqlUser = new TwitterGraphqlUser(userElm); | ||
var user = graphqlUser.ToTwitterUser(); | ||
|
||
Assert.Equal("514241801", user.IdStr); | ||
Assert.Equal("opentween", user.ScreenName); | ||
} | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
OpenTween.Tests/Api/GraphQL/UserByScreenNameRequestTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// 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.Connection; | ||
using Xunit; | ||
|
||
namespace OpenTween.Api.GraphQL | ||
{ | ||
public class UserByScreenNameRequestTest | ||
{ | ||
[Fact] | ||
public async Task Send_Test() | ||
{ | ||
using var responseStream = File.OpenRead("Resources/Responses/UserByScreenName.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/xc8f1g7BYqr6VTzTbvNlGw/UserByScreenName"), url); | ||
Assert.Contains(@"""screen_name"":""opentween""", param["variables"]); | ||
}) | ||
.ReturnsAsync(responseStream); | ||
|
||
var request = new UserByScreenNameRequest | ||
{ | ||
ScreenName = "opentween", | ||
}; | ||
|
||
var user = await request.Send(mock.Object).ConfigureAwait(false); | ||
Assert.Equal("514241801", user.ToTwitterUser().IdStr); | ||
|
||
mock.VerifyAll(); | ||
} | ||
|
||
[Fact] | ||
public async Task Send_UserUnavailableTest() | ||
{ | ||
using var responseStream = File.OpenRead("Resources/Responses/UserByScreenName_Suspended.json"); | ||
|
||
var mock = new Mock<IApiConnection>(); | ||
mock.Setup(x => | ||
x.GetStreamAsync(It.IsAny<Uri>(), It.IsAny<IDictionary<string, string>>()) | ||
) | ||
.ReturnsAsync(responseStream); | ||
|
||
var request = new UserByScreenNameRequest | ||
{ | ||
ScreenName = "elonmusk", | ||
}; | ||
|
||
var ex = await Assert.ThrowsAsync<WebApiException>( | ||
() => request.Send(mock.Object) | ||
); | ||
Assert.Equal("User is suspended", ex.Message); | ||
|
||
mock.VerifyAll(); | ||
} | ||
} | ||
} |
Oops, something went wrong.