better code coverage
This commit is contained in:
parent
40d6f69446
commit
35adfad45f
3 changed files with 323 additions and 1 deletions
|
@ -76,7 +76,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
processor.WaitFactor = 2;
|
||||
processor.GetTwitterUsersAsync(buffer, CancellationToken.None);
|
||||
|
||||
await Task.Delay(200);
|
||||
await Task.Delay(300);
|
||||
|
||||
#region Validations
|
||||
twitterUserDalMock.VerifyAll();
|
||||
|
|
|
@ -510,5 +510,147 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ExecuteAsync_SingleTweet_ParsingError_Test()
|
||||
{
|
||||
#region Stubs
|
||||
var tweetId = 10;
|
||||
var tweets = new List<ExtractedTweet>
|
||||
{
|
||||
new ExtractedTweet
|
||||
{
|
||||
Id = tweetId,
|
||||
}
|
||||
};
|
||||
|
||||
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 = "/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("Invalid pattern blabla at offset 9"));
|
||||
|
||||
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
|
||||
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<SendTweetsToInboxTask>>();
|
||||
#endregion
|
||||
|
||||
var task = new SendTweetsToInboxTask(activityPubService.Object, statusServiceMock.Object, followersDalMock.Object, settings, loggerMock.Object);
|
||||
await task.ExecuteAsync(tweets.ToArray(), follower, twitterUser);
|
||||
|
||||
#region Validations
|
||||
activityPubService.VerifyAll();
|
||||
statusServiceMock.VerifyAll();
|
||||
followersDalMock.VerifyAll();
|
||||
#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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -638,5 +638,185 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ExecuteAsync_SingleTweet_ParsingError_Test()
|
||||
{
|
||||
#region Stubs
|
||||
var tweetId = 10;
|
||||
var tweets = new List<ExtractedTweet>
|
||||
{
|
||||
new ExtractedTweet
|
||||
{
|
||||
Id = tweetId,
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
statusServiceMock
|
||||
.Setup(x => x.GetStatus(
|
||||
It.Is<string>(y => y == twitterHandle),
|
||||
It.Is<ExtractedTweet>(y => y.Id == tweetId)))
|
||||
.Throws(new ArgumentException("Invalid pattern blabla at offset 9"));
|
||||
|
||||
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]
|
||||
[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 = "/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);
|
||||
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<SendTweetsToSharedInboxTask>>();
|
||||
#endregion
|
||||
|
||||
var task = new SendTweetsToSharedInboxTask(activityPubService.Object, statusServiceMock.Object, followersDalMock.Object, settings, loggerMock.Object);
|
||||
|
||||
try
|
||||
{
|
||||
await task.ExecuteAsync(tweets.ToArray(), twitterUser, host, followers.ToArray());
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
#region Validations
|
||||
activityPubService.VerifyAll();
|
||||
statusServiceMock.VerifyAll();
|
||||
followersDalMock.VerifyAll();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue