public ActionResult CalculateOhm(BandColorModel model) { int result; try { if (Convert.ToInt32(model.Band) == 3) { OhmValuCalculator = new Svc.Calculate3BandOhmValue(); } // Since the given interface is only supports 4 bands. Hence both 4 and 5 bands will have // same behaviour as the tolerance cannot be passed else if (Convert.ToInt32(model.Band) == 4 || Convert.ToInt32(model.Band) == 5) { OhmValuCalculator = new Svc.Calculate4BandOhmValue(); } result = OhmValuCalculator.CalculateOhmValue(model.BandAColor, model.BandBColor, model.BandCColor, model.BandDColor); } catch (ValidationException ex) { this.ModelState.AddModelErrors(ex); return(PartialView()); } return(PartialView(result)); }
public void FourBand4YnullMul100ReturnsException() { //Arrange HomeController homecontroller = new HomeController(); BandColorModel bandmodel = new BandColorModel(); bandmodel.BandAColor = "yellow"; bandmodel.BandBColor = null; bandmodel.BandCColor = null; bandmodel.BandDColor = "red"; bandmodel.Band = 4; //Act var result = homecontroller.CalculateOhm(bandmodel) as PartialViewResult; //Assert Assert.AreEqual(2, result.ViewData.ModelState.Count); }
public void FourBand4Y5G6BlueMul100Return45600() { //Arrange HomeController homecontroller = new HomeController(); BandColorModel bandmodel = new BandColorModel(); bandmodel.BandAColor = "yellow"; bandmodel.BandBColor = "green"; bandmodel.BandCColor = "blue"; bandmodel.BandDColor = "red"; bandmodel.Band = 4; //Act var result = homecontroller.CalculateOhm(bandmodel) as PartialViewResult; //Assert Assert.AreEqual(45600, result.Model); }
public void ThreeBand2R1BMult10Returns210() { // Arrange HomeController testController = new HomeController(); BandColorModel bandModel = new BandColorModel(); bandModel.BandAColor = "red"; bandModel.BandBColor = "brown"; bandModel.BandCColor = null; bandModel.BandDColor = "brown"; bandModel.Band = 3; // Act var result = testController.CalculateOhm(bandModel) as PartialViewResult; // Assert Assert.AreEqual(210, result.Model); }
public void ThreeBand4YnullMul100ReturnsException() { //Arrange HomeController homecontroller = new HomeController(); BandColorModel bandmodel = new BandColorModel(); bandmodel.BandAColor = "yellow"; bandmodel.BandBColor = null; bandmodel.BandCColor = null; bandmodel.BandDColor = "red"; bandmodel.Band = 3; //Act var result = homecontroller.CalculateOhm(bandmodel) as PartialViewResult; //Assert var model = result.ViewData.ModelState["bandBColor"]; Assert.AreEqual("invalid bandBColor color", model.Errors[0].ErrorMessage); }