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 99a98e4 + 6cdc55a commit b0f5451
Show file tree
Hide file tree
Showing 14 changed files with 671 additions and 23 deletions.
13 changes: 13 additions & 0 deletions OpenTween.Tests/Api/GraphQL/TimelineTweetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,18 @@ public void ToStatus_WithTwitterPostFactory_RetweetedTweet_Test()
Assert.Equal("1617126084138659840", post.RetweetedId!.Id);
Assert.Equal(514241801L, post.UserId);
}

[Fact]
public void ToStatus_WithTwitterPostFactory_TweetWithVisibility_Test()
{
var rootElm = this.LoadResponseDocument("TimelineTweet_TweetWithVisibility.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("1602775353088524288", post.StatusId.Id);
Assert.Equal(357750891L, post.UserId);
}
}
}
38 changes: 38 additions & 0 deletions OpenTween.Tests/Api/JsonUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.

using System.IO;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using Xunit;

namespace OpenTween.Api
Expand All @@ -34,5 +39,38 @@ public class JsonUtilsTest
[InlineData("\U0001D11E", @"\uD834\uDD1E")]
public void EscapeJsonString_Test(string targetText, string expectedText)
=> Assert.Equal(expectedText, JsonUtils.EscapeJsonString(targetText));

[Fact]
public void JsonXmlToString_WholeTest()
{
var json = """{"hoge":{"aaa":12345}}""";
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
using var jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, XmlDictionaryReaderQuotas.Max);
var rootElement = XElement.Load(jsonReader);

Assert.Equal("""{"hoge":{"aaa":12345}}""", JsonUtils.JsonXmlToString(rootElement));
}

[Fact]
public void JsonXmlToString_SubsetTest()
{
var json = """{"hoge":{"aaa":12345}}""";
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
using var jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, XmlDictionaryReaderQuotas.Max);
var rootElement = XElement.Load(jsonReader);

Assert.Equal("""{"aaa":12345}""", JsonUtils.JsonXmlToString(rootElement.Element("hoge")));
}

[Fact]
public void JsonXmlToString_NullTest()
{
var json = """{"hoge":null}""";
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
using var jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, XmlDictionaryReaderQuotas.Max);
var rootElement = XElement.Load(jsonReader);

Assert.Equal("null", JsonUtils.JsonXmlToString(rootElement.Element("hoge")));
}
}
}
3 changes: 3 additions & 0 deletions OpenTween.Tests/OpenTween.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<None Update="Resources\Responses\TimelineTweet_RetweetedTweet.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Responses\TimelineTweet_TweetWithVisibility.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Responses\TimelineTweet_TweetWithMedia.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Loading

0 comments on commit b0f5451

Please sign in to comment.