public ActionResult Index(HttpPostedFileBase file) { ViewBag.File = file; if (file == null || file.ContentLength <= 0) return RedirectToAction("Index"); var ocr = new KataBankOcr(file.InputStream); ViewBag.Results = ocr.ProcessFileWithChecksum(); return View("Results"); }
public void CanValidateChecksums() { var expected = new string[2] {"345882865", "664371495 ERR"}; var fileUtil = A.Dummy<IFileUtilities>(); var checksumCalculator = A.Fake<IChecksumCalculator>(); var rawCharacterReader = A.Fake<IRawCharacterReader>(); var digits = new[] { 3, 4, 5, 8, 8, 2, 8, 6, 5, 6, 6, 4, 3, 7, 1, 4, 9, 5 }; var values = new List<string>(); for (var i = 0; i < digits.Length; i++) { values.Add(RawDigits[digits[i]]); } values.Add(null); var checkResults = new[] {true, false}; A.CallTo(() => rawCharacterReader.GetRawDigit(A<string>.Ignored, A<int>.Ignored, A<int>.Ignored)) .ReturnsNextFromSequence(values.ToArray()); A.CallTo(() => checksumCalculator.DoesChecksumPass(A<string>.Ignored)).ReturnsNextFromSequence(checkResults); var sut = new KataBankOcr(fileUtil, rawCharacterReader, checksumCalculator); Assert.AreEqual(expected, sut.ProcessFileWithChecksum()); }