diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/BirdsiteLive.Pipeline.Tests.csproj b/src/Tests/BirdsiteLive.Pipeline.Tests/BirdsiteLive.Pipeline.Tests.csproj index e3aae19..7d8e345 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/BirdsiteLive.Pipeline.Tests.csproj +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/BirdsiteLive.Pipeline.Tests.csproj @@ -17,6 +17,7 @@ + diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RefreshTwitterUserStatusProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/RefreshTwitterUserStatusProcessorTests.cs similarity index 99% rename from src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RefreshTwitterUserStatusProcessorTests.cs rename to src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/RefreshTwitterUserStatusProcessorTests.cs index 9e224f7..a1c9757 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RefreshTwitterUserStatusProcessorTests.cs +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/RefreshTwitterUserStatusProcessorTests.cs @@ -13,7 +13,7 @@ using BirdsiteLive.Twitter.Models; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -namespace BirdsiteLive.Pipeline.Tests.Processors +namespace BirdsiteLive.Pipeline.Tests.Processors.Federation { [TestClass] public class RefreshTwitterUserStatusProcessorTests @@ -60,7 +60,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None); #region Validations - Assert.AreEqual(2 , result.Length); + Assert.AreEqual(2, result.Length); Assert.IsTrue(result.Any(x => x.User.Id == userId1)); Assert.IsTrue(result.Any(x => x.User.Id == userId2)); @@ -288,7 +288,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors twitterUserServiceMock .Setup(x => x.GetUser(It.Is(y => y == acct2))) .Throws(new Exception()); - + var twitterUserDalMock = new Mock(MockBehavior.Strict); twitterUserDalMock .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct2))) @@ -360,7 +360,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors twitterUserServiceMock .Setup(x => x.GetUser(It.Is(y => y == acct2))) .Returns((TwitterUser)null); - + var twitterUserDalMock = new Mock(MockBehavior.Strict); twitterUserDalMock .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct2))) @@ -432,7 +432,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors twitterUserServiceMock .Setup(x => x.GetUser(It.Is(y => y == acct2))) .Returns((TwitterUser)null); - + var twitterUserDalMock = new Mock(MockBehavior.Strict); twitterUserDalMock .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct2))) @@ -506,7 +506,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors { Protected = true }); - + var twitterUserDalMock = new Mock(MockBehavior.Strict); twitterUserDalMock .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct2))) @@ -581,7 +581,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors { Protected = true }); - + var twitterUserDalMock = new Mock(MockBehavior.Strict); twitterUserDalMock .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct2))) @@ -609,14 +609,14 @@ namespace BirdsiteLive.Pipeline.Tests.Processors removeTwitterAccountActionMock.VerifyAll(); #endregion } - + [TestMethod] public async Task ProcessAsync_Error_NotInit_Test() { #region Stubs var userId1 = 1; var acct1 = "user1"; - + var users = new List { new SyncTwitterUser @@ -640,7 +640,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors twitterUserServiceMock .Setup(x => x.GetUser(It.Is(y => y == acct1))) .Returns((TwitterUser)null); - + var twitterUserDalMock = new Mock(MockBehavior.Strict); twitterUserDalMock .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct1))) @@ -708,7 +708,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors twitterUserServiceMock .Setup(x => x.GetUser(It.Is(y => y == acct2))) .Throws(new RateLimitExceededException()); - + var twitterUserDalMock = new Mock(MockBehavior.Strict); twitterUserDalMock .Setup(x => x.GetTwitterUserAsync(It.Is(y => y == acct2))) diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveFollowersProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/RetrieveFollowersProcessorTests.cs similarity index 97% rename from src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveFollowersProcessorTests.cs rename to src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/RetrieveFollowersProcessorTests.cs index 99b3e29..d687541 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveFollowersProcessorTests.cs +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/RetrieveFollowersProcessorTests.cs @@ -9,7 +9,7 @@ using BirdsiteLive.Pipeline.Processors.Federation; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -namespace BirdsiteLive.Pipeline.Tests.Processors +namespace BirdsiteLive.Pipeline.Tests.Processors.Federation { [TestClass] public class RetrieveFollowersProcessorTests diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTweetsProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/RetrieveTweetsProcessorTests.cs similarity index 100% rename from src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTweetsProcessorTests.cs rename to src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/RetrieveTweetsProcessorTests.cs diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTwitterUsersProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/RetrieveTwitterUsersProcessorTests.cs similarity index 98% rename from src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTwitterUsersProcessorTests.cs rename to src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/RetrieveTwitterUsersProcessorTests.cs index 8a5a5ba..f8956d3 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTwitterUsersProcessorTests.cs +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/RetrieveTwitterUsersProcessorTests.cs @@ -12,7 +12,7 @@ using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -namespace BirdsiteLive.Pipeline.Tests.Processors +namespace BirdsiteLive.Pipeline.Tests.Processors.Federation { [TestClass] public class RetrieveTwitterUsersProcessorTests @@ -43,7 +43,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors It.Is(y => y == maxUsers), It.Is(y => y == false))) .ReturnsAsync(users); - + var loggerMock = new Mock>(); #endregion @@ -100,7 +100,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors var t = processor.GetTwitterUsersAsync(buffer, CancellationToken.None); await Task.WhenAny(t, Task.Delay(300)); - + #region Validations maxUsersNumberProviderMock.VerifyAll(); twitterUserDalMock.VerifyAll(); @@ -139,7 +139,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors .ReturnsAsync(new SyncTwitterUser[0]) .ReturnsAsync(new SyncTwitterUser[0]) .ReturnsAsync(new SyncTwitterUser[0]); - + var loggerMock = new Mock>(); #endregion @@ -190,7 +190,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors var processor = new RetrieveTwitterUsersProcessor(twitterUserDalMock.Object, maxUsersNumberProviderMock.Object, loggerMock.Object); processor.WaitFactor = 1; - var t =processor.GetTwitterUsersAsync(buffer, CancellationToken.None); + var t = processor.GetTwitterUsersAsync(buffer, CancellationToken.None); await Task.WhenAny(t, Task.Delay(50)); @@ -200,7 +200,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors Assert.AreEqual(0, buffer.Count); #endregion } - + [TestMethod] public async Task GetTwitterUsersAsync_Exception_Test() { @@ -258,7 +258,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors .ReturnsAsync(maxUsers); var twitterUserDalMock = new Mock(MockBehavior.Strict); - + var loggerMock = new Mock>(); #endregion diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SaveProgressionProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/SaveProgressionProcessorTests.cs similarity index 100% rename from src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SaveProgressionProcessorTests.cs rename to src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/SaveProgressionProcessorTests.cs diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SendTweetsToFollowersProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/SendTweetsToFollowersProcessorTests.cs similarity index 100% rename from src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SendTweetsToFollowersProcessorTests.cs rename to src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/SendTweetsToFollowersProcessorTests.cs diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToInboxTaskTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/SubTasks/SendTweetsToInboxTaskTests.cs similarity index 100% rename from src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToInboxTaskTests.cs rename to src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/SubTasks/SendTweetsToInboxTaskTests.cs diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToSharedInboxTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/SubTasks/SendTweetsToSharedInboxTests.cs similarity index 100% rename from src/Tests/BirdsiteLive.Pipeline.Tests/Processors/SubTasks/SendTweetsToSharedInboxTests.cs rename to src/Tests/BirdsiteLive.Pipeline.Tests/Processors/Federation/SubTasks/SendTweetsToSharedInboxTests.cs diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/TweetsCleanUp/DeleteTweetsProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/TweetsCleanUp/DeleteTweetsProcessorTests.cs new file mode 100644 index 0000000..d81c581 --- /dev/null +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/TweetsCleanUp/DeleteTweetsProcessorTests.cs @@ -0,0 +1,160 @@ +using System; +using System.Net; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using BirdsiteLive.DAL.Models; +using BirdsiteLive.Domain; +using BirdsiteLive.Pipeline.Models; +using BirdsiteLive.Pipeline.Processors.Federation; +using BirdsiteLive.Pipeline.Processors.TweetsCleanUp; +using Microsoft.Extensions.Logging; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace BirdsiteLive.Pipeline.Tests.Processors.TweetsCleanUp +{ + [TestClass] + public class DeleteTweetsProcessorTests + { + [TestMethod] + public async Task Process_DeleteTweet_Test() + { + #region Stubs + var tweetId = 42; + var tweet = new TweetToDelete + { + Tweet = new SyncTweet + { + Id = tweetId + } + }; + #endregion + + #region Mocks + var serviceMock = new Mock(MockBehavior.Strict); + serviceMock + .Setup(x => x.DeleteNoteAsync(It.Is(y => y.Id == tweetId))) + .Returns(Task.CompletedTask); + + var loggerMock = new Mock>(); + #endregion + + var processor = new DeleteTweetsProcessor(serviceMock.Object, loggerMock.Object); + var result = await processor.ProcessAsync(tweet, CancellationToken.None); + + #region Validations + serviceMock.VerifyAll(); + loggerMock.VerifyAll(); + + Assert.IsNotNull(result); + Assert.IsTrue(result.DeleteSuccessful); + #endregion + } + + [TestMethod] + public async Task Process_DeleteTweet_NotFound_Test() + { + #region Stubs + var tweetId = 42; + var tweet = new TweetToDelete + { + Tweet = new SyncTweet + { + Id = tweetId + } + }; + #endregion + + #region Mocks + var serviceMock = new Mock(MockBehavior.Strict); + serviceMock + .Setup(x => x.DeleteNoteAsync(It.Is(y => y.Id == tweetId))) + .Throws(new HttpRequestException("not found", null, HttpStatusCode.NotFound)); + + var loggerMock = new Mock>(); + #endregion + + var processor = new DeleteTweetsProcessor(serviceMock.Object, loggerMock.Object); + var result = await processor.ProcessAsync(tweet, CancellationToken.None); + + #region Validations + serviceMock.VerifyAll(); + loggerMock.VerifyAll(); + + Assert.IsNotNull(result); + Assert.IsTrue(result.DeleteSuccessful); + #endregion + } + + [TestMethod] + public async Task Process_DeleteTweet_HttpError_Test() + { + #region Stubs + var tweetId = 42; + var tweet = new TweetToDelete + { + Tweet = new SyncTweet + { + Id = tweetId + } + }; + #endregion + + #region Mocks + var serviceMock = new Mock(MockBehavior.Strict); + serviceMock + .Setup(x => x.DeleteNoteAsync(It.Is(y => y.Id == tweetId))) + .Throws(new HttpRequestException("bad gateway", null, HttpStatusCode.BadGateway)); + + var loggerMock = new Mock>(); + #endregion + + var processor = new DeleteTweetsProcessor(serviceMock.Object, loggerMock.Object); + var result = await processor.ProcessAsync(tweet, CancellationToken.None); + + #region Validations + serviceMock.VerifyAll(); + loggerMock.VerifyAll(); + + Assert.IsNotNull(result); + Assert.IsFalse(result.DeleteSuccessful); + #endregion + } + + [TestMethod] + public async Task Process_DeleteTweet_GenericException_Test() + { + #region Stubs + var tweetId = 42; + var tweet = new TweetToDelete + { + Tweet = new SyncTweet + { + Id = tweetId + } + }; + #endregion + + #region Mocks + var serviceMock = new Mock(MockBehavior.Strict); + serviceMock + .Setup(x => x.DeleteNoteAsync(It.Is(y => y.Id == tweetId))) + .Throws(new Exception()); + + var loggerMock = new Mock>(); + #endregion + + var processor = new DeleteTweetsProcessor(serviceMock.Object, loggerMock.Object); + var result = await processor.ProcessAsync(tweet, CancellationToken.None); + + #region Validations + serviceMock.VerifyAll(); + loggerMock.VerifyAll(); + + Assert.IsNotNull(result); + Assert.IsFalse(result.DeleteSuccessful); + #endregion + } + } +} \ No newline at end of file diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/TweetsCleanUp/RetrieveTweetsToDeleteProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/TweetsCleanUp/RetrieveTweetsToDeleteProcessorTests.cs new file mode 100644 index 0000000..b9f66d5 --- /dev/null +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/TweetsCleanUp/RetrieveTweetsToDeleteProcessorTests.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using System.Threading.Tasks.Dataflow; +using System.Xml.Linq; +using BirdsiteLive.Common.Settings; +using BirdsiteLive.DAL.Contracts; +using BirdsiteLive.DAL.Models; +using BirdsiteLive.Pipeline.Models; +using BirdsiteLive.Pipeline.Processors.TweetsCleanUp; +using Microsoft.Extensions.Logging; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Org.BouncyCastle.Crypto; + +namespace BirdsiteLive.Pipeline.Tests.Processors.TweetsCleanUp +{ + [TestClass] + public class RetrieveTweetsToDeleteProcessorTests + { + [TestMethod] + public async Task Process_Test() + { + #region Stubs + var settings = new InstanceSettings + { + + }; + var bufferBlock = new BufferBlock(); + + var tweetId1 = 42; + var tweetId2 = 43; + + var tweet1 = new SyncTweet + { + Id = tweetId1 + }; + var tweet2 = new SyncTweet + { + Id = tweetId2 + }; + var batch = new List + { + tweet1, + tweet2 + }; + #endregion + + #region Mocks + var dalMock = new Mock(MockBehavior.Strict); + dalMock + .Setup(x => x.GetTweetsOlderThanAsync(It.IsAny(), It.Is(y => y == -1), It.Is(y => y == 100))) + .ReturnsAsync(batch); + #endregion + + var processor = new RetrieveTweetsToDeleteProcessor(dalMock.Object, settings); + processor.GetTweetsAsync(bufferBlock, CancellationToken.None); + + await Task.Delay(TimeSpan.FromSeconds(1)); + + #region Validations + dalMock.VerifyAll(); + + Assert.AreEqual(batch.Count, bufferBlock.Count); + + bufferBlock.TryReceiveAll(out var all); + foreach (var tweet in all) + { + Assert.IsTrue(batch.Any(x => x.Id == tweet.Tweet.Id)); + } + #endregion + } + } +} \ No newline at end of file diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/TweetsCleanUp/SaveDeletedTweetStatusProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/TweetsCleanUp/SaveDeletedTweetStatusProcessorTests.cs new file mode 100644 index 0000000..10d21c7 --- /dev/null +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/TweetsCleanUp/SaveDeletedTweetStatusProcessorTests.cs @@ -0,0 +1,6 @@ +namespace BirdsiteLive.Pipeline.Tests.Processors.TweetsCleanUp; + +public class SaveDeletedTweetStatusProcessorTests +{ + +} \ No newline at end of file diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/TweetCleanUpPipelineTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/TweetCleanUpPipelineTests.cs new file mode 100644 index 0000000..eaaef54 --- /dev/null +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/TweetCleanUpPipelineTests.cs @@ -0,0 +1,6 @@ +namespace BirdsiteLive.Pipeline.Tests; + +public class TweetCleanUpPipelineTests +{ + +} \ No newline at end of file