added integration tests & fixed some picture bugs
This commit is contained in:
parent
9b453c7a90
commit
3e614408da
6 changed files with 76 additions and 12 deletions
|
@ -1,8 +0,0 @@
|
||||||
namespace BirdsiteLive.Common.Settings
|
|
||||||
{
|
|
||||||
public class TwitterSettings
|
|
||||||
{
|
|
||||||
public string ConsumerKey { get; set; }
|
|
||||||
public string ConsumerSecret { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -19,7 +19,6 @@ namespace BirdsiteLive.Twitter.Tools
|
||||||
|
|
||||||
public class TwitterAuthenticationInitializer : ITwitterAuthenticationInitializer
|
public class TwitterAuthenticationInitializer : ITwitterAuthenticationInitializer
|
||||||
{
|
{
|
||||||
private readonly TwitterSettings _settings;
|
|
||||||
private readonly ILogger<TwitterAuthenticationInitializer> _logger;
|
private readonly ILogger<TwitterAuthenticationInitializer> _logger;
|
||||||
private static bool _initialized;
|
private static bool _initialized;
|
||||||
private readonly HttpClient _httpClient = new HttpClient();
|
private readonly HttpClient _httpClient = new HttpClient();
|
||||||
|
@ -32,9 +31,8 @@ namespace BirdsiteLive.Twitter.Tools
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Ctor
|
#region Ctor
|
||||||
public TwitterAuthenticationInitializer(TwitterSettings settings, ILogger<TwitterAuthenticationInitializer> logger)
|
public TwitterAuthenticationInitializer(ILogger<TwitterAuthenticationInitializer> logger)
|
||||||
{
|
{
|
||||||
_settings = settings;
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -17,6 +17,7 @@ namespace BirdsiteLive.Twitter
|
||||||
{
|
{
|
||||||
public interface ITwitterTweetsService
|
public interface ITwitterTweetsService
|
||||||
{
|
{
|
||||||
|
Task<ExtractedTweet> GetTweetAsync(long statusId);
|
||||||
ExtractedTweet GetTweet(long statusId);
|
ExtractedTweet GetTweet(long statusId);
|
||||||
ExtractedTweet[] GetTimeline(string username, int nberTweets, long fromTweetId = -1);
|
ExtractedTweet[] GetTimeline(string username, int nberTweets, long fromTweetId = -1);
|
||||||
}
|
}
|
||||||
|
@ -219,6 +220,8 @@ namespace BirdsiteLive.Twitter
|
||||||
Url = media.GetProperty("media_url_https").GetString(),
|
Url = media.GetProperty("media_url_https").GetString(),
|
||||||
};
|
};
|
||||||
Media.Add(m);
|
Media.Add(m);
|
||||||
|
|
||||||
|
MessageContent = MessageContent.Replace(media.GetProperty("url").GetString(), "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var extractedTweet = new ExtractedTweet
|
var extractedTweet = new ExtractedTweet
|
||||||
|
@ -226,7 +229,7 @@ namespace BirdsiteLive.Twitter
|
||||||
Id = Int64.Parse(tweet.GetProperty("sortIndex").GetString()),
|
Id = Int64.Parse(tweet.GetProperty("sortIndex").GetString()),
|
||||||
InReplyToStatusId = inReplyToPostId,
|
InReplyToStatusId = inReplyToPostId,
|
||||||
InReplyToAccount = inReplyToUser,
|
InReplyToAccount = inReplyToUser,
|
||||||
MessageContent = MessageContent,
|
MessageContent = MessageContent.Trim(),
|
||||||
CreatedAt = DateTime.ParseExact(creationTime, "ddd MMM dd HH:mm:ss yyyy", System.Globalization.CultureInfo.InvariantCulture),
|
CreatedAt = DateTime.ParseExact(creationTime, "ddd MMM dd HH:mm:ss yyyy", System.Globalization.CultureInfo.InvariantCulture),
|
||||||
IsReply = isReply,
|
IsReply = isReply,
|
||||||
IsThread = false,
|
IsThread = false,
|
||||||
|
|
|
@ -51,6 +51,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BSLManager", "BSLManager\BS
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BSLManager.Tests", "Tests\BSLManager.Tests\BSLManager.Tests.csproj", "{D4457271-620E-465A-B08E-7FC63C99A2F6}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BSLManager.Tests", "Tests\BSLManager.Tests\BSLManager.Tests.csproj", "{D4457271-620E-465A-B08E-7FC63C99A2F6}"
|
||||||
EndProject
|
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
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{D4457271-620E-465A-B08E-7FC63C99A2F6}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -160,6 +166,7 @@ Global
|
||||||
{0A311BF3-4FD9-4303-940A-A3778890561C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94}
|
{0A311BF3-4FD9-4303-940A-A3778890561C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94}
|
||||||
{C69F7582-6050-44DC-BAAB-7C8F0BDA525C} = {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}
|
{D4457271-620E-465A-B08E-7FC63C99A2F6} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94}
|
||||||
|
{2DFA0BFD-88F5-4434-A6E3-C93B5750E88C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {69E8DCAD-4C37-4010-858F-5F94E6FBABCE}
|
SolutionGuid = {69E8DCAD-4C37-4010-858F-5F94E6FBABCE}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||||
|
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
||||||
|
<PackageReference Include="moq" Version="4.16.1" />
|
||||||
|
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\BirdsiteLive.Twitter\BirdsiteLive.Twitter.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
42
src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs
Normal file
42
src/Tests/BirdsiteLive.Twitter.Tests/TweetTests.cs
Normal file
|
@ -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<ILogger<TwitterAuthenticationInitializer>>(MockBehavior.Strict);
|
||||||
|
var logger2 = new Mock<ILogger<TwitterUserService>>(MockBehavior.Strict);
|
||||||
|
var logger3 = new Mock<ILogger<TwitterTweetsService>>(MockBehavior.Strict);
|
||||||
|
var stats = new Mock<ITwitterStatisticsHandler>();
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue