public ActionResult DoSumming(SummingModel model) { if (ModelState.IsValid) { bool hasErrors = false; RomanNumber leftOperand; RomanNumber rightOperand; if (!RomanNumber.TryParse(model.LeftOperand, out leftOperand)) { ModelState.AddModelError("LeftOperand", string.Format("'{0}' is not a valid Roman number", model.LeftOperand)); hasErrors = true; } if (!RomanNumber.TryParse(model.RightOperand, out rightOperand)) { ModelState.AddModelError("RightOperand", string.Format("'{0}' is not a valid Roman number", model.RightOperand)); hasErrors = true; } if (!hasErrors) { Abacus abacus = new RomanAbacus(100); // Roman abacus wil be able to handle hundreds of thousands ViewBag.SummingResult = abacus.PerformSumming(model.LeftOperand, model.RightOperand); } } InitSummingView(); return View("Index", model); }
public void PerformSumming_UsingInvalidRomanNumberAsRightOperand_ThrowsException() { const string leftOperand = "MMC"; const string rightOperand = "12"; RomanAbacus romanAbacus = new RomanAbacus(100); romanAbacus.PerformSumming(leftOperand, rightOperand); }
public void PerformSumming_UsingValidRomanNumbers_ReturnsCorrectResult() { const string leftOperand = "MMC"; const string rightOperand = "LX"; RomanAbacus romanAbacus = new RomanAbacus(100); string actualResult = romanAbacus.PerformSumming(leftOperand, rightOperand); Assert.AreEqual("MMCLX", actualResult); }
public void Constructor_UsingValidThousandThreshold_DoesNotThrowException([Values(1, 10)] int validThousandThreshold) { RomanAbacus romanAbacus = new RomanAbacus(validThousandThreshold); }
public void Constructor_UsingInvalidThousandThreshold_ThrowsException([Values(-1, 0)] int invalidThousandThreshold) { RomanAbacus romanAbacus = new RomanAbacus(invalidThousandThreshold); }