public void Test_verify_input_length_less_than_checksum() { var checkSum = new CheckSum(new[] { 'A' }, 3); var appender = new CheckSumAppender("-", checkSum); Assert.IsFalse(appender.Verify("")); Assert.IsFalse(appender.Verify("A")); Assert.IsFalse(appender.Verify("AA")); Assert.IsFalse(appender.Verify("AAA")); }
public void Test_verify_is_false() { var checkSum = new CheckSum(10); var appender = new CheckSumAppender("-", checkSum); var input = appender.Append("ABCDEFGHIJKLMNOPQRSTUVW"); Assert.IsTrue(appender.Verify(input)); Assert.IsFalse(appender.Verify("A" + input)); Assert.IsFalse(appender.Verify(input + "A")); Assert.IsFalse(appender.Verify("B" + new String(input.Skip(1).ToArray()))); }
public void Test_verify_input_null() { var checkSum = new CheckSum(new[] { 'A' }, 3); var appender = new CheckSumAppender("-", checkSum); TestHelper.AssertException <ArgumentNullException>(() => appender.Verify(null)); }
/// <summary> /// Checks if the check sum is valid. /// </summary> /// <param name="hardwareIdentifier"> /// The hardware identifier to check. /// </param> /// <returns> /// true if the hardware identifier has a valid check sum or the hardware /// identifier is equal to <see cref="NoHardwareIdentifier"/>; otherwise false. /// </returns> internal static bool IsCheckSumValid(string hardwareIdentifier) { if (hardwareIdentifier == NoHardwareIdentifier) { return(true); } return(CheckSumAppender.Verify(hardwareIdentifier)); }
private static void AssertCheckSum(string separator, string input) { var checkSum = new CheckSum(new[] { 'A' }, 3); var appender = new CheckSumAppender(separator, checkSum); var expected = input + separator + "AAA"; Assert.AreEqual(expected, appender.Append(input)); Assert.IsTrue(appender.Verify(expected)); }
/// <summary> /// Validates the check sum of the specified serial number. /// </summary> /// <param name="serialNumber"> /// The serial number to check. /// </param> /// <returns> /// true if the check sum is valid or the serial number is equal to <see cref="NoSerialNumber"/>; /// otherwise false. /// </returns> internal static bool IsCheckSumValid(string serialNumber) { return(CheckSumAppender.Verify(serialNumber)); }