using System; using AMWD.Common.AspNetCore.Utilities; namespace AMWD.Common.AspNetCore.Tests.Utilities { [TestClass] public class HtmlHelperTest { [TestMethod] [DataRow(null)] [DataRow("")] [DataRow(" ")] public void ShouldThrowErrorOnEmptyColor(string color) { // arrange // act & assert Assert.ThrowsExactly(() => HtmlHelper.IsDarkColor(color)); } [TestMethod] public void ShouldThrowErrorOnUnsupportedColor() { // arrange // act Assert.ThrowsExactly(() => HtmlHelper.IsDarkColor("hsv(1, 2, 3)")); // assert // exception thrown } [TestMethod] [DataRow("rgb(255, 255, 255)")] [DataRow("rgba(255, 255, 255, .5)")] public void ShouldReturnLightColorForWhiteRgb(string white) { // arrange // act bool isDark = HtmlHelper.IsDarkColor(white); // assert Assert.IsFalse(isDark); } [TestMethod] [DataRow("#ffFFff")] [DataRow("FFffFF")] public void ShouldReturnLightColorForWhiteFullHex(string white) { // arrange // act bool isDark = HtmlHelper.IsDarkColor(white); // assert Assert.IsFalse(isDark); } [TestMethod] [DataRow("#fFf")] [DataRow("FfF")] public void ShouldReturnLightColorForWhiteShortHex(string white) { // arrange // act bool isDark = HtmlHelper.IsDarkColor(white); // assert Assert.IsFalse(isDark); } [TestMethod] [DataRow("rgb(0, 0, 0)")] [DataRow("rgba(0, 0, 0, .5)")] public void ShouldReturnDarkColorForBlackRgb(string black) { // arrange // act bool isDark = HtmlHelper.IsDarkColor(black); // assert Assert.IsTrue(isDark); } [TestMethod] [DataRow("#000000")] [DataRow("000000")] public void ShouldReturnDarkColorForBlackFullHex(string black) { // arrange // act bool isDark = HtmlHelper.IsDarkColor(black); // assert Assert.IsTrue(isDark); } [TestMethod] [DataRow("#000")] [DataRow("000")] public void ShouldReturnDarkColorForBlackShortHex(string black) { // arrange // act bool isDark = HtmlHelper.IsDarkColor(black); // assert Assert.IsTrue(isDark); } [TestMethod] [DataRow("rgb(255, 88, 0)")] [DataRow("rgb(0, 218, 0)")] [DataRow("rgb(0, 168, 255)")] [DataRow("rgb(255, 38, 255)")] [DataRow("rgb(128, 128, 128)")] public void ShouldReturnLightColorForBorderColors(string color) { // arrange // act bool isDark = HtmlHelper.IsDarkColor(color); // assert Assert.IsFalse(isDark); } [TestMethod] [DataRow("rgb(253, 88, 0)")] [DataRow("rgb(0, 217, 0)")] [DataRow("rgb(0, 168, 253)")] [DataRow("rgb(254, 38, 254)")] [DataRow("rgb(127, 127, 127)")] public void ShouldReturnDarkColorForBorderColors(string color) { // arrange // act bool isDark = HtmlHelper.IsDarkColor(color); // assert Assert.IsTrue(isDark); } } }