diff --git a/src/LinqToTwitter6/LinqToTwitter.Tests/StreamTests/StreamContentTests.cs b/src/LinqToTwitter6/LinqToTwitter.Tests/StreamTests/StreamContentTests.cs new file mode 100644 index 00000000..1a52783b --- /dev/null +++ b/src/LinqToTwitter6/LinqToTwitter.Tests/StreamTests/StreamContentTests.cs @@ -0,0 +1,47 @@ +๏ปฟusing LinqToTwitter.Provider; +using LinqToTwitter.Tests.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace LinqToTwitter.Tests.StreamContentTests +{ + [TestClass] + public class StreamContentTests + { + Mock execMock = new(); + + public StreamContentTests() + { + TestCulture.SetCulture(); + } + + [TestMethod] + public void ParseJson_WithTweetEntity_Succeeds() + { + var content = new StreamContent(execMock.Object, TweetContent); + + (StreamTweet entity, StreamEntityType entityType) = content.ParseJson(TweetContent); + + Assert.IsNotNull(entity); + Assert.AreEqual("1439984798332866573", entity.Tweet.ID); + Assert.IsTrue(entity.Tweet.Text.StartsWith("Very")); + Assert.AreEqual("1324201416731160579", entity.MatchingRules[0].ID); + Assert.AreEqual("funny things", entity.MatchingRules[0].Tag); + Assert.AreEqual(StreamEntityType.Tweet, entityType); + } + + const string TweetContent = @"{ + ""data"": { + ""id"": ""1439984798332866573"", + ""text"": ""Very very true, Dev! ..๐Ÿ˜œ๐Ÿ˜‚๐Ÿ’•\n#Dev https://t.co/cHFjan"" + }, + ""matching_rules"": [ + { + ""id"": ""1324201416731160579"", + ""tag"": ""funny things"" + + } + ] +}"; + } +} diff --git a/src/LinqToTwitter6/LinqToTwitter/Streaming/MatchingRule.cs b/src/LinqToTwitter6/LinqToTwitter/Streaming/MatchingRule.cs index a2022ce3..eee918a2 100644 --- a/src/LinqToTwitter6/LinqToTwitter/Streaming/MatchingRule.cs +++ b/src/LinqToTwitter6/LinqToTwitter/Streaming/MatchingRule.cs @@ -11,7 +11,7 @@ public record MatchingRule /// ID for rule /// [JsonPropertyName("id")] - public ulong ID { get; init; } + public string? ID { get; init; } /// /// Rule tag diff --git a/src/LinqToTwitter6/LinqToTwitter/Streaming/StreamContent.cs b/src/LinqToTwitter6/LinqToTwitter/Streaming/StreamContent.cs index d19c8cee..4d9ba1f7 100644 --- a/src/LinqToTwitter6/LinqToTwitter/Streaming/StreamContent.cs +++ b/src/LinqToTwitter6/LinqToTwitter/Streaming/StreamContent.cs @@ -20,7 +20,7 @@ public StreamContent(ITwitterExecute exec, string content) (Entity, EntityType) = ParseJson(content); } - (StreamTweet? entity, StreamEntityType entityType) ParseJson(string json) + public (StreamTweet? entity, StreamEntityType entityType) ParseJson(string json) { if (string.IsNullOrWhiteSpace(json)) return (null, StreamEntityType.Unknown);