activity generation refactoring

This commit is contained in:
Vincent Cloutier 2023-02-10 11:54:33 -05:00
parent 81f54f0084
commit da8092cfd5
9 changed files with 170 additions and 327 deletions

View file

@ -18,7 +18,7 @@ namespace BirdsiteLive.Domain
{
Task<Actor> GetUser(string objectId);
Task<HttpStatusCode> PostDataAsync<T>(T data, string targetHost, string actorUrl, string inbox = null);
Task PostNewActivity(Note note, string username, string activityType, string noteId, string targetHost,
Task PostNewActivity(ActivityCreateNote note, string username, string noteId, string targetHost,
string targetInbox);
}
@ -57,35 +57,11 @@ namespace BirdsiteLive.Domain
return actor;
}
public async Task PostNewActivity(Note note, string username, string activityType, string noteId, string targetHost, string targetInbox)
public async Task PostNewActivity(ActivityCreateNote noteActivity, string username, string noteId, string targetHost, string targetInbox)
{
try
{
var actor = UrlFactory.GetActorUrl(_instanceSettings.Domain, username);
String noteUri;
if (activityType == "Create")
{
noteUri = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, noteId);
} else
{
noteUri = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, note.announceId);
}
var now = DateTime.UtcNow;
var nowString = now.ToString("s") + "Z";
var noteActivity = new ActivityCreateNote()
{
context = "https://www.w3.org/ns/activitystreams",
id = $"{noteUri}/activity",
type = activityType,
actor = actor,
published = nowString,
to = new[] {$"{actor}/followers"},
cc = note.cc,
apObject = note
};
await PostDataAsync(noteActivity, targetHost, actor, targetInbox);
}

View file

@ -1,40 +0,0 @@
using System.Linq;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.Domain.Tools;
namespace BirdsiteLive.Domain.Repository
{
public interface IPublicationRepository
{
bool IsUnlisted(string twitterAcct);
bool IsSensitive(string twitterAcct);
}
public class PublicationRepository : IPublicationRepository
{
private readonly string[] _unlistedAccounts;
private readonly string[] _sensitiveAccounts;
#region Ctor
public PublicationRepository(InstanceSettings settings)
{
_unlistedAccounts = PatternsParser.Parse(settings.UnlistedTwitterAccounts);
_sensitiveAccounts = PatternsParser.Parse(settings.SensitiveTwitterAccounts);
}
#endregion
public bool IsUnlisted(string twitterAcct)
{
if (_unlistedAccounts == null || !_unlistedAccounts.Any()) return false;
return _unlistedAccounts.Contains(twitterAcct.ToLowerInvariant());
}
public bool IsSensitive(string twitterAcct)
{
if (_sensitiveAccounts == null || !_sensitiveAccounts.Any()) return false;
return _sensitiveAccounts.Contains(twitterAcct.ToLowerInvariant());
}
}
}

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using BirdsiteLive.ActivityPub;
using BirdsiteLive.ActivityPub.Converters;
using BirdsiteLive.ActivityPub.Models;
@ -17,6 +18,7 @@ namespace BirdsiteLive.Domain
public interface IStatusService
{
Note GetStatus(string username, ExtractedTweet tweet);
ActivityCreateNote GetActivity(string username, ExtractedTweet tweet);
}
public class StatusService : IStatusService
@ -24,15 +26,13 @@ namespace BirdsiteLive.Domain
private readonly InstanceSettings _instanceSettings;
private readonly IStatusExtractor _statusExtractor;
private readonly IExtractionStatisticsHandler _statisticsHandler;
private readonly IPublicationRepository _publicationRepository;
#region Ctor
public StatusService(InstanceSettings instanceSettings, IStatusExtractor statusExtractor, IExtractionStatisticsHandler statisticsHandler, IPublicationRepository publicationRepository)
public StatusService(InstanceSettings instanceSettings, IStatusExtractor statusExtractor, IExtractionStatisticsHandler statisticsHandler)
{
_instanceSettings = instanceSettings;
_statusExtractor = statusExtractor;
_statisticsHandler = statisticsHandler;
_publicationRepository = publicationRepository;
}
#endregion
@ -50,15 +50,9 @@ namespace BirdsiteLive.Domain
var to = $"{actorUrl}/followers";
var isUnlisted = _publicationRepository.IsUnlisted(username);
var cc = new string[0];
if (isUnlisted)
cc = new[] {"https://www.w3.org/ns/activitystreams#Public"};
string summary = null;
var sensitive = _publicationRepository.IsSensitive(username);
if (sensitive)
summary = "Potential Content Warning";
var extractedTags = _statusExtractor.Extract(tweet.MessageContent);
_statisticsHandler.ExtractedStatus(extractedTags.tags.Count(x => x.type == "Mention"));
@ -90,7 +84,7 @@ namespace BirdsiteLive.Domain
to = new[] { to },
cc = cc,
sensitive = sensitive,
sensitive = false,
summary = summary,
content = $"<p>{content}</p>",
attachment = Convert(tweet.Media),
@ -99,6 +93,40 @@ namespace BirdsiteLive.Domain
return note;
}
public ActivityCreateNote GetActivity(string username, ExtractedTweet tweet)
{
var note = GetStatus(username, tweet);
var actor = UrlFactory.GetActorUrl(_instanceSettings.Domain, username);
String noteUri;
string activityType;
if (tweet.IsRetweet)
{
noteUri = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, tweet.Id.ToString());
activityType = "Announce";
} else
{
noteUri = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, tweet.Id.ToString());
activityType = "Create";
}
var now = DateTime.UtcNow;
var nowString = now.ToString("s") + "Z";
var noteActivity = new ActivityCreateNote()
{
context = "https://www.w3.org/ns/activitystreams",
id = $"{noteUri}/activity",
type = activityType,
actor = actor,
published = nowString,
to = new[] {$"{actor}/followers"},
cc = note.cc,
apObject = note
};
return noteActivity;
}
private Attachment[] Convert(ExtractedMedia[] media)
{

View file

@ -55,13 +55,8 @@ namespace BirdsiteLive.Pipeline.Processors.SubTasks
{
try
{
if (!tweet.IsReply ||
tweet.IsReply && tweet.IsThread ||
_settings.PublishReplies)
{
var note = _statusService.GetStatus(user.Acct, tweet);
await _activityPubService.PostNewActivity(note, user.Acct, "Create", tweet.Id.ToString(), follower.Host, inbox);
}
var activity = _statusService.GetActivity(user.Acct, tweet);
await _activityPubService.PostNewActivity(activity, user.Acct, tweet.Id.ToString(), follower.Host, inbox);
}
catch (ArgumentException e)
{

View file

@ -56,18 +56,8 @@ namespace BirdsiteLive.Pipeline.Processors.SubTasks
{
try
{
if (tweet.IsRetweet)
{
var note = _statusService.GetStatus(user.Acct, tweet);
await _activityPubService.PostNewActivity(note, user.Acct, "Announce", tweet.Id.ToString(), host, inbox);
}
else if (!tweet.IsReply ||
tweet.IsReply && tweet.IsThread ||
_settings.PublishReplies)
{
var note = _statusService.GetStatus(user.Acct, tweet);
await _activityPubService.PostNewActivity(note, user.Acct, "Create", tweet.Id.ToString(), host, inbox);
}
var activity = _statusService.GetActivity(user.Acct, tweet);
await _activityPubService.PostNewActivity(activity, user.Acct, tweet.Id.ToString(), host, inbox);
}
catch (ArgumentException e)
{

View file

@ -171,6 +171,24 @@ namespace BirdsiteLive.Controllers
return View(displayTweet);
}
[Route("/users/{id}/statuses/{statusId}/activity")]
public async Task<IActionResult> Activity(string id, string statusId)
{
if (!long.TryParse(statusId, out var parsedStatusId))
return NotFound();
var tweet = await _twitterTweetService.GetTweetAsync(parsedStatusId);
if (tweet == null)
return NotFound();
var user = await _twitterUserService.GetUserAsync(id);
var status = _statusService.GetActivity(id, tweet);
var jsonApUser = JsonConvert.SerializeObject(status);
return Content(jsonApUser, "application/activity+json; charset=utf-8");
}
[Route("/users/{id}/inbox")]
[HttpPost]
public async Task<IActionResult> Inbox()

View file

@ -1,7 +1,11 @@
using System;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.Domain.Statistics;
using BirdsiteLive.Domain.Tools;
using BirdsiteLive.Twitter.Models;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace BirdsiteLive.Domain.Tests
{
@ -20,29 +24,32 @@ namespace BirdsiteLive.Domain.Tests
}
#endregion
// [TestMethod]
// public void ExtractMentionsTest()
// {
// #region Stubs
// var username = "MyUserName";
// var extractedTweet = new ExtractedTweet
// {
// Id = 124L,
// CreatedAt = DateTime.UtcNow,
// MessageContent = @"Getting ready for the weekend...have a great one everyone!
//
//Photo by Tim Tronckoe | @timtronckoe
//
//#archenemy #michaelamott #alissawhitegluz #jeffloomis #danielerlandsson #sharleedangelo"
// };
// #endregion
[TestMethod]
public void ActivityTest()
{
#region Stubs
var username = "MyUserName";
var extractedTweet = new ExtractedTweet
{
Id = 124L,
CreatedAt = DateTime.UtcNow,
MessageContent = @"Getting ready for the weekend...have a great one everyone!
Photo by Tim Tronckoe | @timtronckoe
#archenemy #michaelamott #alissawhitegluz #jeffloomis #danielerlandsson #sharleedangelo"
};
#endregion
// var service = new StatusService(_settings);
// var result = service.GetStatus(username, extractedTweet);
var logger1 = new Mock<ILogger<StatusExtractor>>();
var statusExtractor = new StatusExtractor(_settings, logger1.Object);
var stats = new Mock<IExtractionStatisticsHandler>();
var service = new StatusService(_settings, statusExtractor, stats.Object);
var result = service.GetActivity(username, extractedTweet);
// #region Validations
#region Validations
// #endregion
// }
#endregion
}
}
}

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using BirdsiteLive.ActivityPub;
using BirdsiteLive.ActivityPub.Models;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.DAL.Contracts;
@ -37,6 +38,9 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
{
id = noteId
};
var activity = new ActivityCreateNote() {
apObject = note
};
var twitterHandle = "Test";
var twitterUserId = 7;
@ -63,12 +67,11 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
#endregion
#region Mocks
var activityPubService = new Mock<IActivityPubService>(MockBehavior.Strict);
var activityPubService = new Mock<IActivityPubService>();
activityPubService
.Setup(x => x.PostNewActivity(
It.Is<Note>(y => y.id == noteId),
It.Is<ActivityCreateNote>(y => y.apObject.id == noteId),
It.Is<string>(y => y == twitterHandle),
"Create",
It.Is<string>(y => y == tweetId.ToString()),
It.Is<string>(y => y == host),
It.Is<string>(y => y == inbox)))
@ -76,10 +79,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
statusServiceMock
.Setup(x => x.GetStatus(
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Returns(note);
.Returns(activity);
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
followersDalMock
@ -120,6 +123,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
{
id = noteId
};
var activity = new ActivityCreateNote()
{
apObject = note
};
var twitterHandle = "Test";
var twitterUserId = 7;
@ -139,15 +146,26 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
FollowingsSyncStatus = new Dictionary<int, long> { { twitterUserId, 9 } }
};
var settings = new InstanceSettings
{
PublishReplies = false
};
var settings = new InstanceSettings { };
#endregion
#region Mocks
var activityPubService = new Mock<IActivityPubService>(MockBehavior.Strict);
activityPubService
.Setup(x => x.PostNewActivity(
It.Is<ActivityCreateNote>(y => y.apObject.id == noteId),
It.Is<string>(y => y == twitterHandle),
It.Is<string>(y => y == tweetId.ToString()),
It.Is<string>(y => y == host),
It.Is<string>(y => y == inbox)))
.Returns(Task.CompletedTask);
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
statusServiceMock
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Returns(activity);
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
followersDalMock
@ -188,6 +206,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
{
id = noteId
};
var activity = new ActivityCreateNote()
{
apObject = note
};
var twitterHandle = "Test";
var twitterUserId = 7;
@ -217,9 +239,8 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var activityPubService = new Mock<IActivityPubService>(MockBehavior.Strict);
activityPubService
.Setup(x => x.PostNewActivity(
It.Is<Note>(y => y.id == noteId),
It.Is<ActivityCreateNote>(y => y.apObject.id == noteId),
It.Is<string>(y => y == twitterHandle),
"Create",
It.Is<string>(y => y == tweetId.ToString()),
It.Is<string>(y => y == host),
It.Is<string>(y => y == inbox)))
@ -227,10 +248,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
statusServiceMock
.Setup(x => x.GetStatus(
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Returns(note);
.Returns(activity);
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
followersDalMock
@ -271,6 +292,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
{
id = noteId
};
var activity = new ActivityCreateNote()
{
apObject = note
};
var twitterHandle = "Test";
var twitterUserId = 7;
@ -300,9 +325,8 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var activityPubService = new Mock<IActivityPubService>(MockBehavior.Strict);
activityPubService
.Setup(x => x.PostNewActivity(
It.Is<Note>(y => y.id == noteId),
It.Is<ActivityCreateNote>(y => y.apObject.id == noteId),
It.Is<string>(y => y == twitterHandle),
"Create",
It.Is<string>(y => y == tweetId.ToString()),
It.Is<string>(y => y == host),
It.Is<string>(y => y == inbox)))
@ -310,10 +334,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
statusServiceMock
.Setup(x => x.GetStatus(
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Returns(note);
.Returns(activity);
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
followersDalMock
@ -380,9 +404,8 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
{
activityPubService
.Setup(x => x.PostNewActivity(
It.Is<Note>(y => y.id == tweetId.ToString()),
It.Is<ActivityCreateNote>(y => y.apObject.id == tweetId.ToString()),
It.Is<string>(y => y == twitterHandle),
"Create",
It.Is<string>(y => y == tweetId.ToString()),
It.Is<string>(y => y == host),
It.Is<string>(y => y == inbox)))
@ -393,10 +416,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
foreach (var tweetId in new[] { tweetId2, tweetId3 })
{
statusServiceMock
.Setup(x => x.GetStatus(
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Returns(new Note { id = tweetId.ToString() });
.Returns(new ActivityCreateNote { apObject = new Note { id = tweetId.ToString() }});
}
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
@ -464,9 +487,8 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
activityPubService
.Setup(x => x.PostNewActivity(
It.Is<Note>(y => y.id == tweetId2.ToString()),
It.Is<ActivityCreateNote>(y => y.apObject.id == tweetId2.ToString()),
It.Is<string>(y => y == twitterHandle),
"Create",
It.Is<string>(y => y == tweetId2.ToString()),
It.Is<string>(y => y == host),
It.Is<string>(y => y == inbox)))
@ -474,9 +496,8 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
activityPubService
.Setup(x => x.PostNewActivity(
It.Is<Note>(y => y.id == tweetId3.ToString()),
It.Is<ActivityCreateNote>(y => y.apObject.id == tweetId3.ToString()),
It.Is<string>(y => y == twitterHandle),
"Create",
It.Is<string>(y => y == tweetId3.ToString()),
It.Is<string>(y => y == host),
It.Is<string>(y => y == inbox)))
@ -486,10 +507,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
foreach (var tweetId in new[] { tweetId2, tweetId3 })
{
statusServiceMock
.Setup(x => x.GetStatus(
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Returns(new Note { id = tweetId.ToString() });
.Returns(new ActivityCreateNote { apObject = new Note { id = tweetId.ToString() }});
}
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
@ -565,7 +586,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
statusServiceMock
.Setup(x => x.GetStatus(
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Throws(new ArgumentException("Invalid pattern blabla at offset 9"));
@ -589,74 +610,5 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
#endregion
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public async Task ExecuteAsync_SingleTweet_ArgumentException_Test()
{
#region Stubs
var tweetId = 10;
var tweets = new List<ExtractedTweet>
{
new ExtractedTweet
{
Id = tweetId,
}
};
var twitterHandle = "Test";
var twitterUserId = 7;
var twitterUser = new SyncTwitterUser
{
Id = twitterUserId,
Acct = twitterHandle
};
var host = "domain.ext";
var inbox = "/user/inbox";
var follower = new Follower
{
Id = 1,
Host = host,
InboxRoute = inbox,
FollowingsSyncStatus = new Dictionary<int, long> { { twitterUserId, 9 } }
};
var settings = new InstanceSettings
{
PublishReplies = false
};
#endregion
#region Mocks
var activityPubService = new Mock<IActivityPubService>(MockBehavior.Strict);
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
statusServiceMock
.Setup(x => x.GetStatus(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Throws(new ArgumentException());
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
var loggerMock = new Mock<ILogger<SendTweetsToInboxTask>>();
#endregion
var task = new SendTweetsToInboxTask(activityPubService.Object, statusServiceMock.Object, followersDalMock.Object, settings, loggerMock.Object);
try
{
await task.ExecuteAsync(tweets.ToArray(), follower, twitterUser);
}
finally
{
#region Validations
activityPubService.VerifyAll();
statusServiceMock.VerifyAll();
followersDalMock.VerifyAll();
#endregion
}
}
}
}

View file

@ -4,6 +4,7 @@ using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using BirdsiteLive.ActivityPub;
using BirdsiteLive.ActivityPub.Models;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.DAL.Contracts;
@ -38,6 +39,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
{
id = noteId
};
var activity = new ActivityCreateNote()
{
apObject = note
};
var twitterHandle = "Test";
var twitterUserId = 7;
@ -84,9 +89,8 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var activityPubService = new Mock<IActivityPubService>(MockBehavior.Strict);
activityPubService
.Setup(x => x.PostNewActivity(
It.Is<Note>(y => y.id == noteId),
It.Is<ActivityCreateNote>(y => y.apObject.id == noteId),
It.Is<string>(y => y == twitterHandle),
"Create",
It.Is<string>(y => y == tweetId.ToString()),
It.Is<string>(y => y == host),
It.Is<string>(y => y == inbox)))
@ -94,100 +98,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
statusServiceMock
.Setup(x => x.GetStatus(
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Returns(note);
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
foreach (var follower in followers)
{
followersDalMock
.Setup(x => x.UpdateFollowerAsync(
It.Is<Follower>(y => y.Id == follower.Id && y.FollowingsSyncStatus[twitterUserId] == tweetId)))
.Returns(Task.CompletedTask);
}
var loggerMock = new Mock<ILogger<SendTweetsToSharedInboxTask>>();
#endregion
var task = new SendTweetsToSharedInboxTask(activityPubService.Object, statusServiceMock.Object, followersDalMock.Object, settings, loggerMock.Object);
await task.ExecuteAsync(tweets.ToArray(), twitterUser, host, followers.ToArray());
#region Validations
activityPubService.VerifyAll();
statusServiceMock.VerifyAll();
followersDalMock.VerifyAll();
#endregion
}
[TestMethod]
public async Task ExecuteAsync_SingleTweet_Reply_Test()
{
#region Stubs
var tweetId = 10;
var tweets = new List<ExtractedTweet>
{
new ExtractedTweet
{
Id = tweetId,
IsReply = true,
IsThread = false
}
};
var noteId = "noteId";
var note = new Note()
{
id = noteId
};
var twitterHandle = "Test";
var twitterUserId = 7;
var twitterUser = new SyncTwitterUser
{
Id = twitterUserId,
Acct = twitterHandle
};
var host = "domain.ext";
var inbox = "/inbox";
var followers = new List<Follower>
{
new Follower
{
Id = 1,
Host = host,
SharedInboxRoute = inbox,
FollowingsSyncStatus = new Dictionary<int, long> { { twitterUserId, 9 } }
},
new Follower
{
Id = 2,
Host = host,
SharedInboxRoute = inbox,
FollowingsSyncStatus = new Dictionary<int, long> { { twitterUserId, 8 } }
},
new Follower
{
Id = 3,
Host = host,
SharedInboxRoute = inbox,
FollowingsSyncStatus = new Dictionary<int, long> { { twitterUserId, 7 } }
}
};
var settings = new InstanceSettings
{
PublishReplies = false
};
#endregion
#region Mocks
var activityPubService = new Mock<IActivityPubService>(MockBehavior.Strict);
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
.Returns(activity);
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
@ -232,6 +146,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
{
id = noteId
};
var activity = new ActivityCreateNote()
{
apObject = note
};
var twitterHandle = "Test";
var twitterUserId = 7;
@ -278,9 +196,8 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var activityPubService = new Mock<IActivityPubService>(MockBehavior.Strict);
activityPubService
.Setup(x => x.PostNewActivity(
It.Is<Note>(y => y.id == noteId),
It.Is<ActivityCreateNote>(y => y.apObject.id == noteId),
It.Is<string>(y => y == twitterHandle),
"Create",
It.Is<string>(y => y == tweetId.ToString()),
It.Is<string>(y => y == host),
It.Is<string>(y => y == inbox)))
@ -288,10 +205,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
statusServiceMock
.Setup(x => x.GetStatus(
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Returns(note);
.Returns(activity);
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
@ -336,6 +253,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
{
id = noteId
};
var activity = new ActivityCreateNote()
{
apObject = note
};
var twitterHandle = "Test";
var twitterUserId = 7;
@ -382,9 +303,8 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var activityPubService = new Mock<IActivityPubService>(MockBehavior.Strict);
activityPubService
.Setup(x => x.PostNewActivity(
It.Is<Note>(y => y.id == noteId),
It.Is<ActivityCreateNote>(y => y.apObject.id == noteId),
It.Is<string>(y => y == twitterHandle),
"Create",
It.Is<string>(y => y == tweetId.ToString()),
It.Is<string>(y => y == host),
It.Is<string>(y => y == inbox)))
@ -392,10 +312,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
statusServiceMock
.Setup(x => x.GetStatus(
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Returns(note);
.Returns(activity);
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
@ -483,9 +403,8 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
{
activityPubService
.Setup(x => x.PostNewActivity(
It.Is<Note>(y => y.id == tweetId.ToString()),
It.Is<ActivityCreateNote>(y => y.apObject.id == tweetId.ToString()),
It.Is<string>(y => y == twitterHandle),
"Create",
It.Is<string>(y => y == tweetId.ToString()),
It.Is<string>(y => y == host),
It.Is<string>(y => y == inbox)))
@ -496,10 +415,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
foreach (var tweetId in new[] { tweetId2, tweetId3 })
{
statusServiceMock
.Setup(x => x.GetStatus(
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Returns(new Note { id = tweetId.ToString() });
.Returns(new ActivityCreateNote { apObject = new Note { id = tweetId.ToString() }});
}
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
@ -588,9 +507,8 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
activityPubService
.Setup(x => x.PostNewActivity(
It.Is<Note>(y => y.id == tweetId2.ToString()),
It.Is<ActivityCreateNote>(y => y.apObject.id == tweetId2.ToString()),
It.Is<string>(y => y == twitterHandle),
"Create",
It.Is<string>(y => y == tweetId2.ToString()),
It.Is<string>(y => y == host),
It.Is<string>(y => y == inbox)))
@ -598,9 +516,8 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
activityPubService
.Setup(x => x.PostNewActivity(
It.Is<Note>(y => y.id == tweetId3.ToString()),
It.Is<ActivityCreateNote>(y => y.apObject.id == tweetId3.ToString()),
It.Is<string>(y => y == twitterHandle),
"Create",
It.Is<string>(y => y == tweetId3.ToString()),
It.Is<string>(y => y == host),
It.Is<string>(y => y == inbox)))
@ -610,10 +527,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
foreach (var tweetId in new[] { tweetId2, tweetId3 })
{
statusServiceMock
.Setup(x => x.GetStatus(
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Returns(new Note { id = tweetId.ToString() });
.Returns(new ActivityCreateNote { apObject = new Note { id = tweetId.ToString() }});
}
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
@ -710,7 +627,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
statusServiceMock
.Setup(x => x.GetStatus(
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Throws(new ArgumentException("Invalid pattern blabla at offset 9"));
@ -798,7 +715,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
statusServiceMock
.Setup(x => x.GetStatus(
.Setup(x => x.GetActivity(
It.Is<string>(y => y == twitterHandle),
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
.Throws(new ArgumentException());