public void GivenBracketsInputErrorIsThrownAndNoResultGiven() { var viewModel = new CalculationViewModel() { Expression = "2*(2+8)" }; var errors = viewModel.Validate(); Assert.IsNotEmpty(errors); }
public void GivenInputBeginsWithOperatorErrorIsThrownAndNoResultGiven() { var viewModel = new CalculationViewModel() { Expression = "+2*2+8" }; var errors = viewModel.Validate(); Assert.IsNotEmpty(errors); }
public void GivenDecimalInputErrorIsThrownAndNoResultGiven() { var viewModel = new CalculationViewModel() { Expression = "1.3+4" }; var errors = viewModel.Validate(); Assert.IsNotEmpty(errors); }
public void GivenAlphabeticInputErrorIsThrownAndNoResultGiven() { var viewModel = new CalculationViewModel() { Expression = "House" }; var errors = viewModel.Validate(); Assert.IsNotEmpty(errors); }
public void GivenValidInputErrorIsNotThrownAndResultIsGiven(string expressionInput) { var viewModel = new CalculationViewModel() { Expression = expressionInput }; var errors = viewModel.Validate(); Assert.IsEmpty(errors); }
public void GivenInputHasConsecutiveOperatorsErrorIsThrownAndNoResultGiven() { var viewModel = new CalculationViewModel() { Expression = "12+-67" }; var errors = viewModel.Validate(); Assert.IsNotEmpty(errors); }
public IActionResult PerformCalculation(CalculationViewModel model) { var errors = model.Validate(); if (errors.Count > 0) { foreach (var error in errors) { ModelState.AddModelError(error.Key, error.Value); } return(View("Index", model)); } model.Result = CalculationHelper.GetExpressionResult(model.Expression); return(View("Index", model)); }