Solution restructured to use multiple test projects
This commit is contained in:
153
test/AMWD.Common.AspNetCore.Tests/Utilities/HtmlHelperTest.cs
Normal file
153
test/AMWD.Common.AspNetCore.Tests/Utilities/HtmlHelperTest.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using System;
|
||||
using AMWD.Common.AspNetCore.Utilities;
|
||||
|
||||
namespace AMWD.Common.AspNetCore.Tests.Utilities
|
||||
{
|
||||
[TestClass]
|
||||
public class HtmlHelperTest
|
||||
{
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void ShouldThrowErrorOnEmptyColor()
|
||||
{
|
||||
// arrange
|
||||
|
||||
// act
|
||||
HtmlHelper.IsDarkColor("");
|
||||
|
||||
// assert
|
||||
// exception thrown
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(NotSupportedException))]
|
||||
public void ShouldThrowErrorOnUnsupportedColor()
|
||||
{
|
||||
// arrange
|
||||
|
||||
// act
|
||||
HtmlHelper.IsDarkColor("hsv(1, 2, 3)");
|
||||
|
||||
// assert
|
||||
// exception thrown
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[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);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow("#ffFFff")]
|
||||
[DataRow("FFffFF")]
|
||||
public void ShouldReturnLightColorForWhiteFullHex(string white)
|
||||
{
|
||||
// arrange
|
||||
|
||||
// act
|
||||
bool isDark = HtmlHelper.IsDarkColor(white);
|
||||
|
||||
// assert
|
||||
Assert.IsFalse(isDark);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow("#fFf")]
|
||||
[DataRow("FfF")]
|
||||
public void ShouldReturnLightColorForWhiteShortHex(string white)
|
||||
{
|
||||
// arrange
|
||||
|
||||
// act
|
||||
bool isDark = HtmlHelper.IsDarkColor(white);
|
||||
|
||||
// assert
|
||||
Assert.IsFalse(isDark);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[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);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow("#000000")]
|
||||
[DataRow("000000")]
|
||||
public void ShouldReturnDarkColorForBlackFullHex(string black)
|
||||
{
|
||||
// arrange
|
||||
|
||||
// act
|
||||
bool isDark = HtmlHelper.IsDarkColor(black);
|
||||
|
||||
// assert
|
||||
Assert.IsTrue(isDark);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow("#000")]
|
||||
[DataRow("000")]
|
||||
public void ShouldReturnDarkColorForBlackShortHex(string black)
|
||||
{
|
||||
// arrange
|
||||
|
||||
// act
|
||||
bool isDark = HtmlHelper.IsDarkColor(black);
|
||||
|
||||
// assert
|
||||
Assert.IsTrue(isDark);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[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);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace AMWD.Common.AspNetCore.Tests.Utilities
|
||||
{
|
||||
[TestClass]
|
||||
public class PasswordHelperTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void ShouldReturnNullHashWhenNullProvided()
|
||||
{
|
||||
// arrange
|
||||
string password = null;
|
||||
|
||||
// act
|
||||
string hash = PasswordHelper.HashPassword(password);
|
||||
|
||||
// assert
|
||||
Assert.IsNull(hash);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnEmptyHashWhenSpacesProvided()
|
||||
{
|
||||
// arrange
|
||||
string password = " ";
|
||||
|
||||
// act
|
||||
string hash = PasswordHelper.HashPassword(password);
|
||||
|
||||
// assert
|
||||
Assert.AreEqual("", hash);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnHashWhenTextProvided()
|
||||
{
|
||||
// arrange
|
||||
string password = "password";
|
||||
|
||||
// act
|
||||
string hash = PasswordHelper.HashPassword(password);
|
||||
|
||||
// assert
|
||||
Assert.IsTrue(!string.IsNullOrWhiteSpace(hash));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnFalseOnNullPassword()
|
||||
{
|
||||
// arrange
|
||||
string password = null;
|
||||
string hash = PasswordHelper.HashPassword(password);
|
||||
|
||||
// act
|
||||
bool isValid = PasswordHelper.VerifyPassword(password, hash, out bool rehashNeeded);
|
||||
|
||||
// assert
|
||||
Assert.IsFalse(isValid);
|
||||
Assert.IsFalse(rehashNeeded);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnFalseOnEmptyPassword()
|
||||
{
|
||||
// arrange
|
||||
string password = " ";
|
||||
string hash = PasswordHelper.HashPassword(password);
|
||||
|
||||
// act
|
||||
bool isValid = PasswordHelper.VerifyPassword(password, hash, out bool rehashNeeded);
|
||||
|
||||
// assert
|
||||
Assert.IsFalse(isValid);
|
||||
Assert.IsFalse(rehashNeeded);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnFalseOnNullHash()
|
||||
{
|
||||
// arrange
|
||||
string password = "password";
|
||||
string hash = null;
|
||||
|
||||
// act
|
||||
bool isValid = PasswordHelper.VerifyPassword(password, hash, out bool rehashNeeded);
|
||||
|
||||
// assert
|
||||
Assert.IsFalse(isValid);
|
||||
Assert.IsFalse(rehashNeeded);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnFalseOnEmptyHash()
|
||||
{
|
||||
// arrange
|
||||
string password = "password";
|
||||
string hash = "";
|
||||
|
||||
// act
|
||||
bool isValid = PasswordHelper.VerifyPassword(password, hash, out bool rehashNeeded);
|
||||
|
||||
// assert
|
||||
Assert.IsFalse(isValid);
|
||||
Assert.IsFalse(rehashNeeded);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnTrueOnSuccess()
|
||||
{
|
||||
// arrange
|
||||
string password = "password";
|
||||
string hash = PasswordHelper.HashPassword(password);
|
||||
|
||||
// act
|
||||
bool isValid = PasswordHelper.VerifyPassword(password, hash, out bool rehashNeeded);
|
||||
|
||||
// assert
|
||||
Assert.IsTrue(isValid);
|
||||
Assert.IsFalse(rehashNeeded);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnFalseOnError()
|
||||
{
|
||||
// arrange
|
||||
string password = "pass";
|
||||
string hash = PasswordHelper.HashPassword(password + "word");
|
||||
|
||||
// act
|
||||
bool isValid = PasswordHelper.VerifyPassword(password, hash, out bool rehashNeeded);
|
||||
|
||||
// assert
|
||||
Assert.IsFalse(isValid);
|
||||
Assert.IsFalse(rehashNeeded);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnTrueWithRehash()
|
||||
{
|
||||
// arrange
|
||||
var devHasher = new PasswordHasher<object>();
|
||||
var field = devHasher.GetType().GetField("_compatibilityMode", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
field.SetValue(devHasher, PasswordHasherCompatibilityMode.IdentityV2);
|
||||
|
||||
string password = "password";
|
||||
string hash = devHasher.HashPassword(null, password);
|
||||
|
||||
// act
|
||||
bool isValid = PasswordHelper.VerifyPassword(password, hash, out bool rehashNeeded);
|
||||
|
||||
// assert
|
||||
Assert.IsTrue(isValid);
|
||||
Assert.IsTrue(rehashNeeded);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user