diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTwitterUsersProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTwitterUsersProcessorTests.cs index b7a2e2b..356a479 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTwitterUsersProcessorTests.cs +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTwitterUsersProcessorTests.cs @@ -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>(); #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>(); #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>(); #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(MockBehavior.Strict); + var loggerMock = new Mock>(); #endregion - var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object); + var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, loggerMock.Object); await processor.GetTwitterUsersAsync(buffer, canTokenS.Token); } } diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SendTweetsToFollowersProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SendTweetsToFollowersProcessorTests.cs index 034d8d2..ad35c3e 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SendTweetsToFollowersProcessorTests.cs +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SendTweetsToFollowersProcessorTests.cs @@ -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(y => y == host), It.Is(y => y.Length == 2))) .Returns(Task.CompletedTask); + + var loggerMock = new Mock>(); #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(y => y.Length == 1))) .Returns(Task.CompletedTask); } + + var loggerMock = new Mock>(); #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(y => y == host2), It.Is(y => y.Length == 1))) .Throws(new Exception()); + + var loggerMock = new Mock>(); #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(MockBehavior.Strict); + + var loggerMock = new Mock>(); #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(MockBehavior.Strict); + + var loggerMock = new Mock>(); #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(MockBehavior.Strict); + + var loggerMock = new Mock>(); #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 diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToInboxTaskTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToInboxTaskTests.cs index 0596162..36688f6 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToInboxTaskTests.cs +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToInboxTaskTests.cs @@ -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(y => y == tweetId.ToString()), It.Is(y => y == host), It.Is(y => y == inbox))) - .ReturnsAsync(HttpStatusCode.Accepted); + .Returns(Task.CompletedTask); var statusServiceMock = new Mock(MockBehavior.Strict); statusServiceMock @@ -136,7 +137,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks It.Is(y => y == tweetId.ToString()), It.Is(y => y == host), It.Is(y => y == inbox))) - .ReturnsAsync(HttpStatusCode.Accepted); + .Returns(Task.CompletedTask); } var statusServiceMock = new Mock(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(y => y == tweetId2.ToString()), It.Is(y => y == host), It.Is(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(y => y == tweetId3.ToString()), It.Is(y => y == host), It.Is(y => y == inbox))) - .ReturnsAsync(HttpStatusCode.InternalServerError); + .Throws(new HttpRequestException()); var statusServiceMock = new Mock(MockBehavior.Strict); foreach (var tweetId in new[] { tweetId2, tweetId3 }) diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToSharedInboxTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToSharedInboxTests.cs index a052a5c..1909108 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToSharedInboxTests.cs +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToSharedInboxTests.cs @@ -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(y => y == tweetId.ToString()), It.Is(y => y == host), It.Is(y => y == inbox))) - .ReturnsAsync(HttpStatusCode.Accepted); + .Returns(Task.CompletedTask); var statusServiceMock = new Mock(MockBehavior.Strict); statusServiceMock @@ -174,7 +175,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors.SubTasks It.Is(y => y == tweetId.ToString()), It.Is(y => y == host), It.Is(y => y == inbox))) - .ReturnsAsync(HttpStatusCode.Accepted); + .Returns(Task.CompletedTask); } var statusServiceMock = new Mock(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(y => y == tweetId2.ToString()), It.Is(y => y == host), It.Is(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(y => y == tweetId3.ToString()), It.Is(y => y == host), It.Is(y => y == inbox))) - .ReturnsAsync(HttpStatusCode.InternalServerError); + .Throws(new HttpRequestException()); var statusServiceMock = new Mock(MockBehavior.Strict); foreach (var tweetId in new[] { tweetId2, tweetId3 })