public void Scramble_TestMethod() { BSNVerification verification = new BSNVerification(); foreach (string validBSNTestNummer in validTestBSNs) { scamble_TestMethod(verification, validBSNTestNummer); } runRandomManyTimesForAllLengths(verification, scamble_TestMethod); }
public void Complete_TestMethod() { BSNVerification verification = new BSNVerification(); foreach (string becomesNineDigit in becomesNineDigits) { string nineDigit = verification.Complete(becomesNineDigit); bool valid = verification.IsValid(nineDigit); Assert.IsTrue(valid, "Completed {0} into {1}, but {1} was not valid", becomesNineDigit, nineDigit); } }
private static void runRandomManyTimesForAllLengths(BSNVerification verification, Action <BSNVerification, string> action) { for (int i = 0; i < 1000; i++) { for (int length = BSNVerification.MinBSNLength; length < BSNVerification.MaxBSNLength; length++) { string generatedBSN = verification.Random(length); action(verification, generatedBSN); } } }
private static void scamble_TestMethod(BSNVerification verification, string validBSNTestNummer) { string rot5 = verification.Scramble(validBSNTestNummer); { int result = rot5.Length; int expected = validBSNTestNummer.Length; Assert.AreEqual(expected, result, "Expected length {0} of BSNVerification.Rot5 to the same as the plain length {1}", result, expected); } foreach (char item in rot5) { bool result = char.IsNumber(item) || (item == '.'); bool expected = true; Assert.AreEqual(expected, result, "Expected all characters returned by BSNVerification.Rot5 to be numeric or dot, but {0} isn't", item); } }
public void IsValid_TestMethod() { BSNVerification verification = new BSNVerification(); foreach (string inValidBSNTestNummer in invalidTestBSNs) { bool result = verification.IsValid(inValidBSNTestNummer); bool expected = false; Assert.AreEqual(expected, result, "Expected BSNVerification.IsValid({0} to be {1}", inValidBSNTestNummer, expected); } foreach (string validBSNTestNummer in validTestBSNs) { bool result = verification.IsValid(validBSNTestNummer); bool expected = true; Assert.AreEqual(expected, result, "Expected BSNVerification.IsValid({0} to be {1}", validBSNTestNummer, expected); } }
public void Complete_cannotBecomeTenDigits_TestMethod() { BSNVerification verification = new BSNVerification(); Exception exception = null; foreach (string cannotBecomeNineDigit in cannotBecomeNineDigits) { try { string nineDigit = verification.Complete(cannotBecomeNineDigit); Assert.Inconclusive("It should not be possible that {0} completed into {1}", Reflector.GetNameSeparatorValue(new { cannotBecomeNineDigit }), Reflector.GetNameSeparatorValue(new { nineDigit })); } catch (Exception ex) { exception = ex; continue; } } throw exception; }
public void Random_validLengths_TestMethod() { BSNVerification verification = new BSNVerification(); runRandomManyTimesForAllLengths(verification, validateGeneratedNumber); }
private static void validateGeneratedNumber(BSNVerification verification, string generatedBSN) { bool validBSN = verification.IsValid(generatedBSN); Assert.IsTrue(validBSN, "Generated {0} is invalid", Reflector.GetNameSeparatorValue(new { generatedBSN })); }
public void Random_invalidLength_TestMethod() { BSNVerification verification = new BSNVerification(); string generatedBSN = verification.Random(100); // invalid length; should throw an exception }