public void Setup() { var mappingSource = new Mock <IRuleMappingSource>(); mappingSource.Setup(ms => ms.GetModulusWeightMappings).Returns(new[] { ModulusWeightMapping.From( "230872 230872 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "499273 499273 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1 "), ModulusWeightMapping.From( "499273 499273 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1 "), ModulusWeightMapping.From( "200000 200002 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1 6") }); _fakedModulusWeightTable = new Mock <IModulusWeightTable>(); _fakedModulusWeightTable.Setup(fmwt => fmwt.RuleMappings).Returns(mappingSource.Object.GetModulusWeightMappings.ToList()); _fakedModulusWeightTable.Setup(fmwt => fmwt.GetRuleMappings(new SortCode("499273"))) .Returns(new [] { ModulusWeightMapping.From ("499273 499273 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1 "), ModulusWeightMapping.From ("499273 499273 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ") }); _fakedModulusWeightTable.Setup(fmwt => fmwt.GetRuleMappings(new SortCode("118765"))) .Returns(new [] { ModulusWeightMapping.From ("110000 119280 DblAl 0 0 2 1 2 1 2 1 2 1 2 1 2 1 1") }); _firstStepDblAlCalculator = new FirstDoubleAlternateCalculator(); _secondStepDblAlCalculator = new SecondDoubleAlternateCalculator(); }
public ValacdosSource() { var assembly = Assembly.GetExecutingAssembly(); string mappings; using (var stream = assembly.GetManifestResourceStream("ModulusChecking.Resources.valacdos.txt")) // ReSharper disable once AssignNullToNotNullAttribute using (var reader = new StreamReader(stream)) { mappings = reader.ReadToEnd(); } if (mappings.Contains('\t')) { throw new Exception( "valacdos.txt contains a tab instead of a set of spaces.\n\nUse a text editor to search for regex \\t to identify the issue."); } GetModulusWeightMappings = mappings .Trim() .Split(new[] { "\r\n", "\n" }, StringSplitOptions.None) .Where(row => row.Length > 0) .Select(row => ModulusWeightMapping.From(row)) .ToArray(); }
public void CanAddAlgorithm(string row, ModulusAlgorithm expected) { var actual = ModulusWeightMapping.From(row); Assert.NotNull(actual); Assert.AreEqual(expected, actual.Algorithm); }
public void ExceptionFiveFirstCheckCorrectSecondIncorrect() { var details = new BankAccountDetails("938063", "15764273"); var mapping = ModulusWeightMapping.From("012345 012346 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 0 5"); var actual = _check.GetModulusSum(details, mapping); Assert.AreEqual(58, actual); }
public void ExceptionFiveValidationTestSumCheck() { var details = new BankAccountDetails("938611", "07806039"); var mapping = ModulusWeightMapping.From("012345 012346 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 0 5"); var actual = _check.GetModulusSum(details, mapping); Assert.AreEqual(51, actual); }
public void CalculatesSumAsExpected() { var details = new BankAccountDetails("499273", "12345678"); var mapping = ModulusWeightMapping.From("012345 012346 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 1"); var actual = _check.GetModulusSum(details, mapping); Assert.AreEqual(70, actual); }
public ValacdosSource() { GetModulusWeightMappings = Resources.valacdos .Split(new[] { "\r\n", "\n" }, StringSplitOptions.None) .Where(row => row.Length > 0) .Select(row => ModulusWeightMapping.From(row)) .ToArray(); }
public void CalculatesExceptionSixTestCaseCorrectly() { var details = new BankAccountDetails("202959", "63748472"); var mapping = ModulusWeightMapping.From("012345 012346 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 1"); var actual = _check.GetModulusSum(details, mapping); Assert.AreEqual(60, actual); }
//938000 938696 Mod11 7 6 5 4 3 2 7 6 5 4 3 2 0 0 5 //938000 938696 DblAl 2 1 2 1 2 1 2 1 2 1 2 1 2 0 5 public void ExceptionFiveDoubleAlternateWhenBothPass() { var details = new BankAccountDetails("938063", "55065200"); var mapping = ModulusWeightMapping.From("938000 938696 DblAl 2 1 2 1 2 1 2 1 2 1 2 1 2 0 5"); var actual = _check.GetModulusSum(details, mapping); Assert.AreEqual(40, actual); Assert.AreEqual(0, actual % 10); }
private void ValidateStandardModulusWeightSumCalculation(string sc, string an, string mappingString, int expected) { var details = new BankAccountDetails(sc, an) { WeightMappings = new [] { ModulusWeightMapping.From(mappingString) } }; var actual = _checker.GetModulusSum(details, details.WeightMappings.First()); Assert.AreEqual(expected, actual); }
public void CanLoadWeightingValues() { var actual = ModulusWeightMapping.From("230872 230872 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1"); var expectedWeightValues = new[] { 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1 }; for (var i = 0; i < actual.WeightValues.Count(); i++) { Assert.AreEqual(actual.WeightValues.ElementAt(i), expectedWeightValues[i]); } }
public void ExceptionOneChangesSum() { var details = new BankAccountDetails("123456", "12345678"); var mapping = ModulusWeightMapping.From("012345 012346 dblal 1 2 3 4 5 6 7 8 9 10 11 12 13 14"); var withNoException = _check.GetModulusSum(details, mapping); mapping = ModulusWeightMapping.From("012345 012346 dblal 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1"); var withException = _check.GetModulusSum(details, mapping); Assert.IsTrue(withNoException + 27 == withException); }
public void CanProcessDoubleAlternate() { var bankDetails = new BankAccountDetails("123456", "12345678") { WeightMappings = new[] { ModulusWeightMapping.From( "090150 090156 DBLAL 0 0 0 0 0 9 8 7 6 5 4 3 2 1") } }; _targetRouter.GetModulusCalculation(bankDetails); _mockFirstDoubleAlternator.Verify(calc => calc.Process(bankDetails)); }
public void CanProcessModulusElevenExceptionFive() { var bankDetails = new BankAccountDetails("123456", "12345678") { WeightMappings = new[] { ModulusWeightMapping.From( "090150 090156 MOD11 0 0 0 0 0 9 8 7 6 5 4 3 2 1 5") } }; _targetRouterForExceptionFive.GetModulusCalculation(bankDetails); _mockFirstStandardElevenExceptionFiveCalculator.Verify(calc => calc.Process(bankDetails)); }
public void CanProcessDoubleAlternateWithExceptionFive() { var bankDetails = new BankAccountDetails("123456", "12345678") { WeightMappings = new[] { ModulusWeightMapping.From( "090150 090156 DBLAL 0 0 0 0 0 9 8 7 6 5 4 3 2 1 5"), ModulusWeightMapping.From( "090150 090156 DBLAL 0 0 0 0 0 9 8 7 6 5 4 3 2 1 5") } }; _targetRouterForExceptionFive.GetModulusCalculation(bankDetails); _mockSecondDoubleAlternateExceptionFiveCalculator.Verify(calc => calc.Process(bankDetails)); }
public void CanProcessModulusTen() { var bankDetails = new BankAccountDetails("123456", "12345678") { WeightMappings = new[] { ModulusWeightMapping.From( "090150 090156 MOD10 0 0 0 0 0 9 8 7 6 5 4 3 2 1"), ModulusWeightMapping.From( "090150 090156 MOD10 0 0 0 0 0 9 8 7 6 5 4 3 2 1") } }; _targetRouter.GetModulusCalculation(bankDetails); _mockSecondStandardTenCalculator.Verify(calc => calc.Process(bankDetails)); }
private static IEnumerable <ModulusWeightMapping> BuildMappingList(string sc, int desiredMappings, int exception) { var items = new List <ModulusWeightMapping>(); for (var i = 0; i < desiredMappings; i++) { exception = i == 0 ? exception == ModulusExceptionFlag ? i : exception : i; items.Add( ModulusWeightMapping.From( string.Format( "{0} 089999 MOD10 0 0 0 0 0 0 7 1 3 7 1 3 7 7 {1}", sc, exception))); } return(items); }
public void Before() { var mappingSource = new Mock <IRuleMappingSource>(); mappingSource.Setup(ms => ms.GetModulusWeightMappings).Returns(new [] { ModulusWeightMapping.From( "000000 000100 MOD10 0 0 0 0 0 0 7 5 8 3 4 6 2 1 "), ModulusWeightMapping.From( "499273 499273 DBLAL 0 0 2 1 2 1 2 1 2 1 2 1 2 1 1"), ModulusWeightMapping.From( "200000 200002 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1 6") }); _fakedModulusWeightTable = new Mock <IModulusWeightTable>(); _fakedModulusWeightTable.Setup(fmwt => fmwt.RuleMappings).Returns(mappingSource.Object.GetModulusWeightMappings); _fakedModulusWeightTable.Setup(fmwt => fmwt.GetRuleMappings(new SortCode("000000"))) .Returns(new [] { ModulusWeightMapping.From("000000 000100 MOD10 0 0 0 0 0 0 7 5 8 3 4 6 2 1 "), }); }
public void Before() { var mappingSource = new Mock <IRuleMappingSource>(); mappingSource.Setup(ms => ms.GetModulusWeightMappings) .Returns(new [] { ModulusWeightMapping.From( "010004 010006 MOD10 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010004 010006 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010007 010010 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010011 010013 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010014 010014 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5") }); _mockModulusWeightTable = new Mock <IModulusWeightTable>(); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("010004"))).Returns( new[] { ModulusWeightMapping.From( "010004 010006 MOD10 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010004 010006 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), }); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("010009"))).Returns( new [] { ModulusWeightMapping.From( "010007 010010 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1") }); _firstModulusCalculatorStep = new Mock <FirstModulusCalculatorStep>(); _firstModulusCalculatorStep.Setup(fmc => fmc.Process(It.IsAny <BankAccountDetails>())). Returns(false); _ruleStep = new ConfirmDetailsAreValidForModulusCheck(_firstModulusCalculatorStep.Object); }
public void Before() { _standardTen = new Mock <SecondStandardModulusTenCalculator>(); _standardEleven = new Mock <SecondStandardModulusElevenCalculator>(); _doubleAlternate = new Mock <SecondDoubleAlternateCalculator>(); _doubleAlternateExceptionFive = new Mock <SecondDoubleAlternateCalculatorExceptionFive>(); var mappingSource = new Mock <IRuleMappingSource>(); mappingSource.Setup(ms => ms.GetModulusWeightMappings) .Returns(new[] { ModulusWeightMapping.From( "010004 010006 MOD10 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010007 010010 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010007 010010 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010011 010013 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010011 010013 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010016 010016 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5"), ModulusWeightMapping.From( "010016 010016 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5"), ModulusWeightMapping.From( "010014 010014 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5"), ModulusWeightMapping.From( "010014 010014 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5"), ModulusWeightMapping.From( "010004 010006 MOD10 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), }); _mockModulusWeightTable = new Mock <IModulusWeightTable>(); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("010004"))).Returns( new[] { ModulusWeightMapping.From( "010004 010006 MOD10 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010004 010006 MOD10 2 1 2 1 2 1 2 1 2 1 2 1 2 1") }); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("010008"))).Returns( new[] { ModulusWeightMapping.From( "010007 010010 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010007 010010 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), }); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("010013"))).Returns( new[] { ModulusWeightMapping.From( "010011 010013 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010011 010013 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), }); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("010014"))).Returns( new[] { ModulusWeightMapping.From( "010014 010014 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5"), ModulusWeightMapping.From( "010014 010014 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5"), }); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("010016"))).Returns( new[] { ModulusWeightMapping.From( "010016 010016 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5"), ModulusWeightMapping.From( "010016 010016 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5") }); _standardTen.Setup(nr => nr.Process(It.IsAny <BankAccountDetails>())).Returns(true); _standardEleven.Setup(nr => nr.Process(It.IsAny <BankAccountDetails>())).Returns(true); _doubleAlternate.Setup(nr => nr.Process(It.IsAny <BankAccountDetails>())).Returns(true); _doubleAlternateExceptionFive.Setup(nr => nr.Process(It.IsAny <BankAccountDetails>())). Returns(true); }
public void Before() { _standardTen = new Mock <FirstStandardModulusTenCalculator>(); _standardEleven = new Mock <FirstStandardModulusElevenCalculator>(); _firstDoubleAlternate = new Mock <FirstDoubleAlternateCalculator>(); _standardExceptionFive = new Mock <FirstStandardModulusElevenCalculatorExceptionFive>(); _secondModulusCalculation = new Mock <SecondModulusCalculatorStep>(); _firstDoubleAlternateExceptionFive = new Mock <FirstDoubleAlternateCalculatorExceptionFive>(); _exceptionFourteenCalculator = new Mock <StandardModulusExceptionFourteenCalculator>(); var mappingSource = new Mock <IRuleMappingSource>(); mappingSource.Setup(ms => ms.GetModulusWeightMappings) .Returns(new[] { ModulusWeightMapping.From( "010004 010006 MOD10 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010004 010006 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010007 010010 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010011 010013 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010016 010016 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5"), ModulusWeightMapping.From( "010014 010014 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5") }); _mockModulusWeightTable = new Mock <IModulusWeightTable>(); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("010004"))).Returns( new [] { ModulusWeightMapping.From( "010004 010006 MOD10 2 1 2 1 2 1 2 1 2 1 2 1 2 1"), ModulusWeightMapping.From( "010004 010006 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1") }); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("010008"))).Returns( new[] { ModulusWeightMapping.From( "010007 010010 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1") }); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("010013"))).Returns( new[] { ModulusWeightMapping.From( "010011 010013 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1") }); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("010014"))).Returns( new[] { ModulusWeightMapping.From( "010014 010014 MOD11 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5") }); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("010016"))).Returns( new[] { ModulusWeightMapping.From( "010016 010016 dblal 2 1 2 1 2 1 2 1 2 1 2 1 2 1 5") }); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("180002"))).Returns( new[] { ModulusWeightMapping.From("180002 180002 Mod11 0 0 0 0 0 0 8 7 6 5 4 3 2 1 14") }); _mockModulusWeightTable.Setup(mwt => mwt.GetRuleMappings(new SortCode("200915"))).Returns( new[] { ModulusWeightMapping.From("200901 201159 Mod11 0 0 0 0 0 0 0 7 6 5 4 3 2 1 6"), ModulusWeightMapping.From("200901 201159 DblAl 2 1 2 1 2 1 2 1 2 1 2 1 2 1 6") }); _standardTen.Setup(nr => nr.Process(It.IsAny <BankAccountDetails>())).Returns(true); _exceptionFourteenPassesFirstTime = new BankAccountDetails("180002", "98093517"); _exceptionFourteenPassesSecondTime = new BankAccountDetails("180002", "00000190"); _standardEleven.Setup(nr => nr.Process(_exceptionFourteenPassesFirstTime)).Returns(true); _standardEleven.Setup(nr => nr.Process(_exceptionFourteenPassesSecondTime)).Returns(false); _firstDoubleAlternate.Setup(nr => nr.Process(It.IsAny <BankAccountDetails>())).Returns(true); _standardExceptionFive.Setup(nr => nr.Process(It.IsAny <BankAccountDetails>())).Returns(true); _secondModulusCalculation.Setup(nr => nr.Process(It.IsAny <BankAccountDetails>())).Returns( true); _firstDoubleAlternateExceptionFive.Setup(nr => nr.Process(It.IsAny <BankAccountDetails>())). Returns(true); _exceptionFourteenCalculator.Setup(nr => nr.Process(It.IsAny <BankAccountDetails>())).Returns (true); _firstStepRouter = new Mock <FirstStepRouter>(_standardTen.Object, _standardEleven.Object, _firstDoubleAlternate.Object); }
public void CannotAddUnknownAlgorithm() { Assert.Throws <ArgumentException>(() => ModulusWeightMapping.From("123456 001234 PLOPPY 2 1 2 1 2 1 2 1 2 1 2 1 2 1")); }