public ActionResult Index(FibViewModel model) { if (ModelState.IsValid) { model.FibNumber = Benet.NthNumber(model.SequenceNumber); } else { model.FibNumber = 0; } return(View(model)); }
public void GivenSequence7ThenExpect13() { // Arrange var inputModel = new FibViewModel { SequenceNumber = 7 }; // Act var result = _controller.Index(inputModel) as ViewResult; var outputModel = (FibViewModel)result.Model; // Assert Assert.AreEqual(13, outputModel.FibNumber); }
public void GivenInvalidValueThenVerifyResultIs0() { // Arrange var inputModel = new FibViewModel { SequenceNumber = 1 }; _controller.ViewData.ModelState.AddModelError("Test", "Invalid value"); // Act var result = _controller.Index(inputModel) as ViewResult; var outputModel = (FibViewModel)result.Model; // Assert Assert.AreEqual(0, outputModel.FibNumber); }