added RetrieveFollowersProcessor tests

This commit is contained in:
Nicolas Constant 2020-08-12 21:05:25 -04:00
parent 5fe1daabd7
commit 98d5b2183b
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
1 changed files with 79 additions and 0 deletions

View File

@ -0,0 +1,79 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using BirdsiteLive.DAL.Contracts;
using BirdsiteLive.DAL.Models;
using BirdsiteLive.Pipeline.Models;
using BirdsiteLive.Pipeline.Processors;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace BirdsiteLive.Pipeline.Tests.Processors
{
[TestClass]
public class RetrieveFollowersProcessorTests
{
[TestMethod]
public async Task ProcessAsync_Test()
{
#region Stubs
var userId1 = 1;
var userId2 = 2;
var users = new List<UserWithTweetsToSync>
{
new UserWithTweetsToSync
{
User = new SyncTwitterUser
{
Id = userId1
}
},
new UserWithTweetsToSync
{
User = new SyncTwitterUser
{
Id = userId2
}
}
};
var followersUser1 = new List<Follower>
{
new Follower(),
new Follower(),
};
var followersUser2 = new List<Follower>
{
new Follower(),
new Follower(),
new Follower(),
};
#endregion
#region Mocks
var followersDalMock = new Mock<IFollowersDal>(MockBehavior.Strict);
followersDalMock
.Setup(x => x.GetFollowersAsync(It.Is<int>(y => y == userId1)))
.ReturnsAsync(followersUser1.ToArray());
followersDalMock
.Setup(x => x.GetFollowersAsync(It.Is<int>(y => y == userId2)))
.ReturnsAsync(followersUser2.ToArray());
#endregion
var processor = new RetrieveFollowersProcessor(followersDalMock.Object);
var result = (await processor.ProcessAsync(users.ToArray(), CancellationToken.None)).ToList();
#region Validations
Assert.IsNotNull(result);
Assert.AreEqual(2, result.Count);
Assert.AreEqual(2, result.First(x => x.User.Id == userId1).Followers.Length);
Assert.AreEqual(3, result.First(x => x.User.Id == userId2).Followers.Length);
followersDalMock.VerifyAll();
#endregion
}
}
}