added ModerationRepository Tests

This commit is contained in:
Nicolas Constant 2021-02-04 01:09:11 -05:00
parent 2d61ae9ae3
commit 024327ffe9
No known key found for this signature in database
GPG key ID: 1E9F677FB01A5688
4 changed files with 381 additions and 0 deletions

View file

@ -7,6 +7,8 @@ namespace BirdsiteLive.Domain.Tools
{
public static string[] Parse(string entry)
{
if (string.IsNullOrWhiteSpace(entry)) return new string[0];
var separationChar = '|';
if (entry.Contains(";")) separationChar = ';';
else if (entry.Contains(",")) separationChar = ',';

View file

@ -18,4 +18,8 @@
<ProjectReference Include="..\..\BirdsiteLive.Domain\BirdsiteLive.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Repository\" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,347 @@
using BirdsiteLive.Common.Settings;
using BirdsiteLive.Domain.Repository;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace BirdsiteLive.Domain.Tests.Repository
{
[TestClass]
public class ModerationRepositoryTests
{
#region GetModerationType
[TestMethod]
public void GetModerationType_Follower_WhiteListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
FollowersWhiteListing = "@me@domain.ext"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModerationTypeEnum.WhiteListing ,repo.GetModerationType(ModerationEntityTypeEnum.Follower));
Assert.AreEqual(ModerationTypeEnum.None, repo.GetModerationType(ModerationEntityTypeEnum.TwitterAccount));
#endregion
}
[TestMethod]
public void GetModerationType_TwitterAccount_WhiteListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
TwitterAccountsWhiteListing = "@me@domain.ext"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModerationTypeEnum.None, repo.GetModerationType(ModerationEntityTypeEnum.Follower));
Assert.AreEqual(ModerationTypeEnum.WhiteListing, repo.GetModerationType(ModerationEntityTypeEnum.TwitterAccount));
#endregion
}
[TestMethod]
public void GetModerationType_FollowerTwitterAccount_WhiteListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
FollowersWhiteListing = "@me@domain.ext",
TwitterAccountsWhiteListing = "@me@domain.ext"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModerationTypeEnum.WhiteListing, repo.GetModerationType(ModerationEntityTypeEnum.Follower));
Assert.AreEqual(ModerationTypeEnum.WhiteListing, repo.GetModerationType(ModerationEntityTypeEnum.TwitterAccount));
#endregion
}
[TestMethod]
public void GetModerationType_Follower_BlackListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
FollowersBlackListing = "@me@domain.ext"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModerationTypeEnum.BlackListing, repo.GetModerationType(ModerationEntityTypeEnum.Follower));
Assert.AreEqual(ModerationTypeEnum.None, repo.GetModerationType(ModerationEntityTypeEnum.TwitterAccount));
#endregion
}
[TestMethod]
public void GetModerationType_TwitterAccount_BlackListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
TwitterAccountsBlackListing = "@me@domain.ext"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModerationTypeEnum.None, repo.GetModerationType(ModerationEntityTypeEnum.Follower));
Assert.AreEqual(ModerationTypeEnum.BlackListing, repo.GetModerationType(ModerationEntityTypeEnum.TwitterAccount));
#endregion
}
[TestMethod]
public void GetModerationType_FollowerTwitterAccount_BlackListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
FollowersBlackListing = "@me@domain.ext",
TwitterAccountsBlackListing = "@me@domain.ext"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModerationTypeEnum.BlackListing, repo.GetModerationType(ModerationEntityTypeEnum.Follower));
Assert.AreEqual(ModerationTypeEnum.BlackListing, repo.GetModerationType(ModerationEntityTypeEnum.TwitterAccount));
#endregion
}
[TestMethod]
public void GetModerationType_Follower_BothListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
FollowersBlackListing = "@me@domain.ext",
FollowersWhiteListing = "@me@domain.ext",
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModerationTypeEnum.WhiteListing, repo.GetModerationType(ModerationEntityTypeEnum.Follower));
Assert.AreEqual(ModerationTypeEnum.None, repo.GetModerationType(ModerationEntityTypeEnum.TwitterAccount));
#endregion
}
[TestMethod]
public void GetModerationType_TwitterAccount_BothListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
TwitterAccountsBlackListing = "@me@domain.ext",
TwitterAccountsWhiteListing = "@me@domain.ext"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModerationTypeEnum.None, repo.GetModerationType(ModerationEntityTypeEnum.Follower));
Assert.AreEqual(ModerationTypeEnum.WhiteListing, repo.GetModerationType(ModerationEntityTypeEnum.TwitterAccount));
#endregion
}
[TestMethod]
public void GetModerationType_FollowerTwitterAccount_BothListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
FollowersBlackListing = "@me@domain.ext",
FollowersWhiteListing = "@me@domain.ext",
TwitterAccountsBlackListing = "@me@domain.ext",
TwitterAccountsWhiteListing = "@me@domain.ext"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModerationTypeEnum.WhiteListing, repo.GetModerationType(ModerationEntityTypeEnum.Follower));
Assert.AreEqual(ModerationTypeEnum.WhiteListing, repo.GetModerationType(ModerationEntityTypeEnum.TwitterAccount));
#endregion
}
#endregion
#region CheckStatus
[TestMethod]
public void CheckStatus_Follower_WhiteListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
FollowersWhiteListing = "@me@domain.ext"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModeratedTypeEnum.WhiteListed, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@me@domain.ext"));
Assert.AreEqual(ModeratedTypeEnum.None, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@me2@domain.ext"));
#endregion
}
[TestMethod]
public void CheckStatus_Follower_WhiteListing_Instance_Test()
{
#region Stubs
var settings = new ModerationSettings
{
FollowersWhiteListing = "domain.ext"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModeratedTypeEnum.WhiteListed, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@me@domain.ext"));
Assert.AreEqual(ModeratedTypeEnum.WhiteListed, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@me2@domain.ext"));
Assert.AreEqual(ModeratedTypeEnum.None, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@me2@domain2.ext"));
#endregion
}
[TestMethod]
public void CheckStatus_Follower_WhiteListing_SubDomain_Test()
{
#region Stubs
var settings = new ModerationSettings
{
FollowersWhiteListing = "*.domain.ext"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModeratedTypeEnum.WhiteListed, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@me@s.domain.ext"));
Assert.AreEqual(ModeratedTypeEnum.WhiteListed, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@me2@s2.domain.ext"));
Assert.AreEqual(ModeratedTypeEnum.None, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@me2@domain.ext"));
Assert.AreEqual(ModeratedTypeEnum.None, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@me2@domain2.ext"));
#endregion
}
[TestMethod]
public void CheckStatus_TwitterAccount_WhiteListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
TwitterAccountsWhiteListing = "handle"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModeratedTypeEnum.WhiteListed, repo.CheckStatus(ModerationEntityTypeEnum.TwitterAccount, "handle"));
Assert.AreEqual(ModeratedTypeEnum.None, repo.CheckStatus(ModerationEntityTypeEnum.TwitterAccount, "handle2"));
#endregion
}
[TestMethod]
public void CheckStatus_Follower_BlackListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
FollowersBlackListing = "@me@domain.ext"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModeratedTypeEnum.BlackListed, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@me@domain.ext"));
Assert.AreEqual(ModeratedTypeEnum.None, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@me2@domain.ext"));
#endregion
}
[TestMethod]
public void CheckStatus_TwitterAccount_BlackListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
TwitterAccountsBlackListing = "handle"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModeratedTypeEnum.BlackListed, repo.CheckStatus(ModerationEntityTypeEnum.TwitterAccount, "handle"));
Assert.AreEqual(ModeratedTypeEnum.None, repo.CheckStatus(ModerationEntityTypeEnum.TwitterAccount, "handle2"));
#endregion
}
[TestMethod]
public void CheckStatus_Follower_BothListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
FollowersWhiteListing = "@me@domain.ext",
FollowersBlackListing = "@me@domain.ext"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModeratedTypeEnum.WhiteListed, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@me@domain.ext"));
Assert.AreEqual(ModeratedTypeEnum.None, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@me2@domain.ext"));
#endregion
}
[TestMethod]
public void CheckStatus_TwitterAccount_BothListing_Test()
{
#region Stubs
var settings = new ModerationSettings
{
TwitterAccountsWhiteListing = "handle",
TwitterAccountsBlackListing = "handle"
};
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModeratedTypeEnum.WhiteListed, repo.CheckStatus(ModerationEntityTypeEnum.TwitterAccount, "handle"));
Assert.AreEqual(ModeratedTypeEnum.None, repo.CheckStatus(ModerationEntityTypeEnum.TwitterAccount, "handle2"));
#endregion
}
[TestMethod]
public void CheckStatus_None_Test()
{
#region Stubs
var settings = new ModerationSettings();
#endregion
var repo = new ModerationRepository(settings);
#region Validations
Assert.AreEqual(ModeratedTypeEnum.None, repo.CheckStatus(ModerationEntityTypeEnum.Follower, "@handle@domain.ext"));
Assert.AreEqual(ModeratedTypeEnum.None, repo.CheckStatus(ModerationEntityTypeEnum.TwitterAccount, "handle"));
#endregion
}
#endregion
}
}

View file

@ -22,6 +22,34 @@ namespace BirdsiteLive.Domain.Tests.Tools
#endregion
}
[TestMethod]
public void Parse_Null_Test()
{
#region Stubs
string entry = null;
#endregion
var result = ModerationParser.Parse(entry);
#region Validations
Assert.AreEqual(0, result.Length);
#endregion
}
[TestMethod]
public void Parse_WhiteSpace_Test()
{
#region Stubs
var entry = " ";
#endregion
var result = ModerationParser.Parse(entry);
#region Validations
Assert.AreEqual(0, result.Length);
#endregion
}
[TestMethod]
public void Parse_PipeSeparator_Test()
{