added ModerationParser Tests

This commit is contained in:
Nicolas Constant 2021-02-04 00:13:49 -05:00
parent 4b0fe65776
commit 2d61ae9ae3
No known key found for this signature in database
GPG key ID: 1E9F677FB01A5688
2 changed files with 123 additions and 1 deletions

View file

@ -13,7 +13,8 @@ namespace BirdsiteLive.Domain.Tools
var splitEntries = entry
.Split(new[] {separationChar}, StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.ToLowerInvariant());
.Where(x => !string.IsNullOrWhiteSpace(x))
.Select(x => x.ToLowerInvariant().Trim());
return splitEntries.ToArray();
}
}

View file

@ -0,0 +1,121 @@
using System.Linq;
using BirdsiteLive.Domain.Tools;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace BirdsiteLive.Domain.Tests.Tools
{
[TestClass]
public class ModerationParserTests
{
[TestMethod]
public void Parse_Simple_Test()
{
#region Stubs
var entry = "test";
#endregion
var result = ModerationParser.Parse(entry);
#region Validations
Assert.AreEqual(1, result.Length);
Assert.AreEqual("test", result.First());
#endregion
}
[TestMethod]
public void Parse_PipeSeparator_Test()
{
#region Stubs
var entry = "test|test2";
#endregion
var result = ModerationParser.Parse(entry);
#region Validations
Assert.AreEqual(2, result.Length);
Assert.AreEqual("test", result[0]);
Assert.AreEqual("test2", result[1]);
#endregion
}
[TestMethod]
public void Parse_SemicolonSeparator_Test()
{
#region Stubs
var entry = "test;test2";
#endregion
var result = ModerationParser.Parse(entry);
#region Validations
Assert.AreEqual(2, result.Length);
Assert.AreEqual("test", result[0]);
Assert.AreEqual("test2", result[1]);
#endregion
}
[TestMethod]
public void Parse_CommaSeparator_Test()
{
#region Stubs
var entry = "test,test2";
#endregion
var result = ModerationParser.Parse(entry);
#region Validations
Assert.AreEqual(2, result.Length);
Assert.AreEqual("test", result[0]);
Assert.AreEqual("test2", result[1]);
#endregion
}
[TestMethod]
public void Parse_SemicolonSeparator_EmptyEntry_Test()
{
#region Stubs
var entry = "test;test2;";
#endregion
var result = ModerationParser.Parse(entry);
#region Validations
Assert.AreEqual(2, result.Length);
Assert.AreEqual("test", result[0]);
Assert.AreEqual("test2", result[1]);
#endregion
}
[TestMethod]
public void Parse_SemicolonSeparator_WhiteSpace_Test()
{
#region Stubs
var entry = "test; test2";
#endregion
var result = ModerationParser.Parse(entry);
#region Validations
Assert.AreEqual(2, result.Length);
Assert.AreEqual("test", result[0]);
Assert.AreEqual("test2", result[1]);
#endregion
}
[TestMethod]
public void Parse_SemicolonSeparator_EmptyEntry_WhiteSpace_Test()
{
#region Stubs
var entry = "test; test2; ";
#endregion
var result = ModerationParser.Parse(entry);
#region Validations
Assert.AreEqual(2, result.Length);
Assert.AreEqual("test", result[0]);
Assert.AreEqual("test2", result[1]);
#endregion
}
}
}