diff --git a/src/BirdsiteLive.Common/Settings/TwitterSettings.cs b/src/BirdsiteLive.Common/Settings/TwitterSettings.cs deleted file mode 100644 index 3e9095a..0000000 --- a/src/BirdsiteLive.Common/Settings/TwitterSettings.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace BirdsiteLive.Common.Settings -{ - public class TwitterSettings - { - public string ConsumerKey { get; set; } - public string ConsumerSecret { get; set; } - } -} \ No newline at end of file diff --git a/src/BirdsiteLive.Twitter/Tools/TwitterAuthenticationInitializer.cs b/src/BirdsiteLive.Twitter/Tools/TwitterAuthenticationInitializer.cs index 5b2e51b..8eb729c 100644 --- a/src/BirdsiteLive.Twitter/Tools/TwitterAuthenticationInitializer.cs +++ b/src/BirdsiteLive.Twitter/Tools/TwitterAuthenticationInitializer.cs @@ -19,7 +19,6 @@ namespace BirdsiteLive.Twitter.Tools public class TwitterAuthenticationInitializer : ITwitterAuthenticationInitializer { - private readonly TwitterSettings _settings; private readonly ILogger _logger; private static bool _initialized; private readonly HttpClient _httpClient = new HttpClient(); @@ -32,9 +31,8 @@ namespace BirdsiteLive.Twitter.Tools } #region Ctor - public TwitterAuthenticationInitializer(TwitterSettings settings, ILogger logger) + public TwitterAuthenticationInitializer(ILogger logger) { - _settings = settings; _logger = logger; } #endregion diff --git a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs index a1bf051..6be8697 100644 --- a/src/BirdsiteLive.Twitter/TwitterTweetsService.cs +++ b/src/BirdsiteLive.Twitter/TwitterTweetsService.cs @@ -17,6 +17,7 @@ namespace BirdsiteLive.Twitter { public interface ITwitterTweetsService { + Task GetTweetAsync(long statusId); ExtractedTweet GetTweet(long statusId); ExtractedTweet[] GetTimeline(string username, int nberTweets, long fromTweetId = -1); } @@ -219,6 +220,8 @@ namespace BirdsiteLive.Twitter Url = media.GetProperty("media_url_https").GetString(), }; Media.Add(m); + + MessageContent = MessageContent.Replace(media.GetProperty("url").GetString(), ""); } } var extractedTweet = new ExtractedTweet @@ -226,7 +229,7 @@ namespace BirdsiteLive.Twitter Id = Int64.Parse(tweet.GetProperty("sortIndex").GetString()), InReplyToStatusId = inReplyToPostId, InReplyToAccount = inReplyToUser, - MessageContent = MessageContent, + MessageContent = MessageContent.Trim(), CreatedAt = DateTime.ParseExact(creationTime, "ddd MMM dd HH:mm:ss yyyy", System.Globalization.CultureInfo.InvariantCulture), IsReply = isReply, IsThread = false, diff --git a/src/BirdsiteLive.sln b/src/BirdsiteLive.sln index 4b0cfc1..afd49a7 100644 --- a/src/BirdsiteLive.sln +++ b/src/BirdsiteLive.sln @@ -51,6 +51,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BSLManager", "BSLManager\BS EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BSLManager.Tests", "Tests\BSLManager.Tests\BSLManager.Tests.csproj", "{D4457271-620E-465A-B08E-7FC63C99A2F6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BirdsiteLive.Twitter.Tests", "Tests\BirdsiteLive.Twitter.Tests\BirdsiteLive.Twitter.Tests.csproj", "{2DFA0BFD-88F5-4434-A6E3-C93B5750E88C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -137,6 +139,10 @@ Global {D4457271-620E-465A-B08E-7FC63C99A2F6}.Debug|Any CPU.Build.0 = Debug|Any CPU {D4457271-620E-465A-B08E-7FC63C99A2F6}.Release|Any CPU.ActiveCfg = Release|Any CPU {D4457271-620E-465A-B08E-7FC63C99A2F6}.Release|Any CPU.Build.0 = Release|Any CPU + {2DFA0BFD-88F5-4434-A6E3-C93B5750E88C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2DFA0BFD-88F5-4434-A6E3-C93B5750E88C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2DFA0BFD-88F5-4434-A6E3-C93B5750E88C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2DFA0BFD-88F5-4434-A6E3-C93B5750E88C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -160,6 +166,7 @@ Global {0A311BF3-4FD9-4303-940A-A3778890561C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94} {C69F7582-6050-44DC-BAAB-7C8F0BDA525C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94} {D4457271-620E-465A-B08E-7FC63C99A2F6} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94} + {2DFA0BFD-88F5-4434-A6E3-C93B5750E88C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {69E8DCAD-4C37-4010-858F-5F94E6FBABCE} diff --git a/src/Tests/BirdsiteLive.Twitter.Tests/BirdsiteLive.Twitter.Tests.csproj b/src/Tests/BirdsiteLive.Twitter.Tests/BirdsiteLive.Twitter.Tests.csproj new file mode 100644 index 0000000..45319de --- /dev/null +++ b/src/Tests/BirdsiteLive.Twitter.Tests/BirdsiteLive.Twitter.Tests.csproj @@ -0,0 +1,22 @@ + + + + net6 + + false + + + + + + + + + + + + + + + + diff --git a/src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs b/src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs new file mode 100644 index 0000000..2f45284 --- /dev/null +++ b/src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs @@ -0,0 +1,42 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.Extensions.Logging; +using System.Threading.Tasks; +using BirdsiteLive.Twitter; +using BirdsiteLive.Twitter.Tools; +using BirdsiteLive.Statistics.Domain; +using Moq; + +namespace BirdsiteLive.ActivityPub.Tests +{ + [TestClass] + public class TweetTests + { + private ITwitterTweetsService _tweetService; + [TestInitialize] + public async Task TestInit() + { + var logger1 = new Mock>(MockBehavior.Strict); + var logger2 = new Mock>(MockBehavior.Strict); + var logger3 = new Mock>(MockBehavior.Strict); + var stats = new Mock(); + ITwitterAuthenticationInitializer auth = new TwitterAuthenticationInitializer(logger1.Object); + ITwitterUserService user = new TwitterUserService(auth, stats.Object, logger2.Object); + _tweetService = new TwitterTweetsService(auth, stats.Object, user, logger3.Object); + } + + [TestMethod] + public async Task SimpleTextTweet() + { + var tweet = await _tweetService.GetTweetAsync(1600905296892891149); + Assert.AreEqual(tweet.MessageContent, "We’re strengthening American manufacturing by creating 750,000 manufacturing jobs since I became president."); + } + + [TestMethod] + public async Task SimpleTextAndSinglePictureTweet() + { + var tweet = await _tweetService.GetTweetAsync(1593344577385160704); + Assert.AreEqual(tweet.MessageContent, "Speaker Nancy Pelosi will go down as one of most accomplished legislators in American history—breaking barriers, opening doors for others, and working every day to serve the American people. I couldn’t be more grateful for her friendship and leadership."); + } + + } +} \ No newline at end of file