added tests for reset errors
This commit is contained in:
parent
77e3caebe0
commit
d3d330d74e
1 changed files with 164 additions and 0 deletions
|
@ -241,6 +241,89 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
#endregion
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ProcessAsync_MultiInstances_SharedInbox_OneTweet_ErrorReset_Test()
|
||||
{
|
||||
#region Stubs
|
||||
var tweetId = 1;
|
||||
var host1 = "domain1.ext";
|
||||
var host2 = "domain2.ext";
|
||||
var sharedInbox = "/inbox";
|
||||
var userId1 = 2;
|
||||
var userId2 = 3;
|
||||
var userAcct = "user";
|
||||
|
||||
var userWithTweets = new UserWithDataToSync()
|
||||
{
|
||||
Tweets = new[]
|
||||
{
|
||||
new ExtractedTweet
|
||||
{
|
||||
Id = tweetId
|
||||
}
|
||||
},
|
||||
User = new SyncTwitterUser
|
||||
{
|
||||
Acct = userAcct
|
||||
},
|
||||
Followers = new[]
|
||||
{
|
||||
new Follower
|
||||
{
|
||||
Id = userId1,
|
||||
Host = host1,
|
||||
SharedInboxRoute = sharedInbox
|
||||
},
|
||||
new Follower
|
||||
{
|
||||
Id = userId2,
|
||||
Host = host2,
|
||||
SharedInboxRoute = sharedInbox,
|
||||
PostingErrorCount = 50
|
||||
},
|
||||
}
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region Mocks
|
||||
var sendTweetsToInboxTaskMock = new Mock<ISendTweetsToInboxTask>(MockBehavior.Strict);
|
||||
|
||||
var sendTweetsToSharedInboxTaskMock = new Mock<ISendTweetsToSharedInboxTask>(MockBehavior.Strict);
|
||||
sendTweetsToSharedInboxTaskMock
|
||||
.Setup(x => x.ExecuteAsync(
|
||||
It.Is<ExtractedTweet[]>(y => y.Length == 1),
|
||||
It.Is<SyncTwitterUser>(y => y.Acct == userAcct),
|
||||
It.Is<string>(y => y == host1),
|
||||
It.Is<Follower[]>(y => y.Length == 1)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
sendTweetsToSharedInboxTaskMock
|
||||
.Setup(x => x.ExecuteAsync(
|
||||
It.Is<ExtractedTweet[]>(y => y.Length == 1),
|
||||
It.Is<SyncTwitterUser>(y => y.Acct == userAcct),
|
||||
It.Is<string>(y => y == host2),
|
||||
It.Is<Follower[]>(y => y.Length == 1)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
|
||||
|
||||
followersDalMock
|
||||
.Setup(x => x.UpdateFollowerAsync(It.Is<Follower>(y => y.Id == userId2 && y.PostingErrorCount == 0)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var loggerMock = new Mock<ILogger<SendTweetsToFollowersProcessor>>();
|
||||
#endregion
|
||||
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object, followersDalMock.Object, loggerMock.Object);
|
||||
var result = await processor.ProcessAsync(userWithTweets, CancellationToken.None);
|
||||
|
||||
#region Validations
|
||||
sendTweetsToInboxTaskMock.VerifyAll();
|
||||
sendTweetsToSharedInboxTaskMock.VerifyAll();
|
||||
followersDalMock.VerifyAll();
|
||||
#endregion
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ProcessAsync_SameInstance_Inbox_OneTweet_Test()
|
||||
{
|
||||
|
@ -463,5 +546,86 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
followersDalMock.VerifyAll();
|
||||
#endregion
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ProcessAsync_MultiInstances_Inbox_OneTweet_ErrorReset_Test()
|
||||
{
|
||||
#region Stubs
|
||||
var tweetId = 1;
|
||||
var host1 = "domain1.ext";
|
||||
var host2 = "domain2.ext";
|
||||
var inbox = "/user/inbox";
|
||||
var userId1 = 2;
|
||||
var userId2 = 3;
|
||||
var userAcct = "user";
|
||||
|
||||
var userWithTweets = new UserWithDataToSync()
|
||||
{
|
||||
Tweets = new[]
|
||||
{
|
||||
new ExtractedTweet
|
||||
{
|
||||
Id = tweetId
|
||||
}
|
||||
},
|
||||
User = new SyncTwitterUser
|
||||
{
|
||||
Acct = userAcct
|
||||
},
|
||||
Followers = new[]
|
||||
{
|
||||
new Follower
|
||||
{
|
||||
Id = userId1,
|
||||
Host = host1,
|
||||
InboxRoute = inbox
|
||||
},
|
||||
new Follower
|
||||
{
|
||||
Id = userId2,
|
||||
Host = host2,
|
||||
InboxRoute = inbox,
|
||||
PostingErrorCount = 50
|
||||
},
|
||||
}
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region Mocks
|
||||
var sendTweetsToInboxTaskMock = new Mock<ISendTweetsToInboxTask>(MockBehavior.Strict);
|
||||
sendTweetsToInboxTaskMock
|
||||
.Setup(x => x.ExecuteAsync(
|
||||
It.Is<ExtractedTweet[]>(y => y.Length == 1),
|
||||
It.Is<Follower>(y => y.Id == userId1),
|
||||
It.Is<SyncTwitterUser>(y => y.Acct == userAcct)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
sendTweetsToInboxTaskMock
|
||||
.Setup(x => x.ExecuteAsync(
|
||||
It.Is<ExtractedTweet[]>(y => y.Length == 1),
|
||||
It.Is<Follower>(y => y.Id == userId2),
|
||||
It.Is<SyncTwitterUser>(y => y.Acct == userAcct)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var sendTweetsToSharedInboxTaskMock = new Mock<ISendTweetsToSharedInboxTask>(MockBehavior.Strict);
|
||||
|
||||
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
|
||||
|
||||
followersDalMock
|
||||
.Setup(x => x.UpdateFollowerAsync(It.Is<Follower>(y => y.Id == userId2 && y.PostingErrorCount == 0)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var loggerMock = new Mock<ILogger<SendTweetsToFollowersProcessor>>();
|
||||
#endregion
|
||||
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object, followersDalMock.Object, loggerMock.Object);
|
||||
var result = await processor.ProcessAsync(userWithTweets, CancellationToken.None);
|
||||
|
||||
#region Validations
|
||||
sendTweetsToInboxTaskMock.VerifyAll();
|
||||
sendTweetsToSharedInboxTaskMock.VerifyAll();
|
||||
followersDalMock.VerifyAll();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue