diff --git a/src/BirdsiteLive.sln b/src/BirdsiteLive.sln index d345e68..4868b12 100644 --- a/src/BirdsiteLive.sln +++ b/src/BirdsiteLive.sln @@ -41,7 +41,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BirdsiteLive.Pipeline.Tests EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BirdsiteLive.DAL.Tests", "Tests\BirdsiteLive.DAL.Tests\BirdsiteLive.DAL.Tests.csproj", "{5A1E3EB5-6CBB-470D-8A0D-10F8C18353D5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BirdsiteLive.Moderation", "BirdsiteLive.Moderation\BirdsiteLive.Moderation.csproj", "{4BE541AC-8A93-4FA3-98AC-956CC2D5B748}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BirdsiteLive.Moderation", "BirdsiteLive.Moderation\BirdsiteLive.Moderation.csproj", "{4BE541AC-8A93-4FA3-98AC-956CC2D5B748}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BirdsiteLive.Moderation.Tests", "Tests\BirdsiteLive.Moderation.Tests\BirdsiteLive.Moderation.Tests.csproj", "{0A311BF3-4FD9-4303-940A-A3778890561C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -113,6 +115,10 @@ Global {4BE541AC-8A93-4FA3-98AC-956CC2D5B748}.Debug|Any CPU.Build.0 = Debug|Any CPU {4BE541AC-8A93-4FA3-98AC-956CC2D5B748}.Release|Any CPU.ActiveCfg = Release|Any CPU {4BE541AC-8A93-4FA3-98AC-956CC2D5B748}.Release|Any CPU.Build.0 = Release|Any CPU + {0A311BF3-4FD9-4303-940A-A3778890561C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0A311BF3-4FD9-4303-940A-A3778890561C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0A311BF3-4FD9-4303-940A-A3778890561C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0A311BF3-4FD9-4303-940A-A3778890561C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -133,6 +139,7 @@ Global {BF51CA81-5A7A-46F8-B4FB-861C6BE59298} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94} {5A1E3EB5-6CBB-470D-8A0D-10F8C18353D5} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94} {4BE541AC-8A93-4FA3-98AC-956CC2D5B748} = {DA3C160C-4811-4E26-A5AD-42B81FAF2D7C} + {0A311BF3-4FD9-4303-940A-A3778890561C} = {A32D3458-09D0-4E0A-BA4B-8C411B816B94} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {69E8DCAD-4C37-4010-858F-5F94E6FBABCE} diff --git a/src/Tests/BirdsiteLive.Moderation.Tests/BirdsiteLive.Moderation.Tests.csproj b/src/Tests/BirdsiteLive.Moderation.Tests/BirdsiteLive.Moderation.Tests.csproj new file mode 100644 index 0000000..e85b592 --- /dev/null +++ b/src/Tests/BirdsiteLive.Moderation.Tests/BirdsiteLive.Moderation.Tests.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + + + diff --git a/src/Tests/BirdsiteLive.Moderation.Tests/ModerationPipelineTests.cs b/src/Tests/BirdsiteLive.Moderation.Tests/ModerationPipelineTests.cs new file mode 100644 index 0000000..7928b34 --- /dev/null +++ b/src/Tests/BirdsiteLive.Moderation.Tests/ModerationPipelineTests.cs @@ -0,0 +1,106 @@ +using System; +using System.Threading.Tasks; +using BirdsiteLive.Domain.Repository; +using BirdsiteLive.Moderation.Processors; +using Microsoft.Extensions.Logging; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace BirdsiteLive.Moderation.Tests +{ + [TestClass] + public class ModerationPipelineTests + { + [TestMethod] + public async Task ApplyModerationSettingsAsync_None() + { + #region Mocks + var moderationRepositoryMock = new Mock(MockBehavior.Strict); + moderationRepositoryMock + .Setup(x => x.GetModerationType(ModerationEntityTypeEnum.Follower)) + .Returns(ModerationTypeEnum.None); + moderationRepositoryMock + .Setup(x => x.GetModerationType(ModerationEntityTypeEnum.TwitterAccount)) + .Returns(ModerationTypeEnum.None); + + var followerModerationProcessorMock = new Mock(MockBehavior.Strict); + var twitterAccountModerationProcessorMock = new Mock(MockBehavior.Strict); + var loggerMock = new Mock>(MockBehavior.Strict); + #endregion + + var pipeline = new ModerationPipeline(moderationRepositoryMock.Object, followerModerationProcessorMock.Object, twitterAccountModerationProcessorMock.Object, loggerMock.Object); + await pipeline.ApplyModerationSettingsAsync(); + + #region Validations + moderationRepositoryMock.VerifyAll(); + followerModerationProcessorMock.VerifyAll(); + twitterAccountModerationProcessorMock.VerifyAll(); + loggerMock.VerifyAll(); + #endregion + } + + [TestMethod] + public async Task ApplyModerationSettingsAsync_Process() + { + #region Mocks + var moderationRepositoryMock = new Mock(MockBehavior.Strict); + moderationRepositoryMock + .Setup(x => x.GetModerationType(ModerationEntityTypeEnum.Follower)) + .Returns(ModerationTypeEnum.WhiteListing); + moderationRepositoryMock + .Setup(x => x.GetModerationType(ModerationEntityTypeEnum.TwitterAccount)) + .Returns(ModerationTypeEnum.BlackListing); + + var followerModerationProcessorMock = new Mock(MockBehavior.Strict); + followerModerationProcessorMock + .Setup(x => x.ProcessAsync( + It.Is(y => y == ModerationTypeEnum.WhiteListing))) + .Returns(Task.CompletedTask); + + var twitterAccountModerationProcessorMock = new Mock(MockBehavior.Strict); + twitterAccountModerationProcessorMock + .Setup(x => x.ProcessAsync( + It.Is(y => y == ModerationTypeEnum.BlackListing))) + .Returns(Task.CompletedTask); + + var loggerMock = new Mock>(MockBehavior.Strict); + #endregion + + var pipeline = new ModerationPipeline(moderationRepositoryMock.Object, followerModerationProcessorMock.Object, twitterAccountModerationProcessorMock.Object, loggerMock.Object); + await pipeline.ApplyModerationSettingsAsync(); + + #region Validations + moderationRepositoryMock.VerifyAll(); + followerModerationProcessorMock.VerifyAll(); + twitterAccountModerationProcessorMock.VerifyAll(); + loggerMock.VerifyAll(); + #endregion + } + + [TestMethod] + public async Task ApplyModerationSettingsAsync_Exception() + { + #region Mocks + var moderationRepositoryMock = new Mock(MockBehavior.Strict); + moderationRepositoryMock + .Setup(x => x.GetModerationType(ModerationEntityTypeEnum.Follower)) + .Throws(new Exception()); + + var followerModerationProcessorMock = new Mock(MockBehavior.Strict); + var twitterAccountModerationProcessorMock = new Mock(MockBehavior.Strict); + + var loggerMock = new Mock>(); + #endregion + + var pipeline = new ModerationPipeline(moderationRepositoryMock.Object, followerModerationProcessorMock.Object, twitterAccountModerationProcessorMock.Object, loggerMock.Object); + await pipeline.ApplyModerationSettingsAsync(); + + #region Validations + moderationRepositoryMock.VerifyAll(); + followerModerationProcessorMock.VerifyAll(); + twitterAccountModerationProcessorMock.VerifyAll(); + loggerMock.VerifyAll(); + #endregion + } + } +}