Skip to content

Commit

Permalink
Fixed StreamTweet MatchingRule.ID parsing. (#231)
Browse files Browse the repository at this point in the history
* Fixed StreamTweet MatchingRule.ID parsing.

* Removed unused usings.
  • Loading branch information
JoeMayo authored Sep 20, 2021
1 parent 1b5585e commit 45a564b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<ITwitterExecute> 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""
}
]
}";
}
}
2 changes: 1 addition & 1 deletion src/LinqToTwitter6/LinqToTwitter/Streaming/MatchingRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public record MatchingRule
/// ID for rule
/// </summary>
[JsonPropertyName("id")]
public ulong ID { get; init; }
public string? ID { get; init; }

/// <summary>
/// Rule tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 45a564b

Please sign in to comment.