dont feed pipeline if no elements

This commit is contained in:
Nicolas Constant 2020-11-18 22:49:44 -05:00
parent b7acb4c907
commit 01337a63ec
No known key found for this signature in database
GPG key ID: 1E9F677FB01A5688
2 changed files with 29 additions and 1 deletions

View file

@ -29,7 +29,9 @@ namespace BirdsiteLive.Pipeline.Processors
try
{
var users = await _twitterUserDal.GetAllTwitterUsersAsync();
await twitterUsersBufferBlock.SendAsync(users, ct);
if(users.Length > 0)
await twitterUsersBufferBlock.SendAsync(users, ct);
}
catch (Exception e)
{

View file

@ -46,6 +46,32 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
#endregion
}
[TestMethod]
public async Task GetTwitterUsersAsync_NoUsers_Test()
{
#region Stubs
var buffer = new BufferBlock<SyncTwitterUser[]>();
#endregion
#region Mocks
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
twitterUserDalMock
.Setup(x => x.GetAllTwitterUsersAsync())
.ReturnsAsync(new SyncTwitterUser[0]);
#endregion
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object);
processor.GetTwitterUsersAsync(buffer, CancellationToken.None);
await Task.Delay(50);
#region Validations
twitterUserDalMock.VerifyAll();
Assert.AreEqual(0, buffer.Count);
#endregion
}
[TestMethod]
public async Task GetTwitterUsersAsync_Exception_Test()
{