added ModerationPipeline tests
This commit is contained in:
parent
af092d942d
commit
5d2d5ffd52
3 changed files with 135 additions and 1 deletions
|
@ -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}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||
<PackageReference Include="Moq" Version="4.14.5" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="1.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\BirdsiteLive.Moderation\BirdsiteLive.Moderation.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -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<IModerationRepository>(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<IFollowerModerationProcessor>(MockBehavior.Strict);
|
||||
var twitterAccountModerationProcessorMock = new Mock<ITwitterAccountModerationProcessor>(MockBehavior.Strict);
|
||||
var loggerMock = new Mock<ILogger<ModerationPipeline>>(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<IModerationRepository>(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<IFollowerModerationProcessor>(MockBehavior.Strict);
|
||||
followerModerationProcessorMock
|
||||
.Setup(x => x.ProcessAsync(
|
||||
It.Is<ModerationTypeEnum>(y => y == ModerationTypeEnum.WhiteListing)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var twitterAccountModerationProcessorMock = new Mock<ITwitterAccountModerationProcessor>(MockBehavior.Strict);
|
||||
twitterAccountModerationProcessorMock
|
||||
.Setup(x => x.ProcessAsync(
|
||||
It.Is<ModerationTypeEnum>(y => y == ModerationTypeEnum.BlackListing)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var loggerMock = new Mock<ILogger<ModerationPipeline>>(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<IModerationRepository>(MockBehavior.Strict);
|
||||
moderationRepositoryMock
|
||||
.Setup(x => x.GetModerationType(ModerationEntityTypeEnum.Follower))
|
||||
.Throws(new Exception());
|
||||
|
||||
var followerModerationProcessorMock = new Mock<IFollowerModerationProcessor>(MockBehavior.Strict);
|
||||
var twitterAccountModerationProcessorMock = new Mock<ITwitterAccountModerationProcessor>(MockBehavior.Strict);
|
||||
|
||||
var loggerMock = new Mock<ILogger<ModerationPipeline>>();
|
||||
#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
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue