fix tests
This commit is contained in:
parent
12875b2c56
commit
568c033f9c
4 changed files with 43 additions and 20 deletions
|
@ -5,6 +5,7 @@ using System.Threading.Tasks.Dataflow;
|
|||
using BirdsiteLive.DAL.Contracts;
|
||||
using BirdsiteLive.DAL.Models;
|
||||
using BirdsiteLive.Pipeline.Processors;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
|
||||
|
@ -31,9 +32,11 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
twitterUserDalMock
|
||||
.Setup(x => x.GetAllTwitterUsersAsync())
|
||||
.ReturnsAsync(users);
|
||||
|
||||
var loggerMock = new Mock<ILogger<RetrieveTwitterUsersProcessor>>();
|
||||
#endregion
|
||||
|
||||
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object);
|
||||
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, loggerMock.Object);
|
||||
processor.GetTwitterUsersAsync(buffer, CancellationToken.None);
|
||||
|
||||
await Task.Delay(50);
|
||||
|
@ -58,9 +61,11 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
twitterUserDalMock
|
||||
.Setup(x => x.GetAllTwitterUsersAsync())
|
||||
.ReturnsAsync(new SyncTwitterUser[0]);
|
||||
|
||||
var loggerMock = new Mock<ILogger<RetrieveTwitterUsersProcessor>>();
|
||||
#endregion
|
||||
|
||||
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object);
|
||||
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, loggerMock.Object);
|
||||
processor.GetTwitterUsersAsync(buffer, CancellationToken.None);
|
||||
|
||||
await Task.Delay(50);
|
||||
|
@ -84,9 +89,11 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
twitterUserDalMock
|
||||
.Setup(x => x.GetAllTwitterUsersAsync())
|
||||
.Throws(new Exception());
|
||||
|
||||
var loggerMock = new Mock<ILogger<RetrieveTwitterUsersProcessor>>();
|
||||
#endregion
|
||||
|
||||
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object);
|
||||
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, loggerMock.Object);
|
||||
var t = processor.GetTwitterUsersAsync(buffer, CancellationToken.None);
|
||||
|
||||
await Task.WhenAny(t, Task.Delay(50));
|
||||
|
@ -110,9 +117,10 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
|
||||
#region Mocks
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
var loggerMock = new Mock<ILogger<RetrieveTwitterUsersProcessor>>();
|
||||
#endregion
|
||||
|
||||
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object);
|
||||
var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, loggerMock.Object);
|
||||
await processor.GetTwitterUsersAsync(buffer, canTokenS.Token);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ using BirdsiteLive.Pipeline.Models;
|
|||
using BirdsiteLive.Pipeline.Processors;
|
||||
using BirdsiteLive.Pipeline.Processors.SubTasks;
|
||||
using BirdsiteLive.Twitter.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
|
||||
|
@ -67,9 +68,11 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
It.Is<string>(y => y == host),
|
||||
It.Is<Follower[]>(y => y.Length == 2)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var loggerMock = new Mock<ILogger<SendTweetsToFollowersProcessor>>();
|
||||
#endregion
|
||||
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object);
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object, loggerMock.Object);
|
||||
var result = await processor.ProcessAsync(userWithTweets, CancellationToken.None);
|
||||
|
||||
#region Validations
|
||||
|
@ -135,9 +138,11 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
It.Is<Follower[]>(y => y.Length == 1)))
|
||||
.Returns(Task.CompletedTask);
|
||||
}
|
||||
|
||||
var loggerMock = new Mock<ILogger<SendTweetsToFollowersProcessor>>();
|
||||
#endregion
|
||||
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object);
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object, loggerMock.Object);
|
||||
var result = await processor.ProcessAsync(userWithTweets, CancellationToken.None);
|
||||
|
||||
#region Validations
|
||||
|
@ -208,9 +213,11 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
It.Is<string>(y => y == host2),
|
||||
It.Is<Follower[]>(y => y.Length == 1)))
|
||||
.Throws(new Exception());
|
||||
|
||||
var loggerMock = new Mock<ILogger<SendTweetsToFollowersProcessor>>();
|
||||
#endregion
|
||||
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object);
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object, loggerMock.Object);
|
||||
var result = await processor.ProcessAsync(userWithTweets, CancellationToken.None);
|
||||
|
||||
#region Validations
|
||||
|
@ -274,9 +281,11 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
}
|
||||
|
||||
var sendTweetsToSharedInboxTaskMock = new Mock<ISendTweetsToSharedInboxTask>(MockBehavior.Strict);
|
||||
|
||||
var loggerMock = new Mock<ILogger<SendTweetsToFollowersProcessor>>();
|
||||
#endregion
|
||||
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object);
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object, loggerMock.Object);
|
||||
var result = await processor.ProcessAsync(userWithTweets, CancellationToken.None);
|
||||
|
||||
#region Validations
|
||||
|
@ -341,9 +350,11 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
}
|
||||
|
||||
var sendTweetsToSharedInboxTaskMock = new Mock<ISendTweetsToSharedInboxTask>(MockBehavior.Strict);
|
||||
|
||||
var loggerMock = new Mock<ILogger<SendTweetsToFollowersProcessor>>();
|
||||
#endregion
|
||||
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object);
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object, loggerMock.Object);
|
||||
var result = await processor.ProcessAsync(userWithTweets, CancellationToken.None);
|
||||
|
||||
#region Validations
|
||||
|
@ -412,9 +423,11 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
.Throws(new Exception());
|
||||
|
||||
var sendTweetsToSharedInboxTaskMock = new Mock<ISendTweetsToSharedInboxTask>(MockBehavior.Strict);
|
||||
|
||||
var loggerMock = new Mock<ILogger<SendTweetsToFollowersProcessor>>();
|
||||
#endregion
|
||||
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object);
|
||||
var processor = new SendTweetsToFollowersProcessor(sendTweetsToInboxTaskMock.Object, sendTweetsToSharedInboxTaskMock.Object, loggerMock.Object);
|
||||
var result = await processor.ProcessAsync(userWithTweets, CancellationToken.None);
|
||||
|
||||
#region Validations
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using BirdsiteLive.ActivityPub.Models;
|
||||
using BirdsiteLive.DAL.Contracts;
|
||||
|
@ -63,7 +64,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
It.Is<string>(y => y == tweetId.ToString()),
|
||||
It.Is<string>(y => y == host),
|
||||
It.Is<string>(y => y == inbox)))
|
||||
.ReturnsAsync(HttpStatusCode.Accepted);
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
|
||||
statusServiceMock
|
||||
|
@ -136,7 +137,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
It.Is<string>(y => y == tweetId.ToString()),
|
||||
It.Is<string>(y => y == host),
|
||||
It.Is<string>(y => y == inbox)))
|
||||
.ReturnsAsync(HttpStatusCode.Accepted);
|
||||
.Returns(Task.CompletedTask);
|
||||
}
|
||||
|
||||
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
|
||||
|
@ -168,7 +169,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(Exception))]
|
||||
[ExpectedException(typeof(HttpRequestException))]
|
||||
public async Task ExecuteAsync_MultipleTweets_Error_Test()
|
||||
{
|
||||
#region Stubs
|
||||
|
@ -213,7 +214,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
It.Is<string>(y => y == tweetId2.ToString()),
|
||||
It.Is<string>(y => y == host),
|
||||
It.Is<string>(y => y == inbox)))
|
||||
.ReturnsAsync(HttpStatusCode.Accepted);
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
activityPubService
|
||||
.Setup(x => x.PostNewNoteActivity(
|
||||
|
@ -222,7 +223,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
It.Is<string>(y => y == tweetId3.ToString()),
|
||||
It.Is<string>(y => y == host),
|
||||
It.Is<string>(y => y == inbox)))
|
||||
.ReturnsAsync(HttpStatusCode.InternalServerError);
|
||||
.Throws(new HttpRequestException());
|
||||
|
||||
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
|
||||
foreach (var tweetId in new[] { tweetId2, tweetId3 })
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using BirdsiteLive.ActivityPub.Models;
|
||||
using BirdsiteLive.DAL.Contracts;
|
||||
|
@ -81,7 +82,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
It.Is<string>(y => y == tweetId.ToString()),
|
||||
It.Is<string>(y => y == host),
|
||||
It.Is<string>(y => y == inbox)))
|
||||
.ReturnsAsync(HttpStatusCode.Accepted);
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
|
||||
statusServiceMock
|
||||
|
@ -174,7 +175,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
It.Is<string>(y => y == tweetId.ToString()),
|
||||
It.Is<string>(y => y == host),
|
||||
It.Is<string>(y => y == inbox)))
|
||||
.ReturnsAsync(HttpStatusCode.Accepted);
|
||||
.Returns(Task.CompletedTask);
|
||||
}
|
||||
|
||||
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
|
||||
|
@ -209,7 +210,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(Exception))]
|
||||
[ExpectedException(typeof(HttpRequestException))]
|
||||
public async Task ExecuteAsync_MultipleTweets_Error_Test()
|
||||
{
|
||||
#region Stubs
|
||||
|
@ -271,7 +272,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
It.Is<string>(y => y == tweetId2.ToString()),
|
||||
It.Is<string>(y => y == host),
|
||||
It.Is<string>(y => y == inbox)))
|
||||
.ReturnsAsync(HttpStatusCode.Accepted);
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
activityPubService
|
||||
.Setup(x => x.PostNewNoteActivity(
|
||||
|
@ -280,7 +281,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks
|
|||
It.Is<string>(y => y == tweetId3.ToString()),
|
||||
It.Is<string>(y => y == host),
|
||||
It.Is<string>(y => y == inbox)))
|
||||
.ReturnsAsync(HttpStatusCode.InternalServerError);
|
||||
.Throws(new HttpRequestException());
|
||||
|
||||
var statusServiceMock = new Mock<IStatusService>(MockBehavior.Strict);
|
||||
foreach (var tweetId in new[] { tweetId2, tweetId3 })
|
||||
|
|
Reference in a new issue